예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            pDetail.Controls.Clear();
            Button addNew = (Button)sender;
            int    tag    = Convert.ToInt32(addNew.Tag);

            switch (tag)
            {
            case 1:
                UCDepartmentListDetail ucDepartment = new UCDepartmentListDetail();
                ucDepartment.Dock           = DockStyle.Fill;
                ucDepartment.btnSave.Click += btnSaveDepartment_Click;
                ucDepartment.btnDelete.Hide();
                pDetail.Controls.Add(ucDepartment);
                break;

            case 2:
                UCUserListDetail ucUser = new UCUserListDetail();
                ucUser.Dock           = DockStyle.Fill;
                ucUser.btnSave.Click += btnSaveUser_Click;
                ucUser.btnDelete.Hide();

                ucUser.cbRole.DisplayMember = "Value";
                ucUser.cbRole.ValueMember   = "Key";
                var department = UserService.GetListDepartment().ToList();
                foreach (var item in department)
                {
                    var temp = new KeyValueModel();
                    temp.Key   = item.DepartmentID;
                    temp.Value = item.DepartmentName;
                    ucUser.cbRole.Items.Add(temp);
                }
                //ucUser.cbRole.SelectedIndex = 0;
                pDetail.Controls.Add(ucUser);
                break;
            }
        }
예제 #2
0
        void addStaffDetail(StaffModel data)
        {
            // pDetail.Controls.Clear();

            if (data.StaffID > 0)
            {
                UCUserListDetail ucUserDetail = new UCUserListDetail();

                if (pDetail.Controls.Count > 0)
                {
                    ucUserDetail = (UCUserListDetail)pDetail.Controls[0];
                }
                else
                {
                    ucUserDetail.Dock = DockStyle.Fill;
                    pDetail.Controls.Add(ucUserDetail);
                }


                // ucUserDetail.Dock = DockStyle.Fill;

                ucUserDetail.lbTitle.Text = data.Fname + " " + data.Lname;

                ucUserDetail.txtFname.Text = data.Fname;

                ucUserDetail.txtLname.Text = data.Lname;

                ucUserDetail.txtUserName.Text = data.UserName;

                ucUserDetail.txtPinCode.Text = StaffModel.Decrypt(data.Password);

                var department = UserService.GetListDepartment().ToList();

                ucUserDetail.cbRole.DisplayMember = "Value";
                ucUserDetail.cbRole.ValueMember   = "Key";

                var textDefault = "";
                ucUserDetail.cbRole.Items.Clear();
                foreach (var item in department)
                {
                    if (item.DepartmentID == data.DepartmentID)
                    {
                        textDefault = item.DepartmentName;
                    }

                    var temp = new KeyValueModel();
                    temp.Key   = item.DepartmentID;
                    temp.Value = item.DepartmentName;
                    ucUserDetail.cbRole.Items.Add(temp);
                }

                if (textDefault != "")
                {
                    ucUserDetail.cbRole.Text = textDefault;
                }
                else
                {
                    ucUserDetail.cbRole.SelectedIndex = 0;
                }



                ucUserDetail.btnSave.Tag    = data;
                ucUserDetail.btnSave.Click += btnSaveUser_Click;

                ucUserDetail.btnDelete.Tag    = data;
                ucUserDetail.btnDelete.Click += btnDeleteUser_Click;
                ucUserDetail.btnDelete.Show();
            }
        }