Example #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;
            }

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

                    {

                        um = new UnitModel()
                        {
                            UnitCD = Txt_Unit_CD.Text,
                            UnitName = txt_Unit_Name.Text,
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now,
                        };
                        layer.DeleteUnit(um, id);
                    }
                    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();
            }
        }
Example #2
0
        public bool DeleteUnit(UnitModel model, string id)
        {
            try
            {
                ExecuteCommand(cn =>
                {
                    MySqlCommand cmd = new MySqlCommand(@"update unitModel set deleted=1
                            where uGUID=@id", cn);
                    cmd.Parameters.AddWithValue("id", id);
                    rst = cmd.ExecuteNonQuery();
                });
                if (rst == 1)
                    return true;
                else
                    return false;

            }
            catch (Exception)
            {

                throw;
            }
        }
Example #3
0
        private void Btn_Save_Click(object sender, EventArgs e)
        {
            // BomContext db = new BomContext();
            UnitModel um;
            try
            {
                if (layer.GetUnitCD((Txt_Unit_CD.Text),id))
                {
                    var exceptionMessage = "Unit Code already exist";
                    // clsWin.ClearWindowsObJect(panelEx1);
                    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                    Txt_Unit_CD.Focus();
                    return;
                }
                if (clsWin.QuestionMessage("Are you sure want to save", "Save Unit"))
                {

                    if (StatusEdit)
                    {

                        um = new UnitModel()
                        {
                            UnitCD = Txt_Unit_CD.Text,
                            UnitName = txt_Unit_Name.Text,
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now,
                        };
                        layer.UpdatetUnit(um,id);
                    }
                    else
                    {
                        um = new UnitModel()
                        {
                            uGUID = Guid.NewGuid().ToString(),
                            UnitCD = Txt_Unit_CD.Text.ToString(),
                            UnitName = txt_Unit_Name.Text.ToString(),
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now
                        };
                        //db.Units.Add(um);
                        layer.InSertUnit(um);
                    }

                    //db.SaveChanges();
                    clsWin.SuccessMessage("Unit has been saved", "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();
            }
        }
Example #4
0
        public bool UpdatetUnit(UnitModel model,string id)
        {
            try
            {
                ExecuteCommand(cn =>
                {
                    MySqlCommand cmd = new MySqlCommand(@"update unitModel set UnitCD=@UnitCd,
                            UnitName=@Unitname,Comp=@Comp,UserName=@username
                            where uGUID=@id", cn);
                    cmd.Parameters.AddWithValue("id", id);
                    cmd.Parameters.AddWithValue("@UnitCd", model.UnitCD);
                    cmd.Parameters.AddWithValue("@Unitname", model.UnitName);
                    cmd.Parameters.AddWithValue("@Comp", model.Comp);
                    cmd.Parameters.AddWithValue("@username", model.UserName);
                    rst = cmd.ExecuteNonQuery();
                });
                if (rst == 1)
                    return true;
                else
                    return false;

            }
            catch (Exception)
            {

                throw;
            }
        }