コード例 #1
0
ファイル: Frm_Create_User.cs プロジェクト: JuhaSoft/BOM_MOI
        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (StatusEdit == false)
            {
                if (!validasiTextBox())
                {
                    return;
                }
                if (LayerUser.GetValUser(Txt_UserID.Text))
                {
                    var exceptionMessage = "User already exist";
                    // clsWin.ClearWindowsObJect(panelEx1);
                    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                    Txt_UserID.Focus();
                    return;
                }
                //if (layerPart.GetPartReference(Txt_Part_Ref.Text))
                //{
                //    var exceptionMessage = "Part Code already exist";
                //    // clsWin.ClearWindowsObJect(panelEx1);
                //    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                //    Txt_Part_Ref.Focus();
                //    return;
                //}
                UsersModel user;
                AccessItemModel AccessItm;
                try
                {
                    if (clsWin.QuestionMessage("Are you sure want to save", "Save User"))
                    {
                        string usr = _frmMain.activeuser;
                        {
                            user = new UsersModel()
                            {
                                usrGUID = Guid.NewGuid().ToString(),
                                UserID = Txt_UserID.Text,
                                Password = (crypto.Encrypt(Txt_User_Password.Text.ToString(), true)),
                                Comp = clsWin.GetComputerName(),
                                UserName = _frmMain.activeuser,
                                LastUpdate = DateTime.Now
                            };
                            LayerUser.InSertUser(user);
                            Cursor.Current = Cursors.WaitCursor;
                            for (int i = 0; i <= dgView.RowCount - 1; i++)
                            {
                                AccessItm = new AccessItemModel()
                                {
                                    usrGUID = user.usrGUID,
                                    AccessItemID = (dgView.Rows[i].Cells[1].Value.ToString()),
                                    Frm_Description = (dgView.Rows[i].Cells[2].Value.ToString()),
                                    Btn_Insert = dgView.Rows[i].Cells[4].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[4].Value),
                                    ReadF = dgView.Rows[i].Cells[3].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[3].Value),
                                    Btn_Edit = dgView.Rows[i].Cells[5].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[5].Value),
                                    Btn_Delete = dgView.Rows[i].Cells[6].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[6].Value),
                                    Btn_Print = dgView.Rows[i].Cells[7].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[7].Value),

                                };
                                LayerAccessItem.InSertAccess(AccessItm);
                            }

                        }

                        //db.SaveChanges();
                        Cursor.Current = Cursors.Default;
                        clsWin.SuccessMessage("User has been saved", "Success");
                        //  Btn_refresh.inse();
                    }

                }
                catch (DbEntityValidationException ex)
                {
                    var errorMessages = ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);
                    var exceptionMessage = string.Concat(errorMessages);
                    clsWin.ClearWindowsObJect(panelEx1);
                    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");

                    //  Btn_refresh.PerformClick();
                }
            }
            else
            {

                AccessItemModel AccessItm;
                try
                {
                    if (clsWin.QuestionMessage("Are you sure want to save", "Edit User"))
                    {

                        {

                            Cursor.Current = Cursors.WaitCursor;
                            LayerAccessItem.DeleteAccess(id);

                            for (int i = 0; i <= dgView.RowCount - 1; i++)
                            {
                                AccessItm = new AccessItemModel()
                                {
                                    usrGUID = id,
                                    AccessItemID = (dgView.Rows[i].Cells[1].Value.ToString()),
                                    Frm_Description = (dgView.Rows[i].Cells[2].Value.ToString()),
                                    Btn_Insert = dgView.Rows[i].Cells[4].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[4].Value),
                                    ReadF = dgView.Rows[i].Cells[3].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[3].Value),
                                    Btn_Edit = dgView.Rows[i].Cells[5].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[5].Value),
                                    Btn_Delete = dgView.Rows[i].Cells[6].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[6].Value),
                                    Btn_Print = dgView.Rows[i].Cells[7].Value == null ? false : Convert.ToBoolean(dgView.Rows[i].Cells[7].Value),

                                };
                                LayerAccessItem.InSertAccess(AccessItm);
                            }

                        }

                        //db.SaveChanges();
                        Cursor.Current = Cursors.Default;
                        clsWin.SuccessMessage("User has been Update", "Success");
                        //  Btn_refresh.inse();
                    }

                }
                catch (DbEntityValidationException ex)
                {
                    var errorMessages = ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);
                    var exceptionMessage = string.Concat(errorMessages);
                    clsWin.ClearWindowsObJect(panelEx1);
                    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");

                    //  Btn_refresh.PerformClick();
                }
            }
            LoadData();
        }
コード例 #2
0
ファイル: AccessItemLayer.cs プロジェクト: JuhaSoft/BOM_MOI
        public bool InSertAccess(AccessItemModel model)
        {
            try
            {
                ExecuteCommand(cn =>
                {
                    MySqlCommand cmd = new MySqlCommand(@"Insert Into tblaccessitem
                                 (usrGUID,AccessItemID  ,Frm_Description ,Btn_Insert ,ReadF ,Btn_Edit,Btn_Delete,Btn_Print)
                    values(@usrGUID,@AccessItemID,@Frm_Description,@Btn_Insert,@ReadF,@Btn_Edit,@Btn_Delete,@Btn_Print)", cn);
                    cmd.Parameters.AddWithValue("@usrGUID", model.usrGUID);
                    cmd.Parameters.AddWithValue("@AccessItemID", model.AccessItemID);
                    cmd.Parameters.AddWithValue("@Frm_Description", model.Frm_Description);
                    cmd.Parameters.AddWithValue("@Btn_Insert", model.Btn_Insert);
                    cmd.Parameters.AddWithValue("@ReadF", model.ReadF);
                    cmd.Parameters.AddWithValue("@Btn_Edit", model.Btn_Edit);
                    cmd.Parameters.AddWithValue("@Btn_Delete", model.Btn_Delete);
                    cmd.Parameters.AddWithValue("@Btn_Print", model.Btn_Print);
                    rst = cmd.ExecuteNonQuery();

                });
                if (rst == 1)
                    return true;
                else
                    return false;

            }
            catch (Exception)
            {

                throw;
            }
        }