懒羊羊
2023-12-28 e46d3baaf3e8d7d85f4bafec3aad75e52b078408
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YX.BLL;
using YX.Entity;
 
namespace YX
{
    public partial class FrmMenuEdit : Form
    {
        YX.BLL.SystemMenu_Bll bll = new BLL.SystemMenu_Bll();
        
        FrmMenu _frmMenu;
        OperationType type;
        string MenuID = "";
        public FrmMenuEdit(FrmMenu frmMenu)
        {
         
            type = OperationType.Add;
            this._frmMenu = frmMenu;
            InitializeComponent();
            this.Text = "菜单信息-添加";
            this.txt_parent.Text = _frmMenu.treeView1.SelectedNode.Text;
        }
        public FrmMenuEdit(FrmMenu frmMenu, ref DataGridViewRow dvr)
        {
            try
            {
 
                type = OperationType.Edit;
                this._frmMenu = frmMenu;
                InitializeComponent();
                this.Text = "菜单信息-编辑";
                //  this.com_Parent.Text=dvr.Cells["节点位置"].Value==null?"": dvr.Cells["节点位置"].Value.ToString();
                this.txt_parent.Text = _frmMenu.treeView1.SelectedNode.Text;
                this.txt_MenuName.Text = dvr.Cells["Menu_Name"].Value == null ? "" : dvr.Cells["Menu_Name"].Value.ToString();
                txt_MenuTag.Text = dvr.Cells["Menu_Tag"].Value == null ? "" : dvr.Cells["Menu_Tag"].Value.ToString();
                txt_Sort.Text = dvr.Cells["SortCode"].Value == null ? "0" : dvr.Cells["SortCode"].Value.ToString();
                pic_menu.Image = new FrmListImages(this).imageList1.Images[dvr.Cells["Menu_Img"].Value==null? 0 : int.Parse(dvr.Cells["Menu_Img"].Value.ToString())];
                pic_menu.Tag = dvr.Cells["Menu_Img"].Value==null ? 0 : int.Parse(dvr.Cells["Menu_Img"].Value.ToString());
                MenuID = dvr.Cells["Menu_Id"].Value == null ? "" : dvr.Cells["Menu_Id"].Value.ToString();
            }
            catch (Exception ex)
            {
                System_Bll.WriteLogToDB(new Entity.Base_Log
                {
                    CreateUserID = FrmLogin.LoginUserID,
                    CreateUserName = FrmLogin.loginUserName,
                    LocalIP = FrmLogin.LocalIP,
                    LogMessage = ex.Message,
                    Type = "系统错误!",
                    ClassName = typeof(FrmMenuEdit).ToString()
                });
                MessageBox.Show(ex.Message);
            }
        }
 
    
   
        private void FrmMenuEdit_Load(object sender, EventArgs e)
        {
 
            //var ParentID= _frmMenu.treeView1.SelectedNode==null?"": _frmMenu.treeView1.SelectedNode.Tag;
            //com_Parent.DataSource = bll.GetSysMenusParent(FrmLogin.LoginUserID);
            //com_Parent.DisplayMember = "Menu_Name";
            //com_Parent.ValueMember = "Menu_Id";
            //com_Parent.SelectedValue = ParentID;
        }
 
        private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
    
                if (type == OperationType.Add)
                {
                    Base_SysMenu info = new Base_SysMenu
                    {
                        CreateDate = DateTime.Now,
                        CreateUserId = FrmLogin.LoginUserID,
                        CreateUserName = FrmLogin.loginUserName,
                        Menu_Img = int.Parse(pic_menu.Tag.ToString()),
                        Menu_Name = txt_MenuName.Text,
                        Menu_Tag = txt_MenuTag.Text,                      
                        ParentId = _frmMenu.treeView1.SelectedNode.Tag.ToString(),
                        SortCode = int.Parse(txt_Sort.Text),                   
                        Menu_Id = Guid.NewGuid().ToString()
 
                    };
                  int result=  bll.AddSysMenu(info);
                  if (result == 1)
                  {
                      MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                      _frmMenu.dataGridView1.DataSource = bll.GetSysMenuChilds(_frmMenu.treeView1.SelectedNode.Tag.ToString(),FrmLogin.LoginUserID);
                      this.Close();
                  }
                  else
                  {
                      MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  }
                }
                else
                {
                    Base_SysMenu info = new Base_SysMenu
                    {
 
                        Menu_Img = int.Parse(pic_menu.Tag.ToString()),
                        Menu_Name = txt_MenuName.Text,
                        Menu_Tag = txt_MenuTag.Text,
                        ParentId = _frmMenu.treeView1.SelectedNode.Tag.ToString(),
                        SortCode = int.Parse(txt_Sort.Text),
                        ModifyUserName = FrmLogin.loginUserName,
                        ModifyDate = DateTime.Now,
                        ModifyUserId = FrmLogin.LoginUserID,
                        Menu_Id = MenuID
                       
 
                    };
                    int result=  bll.UpdateSysMenu(info);
                    if (result == 1)
                    {
                        MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        _frmMenu.dataGridView1.DataSource = bll.GetSysMenuChilds(_frmMenu.treeView1.SelectedNode.Tag.ToString(),FrmLogin.LoginUserID);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                System_Bll.WriteLogToDB(new Entity.Base_Log
                {
                    CreateUserID = FrmLogin.LoginUserID,
                    CreateUserName = FrmLogin.loginUserName,
                    LocalIP = FrmLogin.LocalIP,
                    LogMessage = ex.Message,
                    Type = "系统错误!",
                    ClassName = typeof(FrmMenuEdit).ToString()
                });
                MessageBox.Show(ex.Message);
            }
           
        }
 
        private void pic_menu_Click(object sender, EventArgs e)
        {
            FrmListImages image = new FrmListImages(this);
            image.ShowDialog();
        }
 
        private void btn_concel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}