Beispiel #1
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            if (!layerAccess.IsCanDelete(_frmMain.userID))
            {
                clsWin.WarningMessage("You dont have permition to access this form, please contact your administrator", "Access Denied");

                return;
            }
            UsersModel um;
            try
            {
                if (clsWin.QuestionMessage("Are you sure want to Delete this record?", "Confirm Delete"))
                {

                    {

                        um = new UsersModel()
                        {
                            usrGUID =id,
                            //UnitName = txt_Unit_Name.Text,
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now,
                        };
                        LayerUser.DeleteUser(id, _frmMain.activeuser, clsWin.GetComputerName(), DateTime.Now);
                    }
                    clsWin.SuccessMessage("Unit has been Delete", "Success");
                    //Btn_refresh.PerformClick();
                }

            }
            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();
            }
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        public bool InSertUser(UsersModel model)
        {
            try
            {
                ExecuteCommand(cn =>
                {
                    MySqlCommand cmd = new MySqlCommand(@"Insert Into tblusers
                                 (usrGUID,UserID  ,Password ,Comp ,UserName ,LastUpdate)
                    values(@usrGUID,@UserID,@Password,@Comp,@UserName,@LastUpdate)", cn);
                    cmd.Parameters.AddWithValue("@usrGUID", model.usrGUID);
                    cmd.Parameters.AddWithValue("@UserID", model.UserID);
                    cmd.Parameters.AddWithValue("@Password", model.Password);
                    cmd.Parameters.AddWithValue("@Comp", model.Comp);
                    cmd.Parameters.AddWithValue("@UserName", model.UserName);
                    cmd.Parameters.AddWithValue("@LastUpdate", model.LastUpdate);
                    rst = cmd.ExecuteNonQuery();

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

            }
            catch (Exception)
            {

                throw;
            }
        }