Exemplo n.º 1
0
        // Method Delete
        public GlobalConstants.ResponseResult Delete(string name)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            name = name.Trim();

            int count = RolesDao.Instance.CheckForeignKey(new RolesModel
            {
                Name = name
            });

            if (count > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.ForeignKey;

                return(res);
            }

            int execute = RolesDao.Instance.Delete(new RolesModel
            {
                Name = name
            });

            if (execute > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertFail;
            }

            return(res);
        }
Exemplo n.º 2
0
        // Method Edit
        public GlobalConstants.ResponseResult Edit(int id, string categoryname, bool status, string modifiedBy)
        {
            categoryname = categoryname.Trim();

            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int count = CategoriesDao.Instance.CheckExist(new CategoriesModel
            {
                Id   = id,
                Name = categoryname
            }, new string[] { "@NAME" });

            if (count > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.Unique;

                return(res);
            }

            DateTime now = DateTime.Now;

            string subDateTime = now.ToString("dd/MM/yyyy hh:mm:ss");

            subDateTime = subDateTime.Substring(0, subDateTime.LastIndexOf(":"));

            subDateTime = subDateTime + ":00";

            int execute = CategoriesDao.Instance.Edit(new CategoriesModel
            {
                Id           = id,
                Name         = categoryname,
                Status       = status,
                ModifiedDate = Convert.ToDateTime(subDateTime),
                ModifiedBy   = modifiedBy
            }, new string[] {
                "@NAME",
                "@STATUS",
                "@MODIFIEDDATE",
                "@MODIFIEDBY"
            });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditSuccess;

                List <CategoriesModel> categories = CategoriesDao.Instance.List();

                res.Result = categories;

                Categories.Clear();

                Categories.AddRange(categories);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditFail;
            }

            return(res);
        }
Exemplo n.º 3
0
        // Method Login
        public GlobalConstants.ResponseResult Login(string username, string password)
        {
            UsersModel user = UsersDao.Instance.Login(username.Trim(), password.Trim());

            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            if (user == null)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.LoginFail;
            }
            else if (user != null && !user.Status)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.BlockUser;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.LoginSuccess;

                res.Result = user;

                GlobalConstants.RoleName = user.RoleName;

                GlobalConstants.Username = user.Username;
            }

            return(res);
        }
Exemplo n.º 4
0
        // Method UpdateRole
        public static GlobalConstants.ResponseResult UpdateRole(string roleName, MetroGrid grid)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int execute = 0;

            string originalPath = Application.StartupPath;

            string fileSQLite = originalPath + "\\Roles.db3";

            if (!File.Exists(fileSQLite))
            {
                SQLiteConnection.CreateFile("Roles.db3");
            }

            string createRoles = @"CREATE TABLE IF NOT EXISTS [ROLES]
                                   (
                                       [MANIPULATION] VARCHAR(20) NOT NULL,
                                       [ROLE] VARCHAR(50) NOT NULL
                                   )
                                 ";

            using (SQLiteConnection con = new SQLiteConnection("Data Source = Roles.db3"))
            {
                using (SQLiteCommand command = new SQLiteCommand(con))
                {
                    con.Open();

                    command.CommandType = System.Data.CommandType.Text;

                    command.CommandText = createRoles;

                    command.ExecuteNonQuery();

                    command.CommandText = $"DELETE FROM ROLES WHERE ROLE = '{roleName}'";

                    command.ExecuteNonQuery();

                    for (int i = 0; i < grid.Rows.Count; i++)
                    {
                        command.CommandText = $"INSERT INTO ROLES(MANIPULATION, ROLE) VALUES('{grid["Manipulation", i].Value.ToString()}', '{roleName}')";

                        execute += command.ExecuteNonQuery();
                    }

                    con.Close();

                    if (execute == grid.Rows.Count)
                    {
                        res.TypeResponse = GlobalConstants.EnumResponse.EditSuccess;
                    }
                    else
                    {
                        res.TypeResponse = GlobalConstants.EnumResponse.EditFail;
                    }
                }
            }

            return(res);
        }
        // Method DeleteStuffsPlaceStuffs
        void DeleteStuffsPlaceStuffs()
        {
            if (gvStuffsPlaceStuffs.SelectedRows.Count > 0)
            {
                DialogResult dialog = MetroMessageBox.Show(this, "Bạn có chắc chắn xóa những vật tư đã chọn không ?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (dialog == DialogResult.Yes)
                {
                    DataGridViewRow row = gvPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault();

                    int    idPlaceStuff = Convert.ToInt32(row.Cells["Id"].Value.ToString());
                    string namePlace    = row.Cells["Name"].Value.ToString();

                    int[] stuffs = gvStuffsPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().Select(p => Convert.ToInt32(p.Cells["Id"].Value.ToString())).ToArray();

                    string[] nameStuffs = gvStuffsPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().Select(p => p.Cells["Name"].Value.ToString()).ToArray();

                    GlobalConstants.ResponseResult res = StuffsPlaceStuffsBll.Instance.Delete(idPlaceStuff, stuffs);

                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.DeleteSuccess:
                        foreach (string item in nameStuffs)
                        {
                            LogEvent.Log = LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{ GlobalConstants.Username}] - xóa vật tư [{item}] ra khỏi nơi [{namePlace}]";
                        }

                        DataGridViewRow rowChose = gvPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault();

                        int rowIndex = rowChose.Index;

                        if (rowChose != null)
                        {
                            PlaceStuffsBll.Instance.List(gvPlaceStuffs, false);

                            gvPlaceStuffs.CurrentCell = gvPlaceStuffs.Rows[rowIndex].Cells["Id"];

                            gvPlaceStuffs.Rows[rowIndex].Selected = true;

                            LoadStuffByPlaceStuff();
                        }

                        StuffsBll.Instance.ListStuffsNotHavePlace(gvStuffs, false);

                        MetroMessageBox.Show(this, $"Bạn đã xóa '{stuffs.Length.ToString()}' vật tư  ra khỏi nơi '{namePlace}' thành công !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.DeleteFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình xóa dữ liệu, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn vật tư để xóa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }
        }
        // Method Edit
        public GlobalConstants.ResponseResult Edit(int id, string placeStuffName)
        {
            placeStuffName = placeStuffName.Trim();

            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int count = PlaceStuffsDao.Instance.CheckExist(new PlaceStuffsModel
            {
                Id   = id,
                Name = placeStuffName
            }, new string[] { "@NAME" });

            if (count > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.Unique;

                return(res);
            }

            DateTime now = DateTime.Now;

            string subDateTime = now.ToString("dd/MM/yyyy hh:mm:ss");

            subDateTime = subDateTime.Substring(0, subDateTime.LastIndexOf(":"));

            subDateTime = subDateTime + ":00";

            int execute = PlaceStuffsDao.Instance.Edit(new PlaceStuffsModel
            {
                Id   = id,
                Name = placeStuffName,
            }, new string[] {
                "@NAME",
            });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditSuccess;

                List <PlaceStuffsModel> placeStuffs = PlaceStuffsDao.Instance.List();

                res.Result = placeStuffs;

                PlaceStuffs.Clear();

                PlaceStuffs.AddRange(placeStuffs);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditFail;
            }

            return(res);
        }
Exemplo n.º 7
0
        // Method Insert
        public GlobalConstants.ResponseResult Insert(string categoryName, bool status, string createdBy)
        {
            categoryName = categoryName.Trim();

            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int count = CategoriesDao.Instance.CheckExist(new CategoriesModel
            {
                Name = categoryName
            }, new string[] { "@NAME" });

            if (count >= 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.Unique;

                return(res);
            }

            string[] parameters =
            {
                "@NAME",
                "@STATUS",
                "@CREATEBY",
                "@MODIFIEDDATE:NULL"
            };

            int execute = CategoriesDao.Instance.Insert(new CategoriesModel
            {
                Name         = categoryName,
                Status       = status,
                CreatedBy    = createdBy,
                ModifiedDate = null
            }, parameters);

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertSuccess;

                List <CategoriesModel> categories = CategoriesDao.Instance.List();

                res.Result = categories;

                Categories.Clear();

                Categories.AddRange(categories);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertFail;
            }

            return(res);
        }
Exemplo n.º 8
0
        // Method DeleteRole
        public static GlobalConstants.ResponseResult DeleteRole(string roleName)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int execute = 0;

            string originalPath = Application.StartupPath;

            string fileSQLite = originalPath + "\\Roles.db3";

            if (!File.Exists(fileSQLite))
            {
                SQLiteConnection.CreateFile("Roles.db3");
            }

            string createRoles = @"CREATE TABLE IF NOT EXISTS [ROLES]
                                   (
                                       [MANIPULATION] VARCHAR(20) NOT NULL,
                                       [ROLE] VARCHAR(50) NOT NULL
                                   )
                                 ";

            using (SQLiteConnection con = new SQLiteConnection("Data Source = Roles.db3"))
            {
                using (SQLiteCommand command = new SQLiteCommand(con))
                {
                    con.Open();

                    command.CommandType = System.Data.CommandType.Text;

                    command.CommandText = createRoles;

                    command.ExecuteNonQuery();

                    command.CommandText = $"DELETE FROM ROLES WHERE ROLE = '{roleName}'";

                    execute = command.ExecuteNonQuery();

                    con.Close();

                    if (execute >= 1)
                    {
                        res.TypeResponse = GlobalConstants.EnumResponse.DeleteSuccess;
                    }
                    else
                    {
                        res.TypeResponse = GlobalConstants.EnumResponse.DeleteFail;
                    }
                }
            }

            return(res);
        }
        // Method DeleteRole
        void DeleteRole()
        {
            if (gvRoles.SelectedRows.Count > 0)
            {
                string roleName = gvRoles["RoleName", gvRoles.SelectedRows[0].Index].Value.ToString();

                DialogResult dialog = MetroMessageBox.Show(this, $"Bạn chắc chắn muốn xóa quyền '{roleName}' này chứ ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (dialog == DialogResult.Yes)
                {
                    GlobalConstants.ResponseResult resSqlServer = RolesBll.Instance.Delete(roleName);

                    GlobalConstants.ResponseResult resSqlite = ManipulationRoles.DeleteRole(roleName);

                    switch (resSqlServer.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.DeleteSuccess:
                        switch (resSqlite.TypeResponse)
                        {
                        case GlobalConstants.EnumResponse.DeleteSuccess:
                            LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{GlobalConstants.Username}] - xóa quyền [{roleName}]";

                            LoadAll();

                            MetroMessageBox.Show(this, $"Xóa quyền '{roleName}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                            txtRoleName.Focus();
                            break;

                        case GlobalConstants.EnumResponse.DeleteFail:
                            MetroMessageBox.Show(this, "Có lỗi trong quá trình xóa dữ liệu, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                            break;
                        }
                        break;

                    case GlobalConstants.EnumResponse.DeleteFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình xóa dữ liệu, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.ForeignKey:
                        MetroMessageBox.Show(this, "Quyền này đang được áp dụng cho một số user, hiện tại không thể xóa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn quyền cần xóa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }

            gvRoles.Focus();
        }
        // Method Delete
        void Delete()
        {
            if (gvPlaceStuffs.SelectedRows.Count > 0)
            {
                DataGridViewRow row = gvPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault();

                int rowIndex = row.Index;

                int id = Convert.ToInt32(gvPlaceStuffs["Id", row.Index].Value.ToString());

                string namePlaceStuff = gvPlaceStuffs["Name", row.Index].Value.ToString();

                DialogResult quesion = MetroMessageBox.Show(this, $"Bạn có chắn chắc muốn xóa {namePlaceStuff} chứ ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (quesion == DialogResult.Yes)
                {
                    GlobalConstants.ResponseResult res = PlaceStuffsBll.Instance.Delete(id);
                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.DeleteSuccess:
                        gvPlaceStuffs.DataSource = res.Result;

                        if (gvPlaceStuffs.RowCount > 0)
                        {
                            gvPlaceStuffs.CurrentCell = gvPlaceStuffs.Rows[rowIndex - 1].Cells["Id"];

                            gvPlaceStuffs.Rows[rowIndex - 1].Selected = true;
                        }

                        ClickRowGridViewBindingText();

                        LogEvent.Log = $"[{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{GlobalConstants.Username}] - xóa nơi [{namePlaceStuff}]";

                        MetroMessageBox.Show(this, $"Bạn đã xóa '{namePlaceStuff}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.DeleteFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình xóa dữ liệu, xin vui lòng thử xóa lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.ForeignKey:
                        MetroMessageBox.Show(this, $"Bạn không thể không thể xóa {namePlaceStuff} được vì nơi này đang được sử dụng !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn nơi cần xóa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }
        }
        // Method Insert
        public GlobalConstants.ResponseResult Insert(string placeStuffName)
        {
            placeStuffName = placeStuffName.Trim();

            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int count = PlaceStuffsDao.Instance.CheckExist(new PlaceStuffsModel
            {
                Name = placeStuffName
            }, new string[] { "@NAME" });

            if (count >= 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.Unique;

                return(res);
            }

            string[] parameters =
            {
                "@NAME"
            };

            int execute = PlaceStuffsDao.Instance.Insert(new PlaceStuffsModel
            {
                Name = placeStuffName
            }, parameters);

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertSuccess;

                List <PlaceStuffsModel> placeStuffs = PlaceStuffsDao.Instance.List();

                res.Result = placeStuffs;

                PlaceStuffs.Clear();

                PlaceStuffs.AddRange(placeStuffs);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertFail;
            }

            return(res);
        }
Exemplo n.º 12
0
        // Method Delete
        public GlobalConstants.ResponseResult Delete(int id, string usernameDelete, string usernameCurrent)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int execute = UsersDao.Instance.Delete(id);

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteFail;
            }

            return(res);
        }
        // Method Delete
        public GlobalConstants.ResponseResult Delete(int idPlaceStuff, int[] stuffs)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int excute = StuffsPlaceStuffsDao.Instance.Delete(idPlaceStuff, stuffs);

            if (excute == stuffs.Length)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteFail;
            }

            return(res);
        }
        // Method Delete
        void Delete()
        {
            if (gvUsers.SelectedRows.Count > 0)
            {
                string username = gvUsers["Username", gvUsers.SelectedRows[0].Index].Value.ToString();

                DialogResult dialog = MetroMessageBox.Show(this, $"Bạn chắc chắn muốn xóa tài khoản '{username}' !", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (dialog == DialogResult.Yes)
                {
                    int id = Convert.ToInt32(gvUsers["Id", gvUsers.SelectedRows[0].Index].Value.ToString());

                    GlobalConstants.ResponseResult res = UsersBll.Instance.Delete(id, username, GlobalConstants.Username);

                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.DeleteSuccess:
                        LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{ GlobalConstants.Username}] - xóa user [{username}]";

                        LoadUsers();

                        if (gvUsers.RowCount > 0)
                        {
                            gvUsers.CurrentCell = gvUsers.Rows[gvUsers.RowCount - 1].Cells["Id"];

                            gvUsers.Rows[gvUsers.RowCount - 1].Selected = true;
                        }

                        ClickRowBindingText();

                        MetroMessageBox.Show(this, $"Xóa tài khoản '{username}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.DeleteFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình xóa dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn tài khoản cần xóa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                gvUsers.Focus();
            }
        }
        // void DeleteStuffs
        void DeleteStuffs()
        {
            if (gvStuffs.SelectedRows.Count > 0)
            {
                DialogResult dialog = MetroMessageBox.Show(this, "Bạn có chắc chắn muốn xóa những vật tư vừa chọn ?. Nếu đồng ý những dòng liên quan đến vật tư bị xóa đều xóa theo.", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (dialog == DialogResult.Yes)
                {
                    int[] ids = gvStuffs.SelectedRows.Cast <DataGridViewRow>().
                                Select(p => Convert.ToInt32(p.Cells["Id"].Value.ToString())).Cast <int>().ToArray();

                    string[] names = gvStuffs.SelectedRows.Cast <DataGridViewRow>().
                                     Select(p => p.Cells["Name"].Value.ToString()).Cast <string>().ToArray();

                    GlobalConstants.ResponseResult res = StuffsBll.Instance.Deletes(ids, Convert.ToInt32(idCategory));

                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.DeleteSuccess:
                        StringBuilder logs = new StringBuilder();

                        foreach (string name in names)
                        {
                            LogEvent.Log = $"[{DateTime.Now}] - [{GlobalConstants.Username}] xóa vật tư[{name}]";
                        }

                        MetroMessageBox.Show(this, $"Bạn đã xóa thành công '{ids.Length.ToString()}' vật tư !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                        ClearTextControl();
                        break;

                    case GlobalConstants.EnumResponse.DeleteFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình xóa vật tư, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa những chọn vật tư cần xóa", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }

            gvStuffs.Focus();
        }
Exemplo n.º 16
0
        // Method ChangeProfile
        public GlobalConstants.ResponseResult ChangeProfile(string username, string name, bool sex, DateTime birthOfDate, string email, string phone)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int userId = UsersDao.Instance.GetUserIdByUsername(username);

            if (userId == 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.NotExsist;

                return(res);
            }

            int execute = UsersDao.Instance.ChangeProfile(new UsersModel
            {
                Id          = userId,
                Name        = name.Trim(),
                Sex         = sex,
                BirthOfDate = birthOfDate,
                Email       = email.Trim(),
                PhoneNumber = phone.Trim()
            }, new string[]
            {
                "@NAME",
                "@SEX",
                "@BIRTHOFDATE",
                "@EMAIL",
                "@PHONENUMBER"
            });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditFail;
            }

            return(res);
        }
Exemplo n.º 17
0
        // Method ExportExcel
        void ExportExcel()
        {
            if (gvData.Rows.Count > 0)
            {
                GlobalConstants.ResponseResult res = ManipulationExportExcel.ExportExcel(GlobalConstants.Username, cbbTables.Text, cbbTables.Text, gvData);

                switch (res.TypeResponse)
                {
                case GlobalConstants.EnumResponse.NotExsistPath:
                    MetroMessageBox.Show(this, "Đường dẫn không hợp lệ !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
                    break;

                case GlobalConstants.EnumResponse.ExportSuccess:
                    MetroMessageBox.Show(this, "Xuất excel thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);
                    break;
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bảng này không có dữ liệu để xuất ra excel !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }
        }
Exemplo n.º 18
0
        // Method ChangePassword
        public GlobalConstants.ResponseResult ChangePassword(string username, string passwordOld, string passwordNew)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            username    = username.Trim();
            passwordOld = passwordOld.Trim();
            passwordNew = passwordNew.Trim();

            int checkPassword = UsersDao.Instance.CheckPassword(username, passwordOld);

            if (checkPassword <= 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.NotMatch;

                return(res);
            }

            int userId = UsersDao.Instance.GetUserIdByUsername(username);

            if (userId == 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.NotExsist;

                return(res);
            }

            int execute = UsersDao.Instance.ChangePassword(userId, passwordNew);

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditFail;
            }

            return(res);
        }
Exemplo n.º 19
0
        // Method Delete
        public GlobalConstants.ResponseResult Delete(int id)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int count = CategoriesDao.Instance.CheckForeignKey(id);

            if (count > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.ForeignKey;

                return(res);
            }

            int execute = CategoriesDao.Instance.Delete(new CategoriesModel
            {
                Id = id
            }, new string[] { "@ID" });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteSuccess;

                res.Result = CategoriesDao.Instance.List();

                List <CategoriesModel> categories = CategoriesDao.Instance.List();

                res.Result = categories;

                Categories.Clear();

                Categories.AddRange(categories);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteFail;
            }

            return(res);
        }
Exemplo n.º 20
0
        // Method Insert
        public GlobalConstants.ResponseResult Insert(string name)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            name = name.Trim();

            int execute = RolesDao.Instance.Insert(new RolesModel
            {
                Name = name
            });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertFail;
            }

            return(res);
        }
Exemplo n.º 21
0
        // Method Delete
        public GlobalConstants.ResponseResult Deletes(int[] ids, int idCategory)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int execute = StuffsDao.Instance.DeleteStuffs(ids);

            if (execute == ids.Length)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteSuccess;

                if (ids.Length == PageSizes)
                {
                    Pages = Pages - 1;
                }

                ListPaging(Grid, PageSizes, out TotalCountNumber, out CountStuffs, Txt, false, 1, idCategory, LbTotal, LbCount, true);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.DeleteFail;
            }

            return(res);
        }
        // Method InsertStuffsPlaceStuffs
        void InsertStuffsPlaceStuffs()
        {
            if (gvStuffs.SelectedRows.Count > 0)
            {
                if (cbbIdPlaceStuffs.SelectedValue != null)
                {
                    int    idPlaceStuff = Convert.ToInt32(cbbIdPlaceStuffs.SelectedValue.ToString());
                    string namePlace    = cbbIdPlaceStuffs.Text;

                    int[] stuffs = gvStuffs.SelectedRows.Cast <DataGridViewRow>().Select(p => Convert.ToInt32(p.Cells["Id"].Value.ToString())).ToArray();

                    string[] nameStuffs = gvStuffs.SelectedRows.Cast <DataGridViewRow>().Select(p => p.Cells["Name"].Value.ToString()).ToArray();

                    GlobalConstants.ResponseResult res = StuffsPlaceStuffsBll.Instance.Insert(idPlaceStuff, stuffs);

                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.InsertSuccess:
                        foreach (string item in nameStuffs)
                        {
                            LogEvent.Log = LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{ GlobalConstants.Username}] - thêm vật tư [{item}] vào nơi [{namePlace}]";
                        }

                        if (gvPlaceStuffs.SelectedRows.Count > 0)
                        {
                            DataGridViewRow row = gvPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().Where(p => Convert.ToInt32(p.Cells["Id"].Value.ToString()) == idPlaceStuff).FirstOrDefault();

                            int rowIndex = row.Index;

                            if (row != null)
                            {
                                PlaceStuffsBll.Instance.List(gvPlaceStuffs, false);

                                gvPlaceStuffs.CurrentCell = gvPlaceStuffs.Rows[rowIndex].Cells["Id"];

                                gvPlaceStuffs.Rows[rowIndex].Selected = true;

                                LoadStuffByPlaceStuff();
                            }
                        }

                        StuffsBll.Instance.ListStuffsNotHavePlace(gvStuffs, false);

                        MetroMessageBox.Show(this, $"Bạn thêm '{stuffs.Length.ToString()}' vật tư vào nơi '{namePlace}' thành công !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.InsertFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình thêm dữ liệu, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                }
                else
                {
                    MetroMessageBox.Show(this, "Bạn chưa chọn nơi để thêm vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }
        }
Exemplo n.º 23
0
        // Method Insert
        public GlobalConstants.ResponseResult Insert(string username, string password, string name, bool sex, DateTime birthOfDate, string email, string phone, bool status, string roleName, string createdBy)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            username = username.Trim();

            int checkExist = UsersDao.Instance.CheckExist(username);

            if (checkExist > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.Unique;

                return(res);
            }

            int roleId = RolesDao.Instance.GetRoleIdByName(roleName.Trim());

            if (roleId == 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.NotExsist;

                return(res);
            }

            int execute = UsersDao.Instance.Insert(new UsersModel
            {
                Username    = username,
                Password    = password.Trim(),
                Name        = name.Trim(),
                Sex         = sex,
                BirthOfDate = birthOfDate,
                Email       = email,
                PhoneNumber = phone,
                Status      = status,
                CreatedBy   = createdBy,
                CreatedDate = DateTime.Now,
                IdRoles     = roleId
            }, new string[]
            {
                "@USERNAME",
                "@PASSWORD",
                "@NAME",
                "@SEX",
                "@BIRTHOFDATE",
                "@EMAIL",
                "@PHONENUMBER",
                "@STATUS",
                "@CREATEDDATE",
                "@CREATEBY",
                "@MODIFIEDDATE:NULL",
                "@IDROLES"
            });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertSuccess;
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.InsertFail;
            }

            return(res);
        }
        // Method Insert
        void Insert()
        {
            string   username    = txtUsername.Text;
            string   password    = txtPassword.Text;
            string   name        = txtName.Text;
            string   rePassword  = txtRePassword.Text;
            bool     sex         = cbSex.Checked;
            DateTime birthOfDate = dtBirthOfDay.Value;
            string   email       = txtEmail.Text;
            string   phone       = txtPhoneNumber.Text;
            bool     status      = cbStatus.Checked;
            string   roleName    = cbbRoles.SelectedValue.ToString();

            if (string.IsNullOrEmpty(username))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Tên tài khoản !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtUsername.Focus();

                return;
            }

            if (string.IsNullOrEmpty(password))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Mật khẩu !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtPassword.Focus();

                return;
            }

            if (password != rePassword)
            {
                MetroMessageBox.Show(this, "Mật khẩu nhập lại không chính xác !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtRePassword.Focus();

                return;
            }

            if (string.IsNullOrEmpty(name))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Tên !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtName.Focus();

                return;
            }

            if (string.IsNullOrEmpty(email))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập địa chỉ Email !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtEmail.Focus();

                return;
            }

            if (string.IsNullOrEmpty(phone))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Số điện thoại !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtPhoneNumber.Focus();

                return;
            }

            GlobalConstants.ResponseResult res = UsersBll.Instance.Insert(username, password, name, sex, birthOfDate, email, phone, status, roleName, GlobalConstants.Username);

            switch (res.TypeResponse)
            {
            case GlobalConstants.EnumResponse.InsertSuccess:
                LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{ GlobalConstants.Username}] - thêm user [{username}]";

                LoadUsers();

                gvUsers.CurrentCell = gvUsers.Rows[gvUsers.RowCount - 1].Cells["Id"];

                gvUsers.Rows[gvUsers.RowCount - 1].Selected = true;

                ClickRowBindingText();

                MetroMessageBox.Show(this, $"Thêm tài khoản '{username}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);
                break;

            case GlobalConstants.EnumResponse.InsertFail:
                MetroMessageBox.Show(this, "Có lỗi trong quá trình thêm dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                break;

            case GlobalConstants.EnumResponse.Unique:
                MetroMessageBox.Show(this, "Tên tài khoản đã tồn tại. Xin vui lòng nhập tên tài khoản khác !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtUsername.Focus();
                break;

            case GlobalConstants.EnumResponse.NotExsist:
                MetroMessageBox.Show(this, "Quyền này không tồn tại. Xin vui lòng chọn quyền khác !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                cbbRoles.Focus();
                break;
            }
        }
Exemplo n.º 25
0
        // Method Edit
        public GlobalConstants.ResponseResult Edit(int id, string bqCode, string stuffName, string producer, DateTime dateBuy, DateTime dateUse, DateTime yearRelease, string color, string state, decimal price, string warranty, bool status, int idCategory, string createdBy)
        {
            GlobalConstants.ResponseResult res = new GlobalConstants.ResponseResult();

            int count = StuffsDao.Instance.CheckExist(new StuffsModel
            {
                Id     = id,
                BQCode = bqCode
            }, new string[] { "@BQCODE" });

            if (count > 0)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.Unique;

                return(res);
            }

            int execute = StuffsDao.Instance.Edit(new StuffsModel
            {
                Id           = id,
                BQCode       = bqCode,
                Name         = stuffName,
                Producer     = producer,
                DateBuy      = dateBuy,
                DateUse      = dateUse,
                YearRelease  = yearRelease,
                ColorStuffs  = color,
                State        = state,
                PriceBuy     = price,
                Warranty     = warranty,
                Status       = status,
                IdCategories = idCategory,
                ModifiedDate = DateTime.Now,
                ModifiedBy   = createdBy
            }, new string[] {
                "@BQCODE",
                "@NAME",
                "@PRODUCER",
                "@DATEBUY",
                "@DATEUSE",
                "@YEARRELEASE",
                "@COLORSTUFFS",
                "@STATE",
                "@PRICEBUY",
                "@WARRANTY",
                "@STATUS",
                "@MODIFIEDDATE",
                "@IDCATEGORIES",
                "@MODIFIEDBY"
            });

            if (execute == 1)
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditSuccess;

                ListPaging(Grid, PageSizes, out TotalCountNumber, out CountStuffs, Txt, false, Pages, idCategory, LbTotal, LbCount, true);
            }
            else
            {
                res.TypeResponse = GlobalConstants.EnumResponse.EditFail;
            }

            return(res);
        }
        // Method InsertRole
        void InsertRole()
        {
            switch (isInsert)
            {
            case true:
                string roleName = txtRoleName.Text.Trim();

                if (string.IsNullOrEmpty(roleName))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Tên quyền !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtRoleName.Focus();

                    return;
                }

                if (gvManipulationOfRole.Rows.Count <= 0)
                {
                    MetroMessageBox.Show(this, "Bạn cần có ít nhất một thao tác cho phép đối với quyền này !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    gvManipulations.Focus();

                    return;
                }

                GlobalConstants.ResponseResult resSqlite = ManipulationRoles.InsertRole(roleName, gvManipulationOfRole);

                GlobalConstants.ResponseResult resSqlServer = RolesBll.Instance.Insert(roleName);

                switch (resSqlite.TypeResponse)
                {
                case GlobalConstants.EnumResponse.InsertSuccess:
                    switch (resSqlServer.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.InsertSuccess:
                        LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{GlobalConstants.Username}] - thêm một quyền [{roleName}]";

                        ManipulationRoles.ListRoles(gvRoles);

                        int rowIndex = gvRoles.Rows.Cast <DataGridViewRow>().Where(p => p.Cells["RoleName"].Value.ToString().Equals(roleName)).FirstOrDefault().Index;

                        gvRoles.CurrentCell = gvRoles.Rows[rowIndex].Cells["RoleName"];

                        gvRoles.Rows[rowIndex].Selected = true;

                        LoadManipulationsOfRole();

                        ClickButtonInsertRole(true);

                        MetroMessageBox.Show(this, $"Thêm quyền '{roleName}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                        txtRoleName.ResetText();

                        txtRoleName.Focus();
                        break;

                    case GlobalConstants.EnumResponse.InsertFail:
                        MetroMessageBox.Show(this, $"Có lỗi trong quá trình thêm dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;
                    }
                    break;

                case GlobalConstants.EnumResponse.InsertFail:
                    MetroMessageBox.Show(this, "Có lỗi trong quá trình thêm dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                    break;

                case GlobalConstants.EnumResponse.Unique:
                    MetroMessageBox.Show(this, $"Tên quyền '{roleName}' của bạn bị trùng, xin vui lòng nhập tên quyền khác !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtRoleName.Focus();
                    break;
                }
                break;

            case false:
                if (gvManipulationOfRole.Rows.Count <= 0)
                {
                    MetroMessageBox.Show(this, "Bạn cần có ít nhất một thao tác cho phép đối với quyền này !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    gvManipulations.Focus();

                    return;
                }

                string roleNameCurrent = gvRoles["RoleName", gvRoles.SelectedRows[0].Index].Value.ToString();

                GlobalConstants.ResponseResult resUpdate = ManipulationRoles.UpdateRole(roleNameCurrent, gvManipulationOfRole);

                switch (resUpdate.TypeResponse)
                {
                case GlobalConstants.EnumResponse.EditSuccess:
                    LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{GlobalConstants.Username}] - sửa quyền [{roleNameCurrent}]";

                    LoadManipulationsOfRole();

                    ClickButtonInsertRole(true);

                    MetroMessageBox.Show(this, $"Sửa thao tác cho quyền '{roleNameCurrent}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                    txtRoleName.Focus();
                    break;

                case GlobalConstants.EnumResponse.EditFail:
                    MetroMessageBox.Show(this, "Có lỗi trong quá trình thay đổi dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                    break;
                }
                break;
            }

            gvRoles.Focus();
        }
        // Method Insert
        void Insert()
        {
            string namePlaceStuff = txtNamePlaceStuffs.Text.Trim();

            if (string.IsNullOrEmpty(namePlaceStuff))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Tên nơi !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtNamePlaceStuffs.Focus();

                return;
            }

            GlobalConstants.ResponseResult res = PlaceStuffsBll.Instance.Insert(namePlaceStuff);

            switch (res.TypeResponse)
            {
            case GlobalConstants.EnumResponse.InsertSuccess:
                int idCategoryMax = 0;

                if (gvPlaceStuffs.RowCount > 0)
                {
                    idCategoryMax = Convert.ToInt32(gvPlaceStuffs["Id", gvPlaceStuffs.RowCount - 1].Value.ToString());
                }

                gvPlaceStuffs.DataSource = res.Result;

                LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{ GlobalConstants.Username}] - thêm một nơi [{ namePlaceStuff}]";

                MetroMessageBox.Show(this, $"Thêm nơi '{namePlaceStuff}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                for (int i = 0; i < gvPlaceStuffs.RowCount; i++)
                {
                    if (Convert.ToInt32(gvPlaceStuffs["Id", i].Value.ToString()) > idCategoryMax)
                    {
                        idCategoryMax = Convert.ToInt32(gvPlaceStuffs["Id", i].Value.ToString());

                        break;
                    }
                }

                if (idCategoryMax > 0)
                {
                    DataGridViewRow row = gvPlaceStuffs.Rows.Cast <DataGridViewRow>().FirstOrDefault(p => p.Cells["Id"].Value.ToString().Equals(idCategoryMax.ToString()));

                    if (row != null)
                    {
                        gvPlaceStuffs.CurrentCell = row.Cells["Id"];

                        row.Selected = true;
                    }
                }
                else
                {
                    gvPlaceStuffs.CurrentCell = gvPlaceStuffs.Rows[0].Cells["Id"];

                    gvPlaceStuffs.Rows[0].Selected = true;
                }

                ClickRowGridViewBindingText();
                break;

            case GlobalConstants.EnumResponse.InsertFail:
                MetroMessageBox.Show(this, "Có lỗi trong quá trình thêm dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                break;

            case GlobalConstants.EnumResponse.Unique:
                MetroMessageBox.Show(this, "Tên nơi bị trùng !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);

                txtNamePlaceStuffs.Focus();
                break;
            }
        }
        // void InsertStuffs
        void InsertStuffs()
        {
            string   stuffName   = txtNameStuffs.Text.Trim();
            string   bqCode      = txtBQCode.Text.Trim();
            string   producer    = txtProducer.Text.Trim();
            string   color       = txtColor.Text.Trim();
            string   state       = txtState.Text.Trim();
            string   price       = txtPriceBuy.Text.Trim();
            string   warranty    = txtWarranty.Text.Trim();
            string   idCategory  = cbbIdCategories.SelectedValue.ToString();
            bool     status      = cbStatus.Checked;
            DateTime dateBuy     = dtDateBuy.Value;
            DateTime dateUse     = dtDateUse.Value;
            DateTime yearRelease = dtYearRelease.Value;

            if (string.IsNullOrEmpty(stuffName))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Tên vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtNameStuffs.Focus();

                return;
            }

            if (string.IsNullOrEmpty(bqCode))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Code !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtBQCode.Focus();

                return;
            }

            if (string.IsNullOrEmpty(producer))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Tên nhà sản xuất !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtProducer.Focus();

                return;
            }

            if (string.IsNullOrEmpty(color))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Màu cho vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtColor.Focus();

                return;
            }

            if (string.IsNullOrEmpty(state))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Trạng thái vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtState.Focus();

                return;
            }

            if (string.IsNullOrEmpty(price))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Giá vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtPriceBuy.Focus();

                return;
            }

            if (string.IsNullOrEmpty(warranty))
            {
                MetroMessageBox.Show(this, "Bạn chưa nhập Thời gian bảo hành !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                txtWarranty.Focus();

                return;
            }

            if (dateBuy > DateTime.Now)
            {
                MetroMessageBox.Show(this, "Thời gian mua phải nhỏ hơn hoặc bằng thời gian hiện tại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                dtDateBuy.Focus();

                return;
            }

            if (dateUse > DateTime.Now)
            {
                MetroMessageBox.Show(this, "Thời gian sử dụng phải nhỏ hơn hoặc bằng thời gian hiện tại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                dtDateUse.Focus();

                return;
            }

            if (yearRelease > DateTime.Now)
            {
                MetroMessageBox.Show(this, "Thời gian bảo hành phải nhỏ hơn hoặc bằng thời gian hiện tại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                dtYearRelease.Focus();

                return;
            }

            GlobalConstants.ResponseResult res = StuffsBll.Instance.Insert(
                bqCode,
                stuffName,
                producer,
                dateBuy,
                dateUse,
                yearRelease,
                color,
                state,
                Convert.ToDecimal(price),
                warranty,
                status,
                Convert.ToInt32(idCategory),
                GlobalConstants.Username
                );

            switch (res.TypeResponse)
            {
            case GlobalConstants.EnumResponse.InsertSuccess:
                LogEvent.Log = $"[{ DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{ GlobalConstants.Username}] - thêm một vật tư [{stuffName}]";

                this.idCategory = idCategory;

                AutoSelectRowCategories();

                MetroMessageBox.Show(this, $"Thêm vật tư '{stuffName}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);
                break;

            case GlobalConstants.EnumResponse.InsertFail:
                MetroMessageBox.Show(this, "Có lỗi trong quá trình thêm dữ liệu, xin vui lòng thêm lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                break;

            case GlobalConstants.EnumResponse.Unique:
                MetroMessageBox.Show(this, "Mã BQCode bị trùng !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);

                txtNameStuffs.Focus();
                break;
            }

            txtNameStuffs.Focus();
        }
        // Method Edit
        void Edit()
        {
            if (gvPlaceStuffs.SelectedRows.Count > 0)
            {
                string namePlaceStuffNew = txtNamePlaceStuffs.Text.Trim();

                if (string.IsNullOrEmpty(namePlaceStuffNew))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Tên nơi !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtNamePlaceStuffs.Focus();

                    return;
                }

                DataGridViewRow row = gvPlaceStuffs.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault();

                int id = Convert.ToInt32(gvPlaceStuffs["Id", row.Index].Value.ToString());

                string nameCategoryOld = gvPlaceStuffs["Name", row.Index].Value.ToString();

                DialogResult quesion = MetroMessageBox.Show(this, $"Bạn có chắn chắc muốn sửa '{nameCategoryOld}' thành '{namePlaceStuffNew}'chứ ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (quesion == DialogResult.Yes)
                {
                    GlobalConstants.ResponseResult res = PlaceStuffsBll.Instance.Edit(id, namePlaceStuffNew);

                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.EditSuccess:
                        gvPlaceStuffs.DataSource = res.Result;

                        LogEvent.Log = $"[{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{GlobalConstants.Username}] - sửa nơi [{nameCategoryOld}] thành [{namePlaceStuffNew}]";

                        MetroMessageBox.Show(this, $"Sửa nơi {nameCategoryOld} thành {namePlaceStuffNew} thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                        row = gvPlaceStuffs.Rows.Cast <DataGridViewRow>().FirstOrDefault(p => p.Cells["Id"].Value.ToString().Equals(id.ToString()));

                        if (row != null)
                        {
                            gvPlaceStuffs.CurrentCell = row.Cells["Id"];

                            row.Selected = true;
                        }

                        ClickRowGridViewBindingText();
                        break;

                    case GlobalConstants.EnumResponse.EditFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình thay đổi dữ liệu, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.Unique:
                        MetroMessageBox.Show(this, $"Tên nơi {nameCategoryOld} đã bị trùng !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);

                        txtNamePlaceStuffs.Focus();
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn nơi cần sửa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }
        }
        // void EditStuff
        void EditStuff()
        {
            if (gvStuffs.SelectedRows.Count > 0)
            {
                string   stuffName   = txtNameStuffs.Text.Trim();
                string   bqCode      = txtBQCode.Text.Trim();
                string   producer    = txtProducer.Text.Trim();
                string   color       = txtColor.Text.Trim();
                string   state       = txtState.Text.Trim();
                string   price       = txtPriceBuy.Text.Trim();
                string   warranty    = txtWarranty.Text.Trim();;
                string   idCategory  = cbbIdCategories.SelectedValue.ToString();
                bool     status      = cbStatus.Checked;
                DateTime dateBuy     = dtDateBuy.Value;
                DateTime dateUse     = dtDateUse.Value;
                DateTime yearRelease = dtYearRelease.Value;

                if (string.IsNullOrEmpty(stuffName))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Tên vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtNameStuffs.Focus();

                    return;
                }

                if (string.IsNullOrEmpty(bqCode))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Code !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtBQCode.Focus();

                    return;
                }

                if (string.IsNullOrEmpty(producer))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Tên nhà sản xuất !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtProducer.Focus();

                    return;
                }

                if (string.IsNullOrEmpty(color))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Màu cho vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtColor.Focus();

                    return;
                }

                if (string.IsNullOrEmpty(state))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Trạng thái vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtState.Focus();

                    return;
                }

                if (string.IsNullOrEmpty(price))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Giá vật tư !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtPriceBuy.Focus();

                    return;
                }

                if (string.IsNullOrEmpty(warranty))
                {
                    MetroMessageBox.Show(this, "Bạn chưa nhập Thời gian bảo hành !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    txtWarranty.Focus();

                    return;
                }

                if (dateBuy > DateTime.Now)
                {
                    MetroMessageBox.Show(this, "Thời gian mua phải nhỏ hơn hoặc bằng thời gian hiện tại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    dtDateBuy.Focus();

                    return;
                }

                if (dateUse > DateTime.Now)
                {
                    MetroMessageBox.Show(this, "Thời gian sử dụng phải nhỏ hơn hoặc bằng thời gian hiện tại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    dtDateUse.Focus();

                    return;
                }

                if (yearRelease > DateTime.Now)
                {
                    MetroMessageBox.Show(this, "Thời gian bảo hành phải nhỏ hơn hoặc bằng thời gian hiện tại!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);

                    dtYearRelease.Focus();

                    return;
                }

                DataGridViewRow row = gvStuffs.SelectedRows.Cast <DataGridViewRow>().FirstOrDefault();

                int id = Convert.ToInt32(gvStuffs["Id", row.Index].Value.ToString());

                string nameStuffOld = gvStuffs["Name", row.Index].Value.ToString();

                string nameStuffNew = txtNameStuffs.Text.Trim();

                DialogResult dialog = MetroMessageBox.Show(this, $"Bạn có chắc chắn muốn sửa vật tự '{nameStuffOld}' thành '{nameStuffNew}' chứ ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, GlobalConstants.Config.HeightAlert);

                if (dialog == DialogResult.Yes)
                {
                    GlobalConstants.ResponseResult res = StuffsBll.Instance.Edit(
                        id,
                        bqCode,
                        stuffName,
                        producer,
                        dateBuy,
                        dateUse,
                        yearRelease,
                        color,
                        state,
                        Convert.ToDecimal(price),
                        warranty,
                        status,
                        Convert.ToInt32(idCategory),
                        GlobalConstants.Username
                        );

                    switch (res.TypeResponse)
                    {
                    case GlobalConstants.EnumResponse.EditSuccess:
                        LogEvent.Log = $"[{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}] - [{GlobalConstants.Username}] - sửa vật tư [{nameStuffOld}] thành [{nameStuffNew}]";

                        MetroMessageBox.Show(this, $"Sửa vật tư '{nameStuffOld}' thành '{nameStuffNew}' thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, GlobalConstants.Config.HeightAlert);

                        row = gvStuffs.Rows.Cast <DataGridViewRow>().Where(p => p.Cells["Id"].Value.ToString().Equals(id.ToString())).FirstOrDefault();

                        if (row != null)
                        {
                            gvStuffs.CurrentCell = row.Cells["Id"];

                            row.Selected = true;

                            txtPriceBuy.Text = row.Cells["PriceBuy"].Value.ToString();
                        }
                        break;

                    case GlobalConstants.EnumResponse.EditFail:
                        MetroMessageBox.Show(this, "Có lỗi trong quá trình sửa dữ liệu, xin vui lòng thử lại sau !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        break;

                    case GlobalConstants.EnumResponse.Unique:
                        MetroMessageBox.Show(this, $"BQCode vật tư '{bqCode}' bị trùng, xin vui lòng nhập BQCode khác !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, GlobalConstants.Config.HeightAlert);
                        txtNameStuffs.Focus();
                        break;
                    }
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Bạn chưa chọn vật tư cần sửa !", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning, GlobalConstants.Config.HeightAlert);
            }

            txtNameStuffs.Focus();
        }