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

                return;
            }
               // BomContext db = new BomContext();
            BrandModel Cur;
            try
            {
                if (clsWin.QuestionMessage("Are you sure want to Delete this record?", "Confirm Delete"))
                {

                    {
                         Cur = new BrandModel()
                        {
                            //Cur.Deleted = true;
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now,
                        };
                        layerBrand.DeleteBrand(Cur,id);
                    }

                    clsWin.SuccessMessage("Brand 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();
            }
        }
示例#2
0
        private void Btn_Save_Click(object sender, System.EventArgs e)
        {
            BrandModel brand;
            try
            {

                if (layerBrand.GetBrandCD((Txt_Brand_CD.Text), id))
                {
                    var exceptionMessage = "Brand Code already exist";
                    // clsWin.ClearWindowsObJect(panelEx1);
                    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                    Txt_Brand_CD.Focus();
                    return;
                }

                if (clsWin.QuestionMessage("Are you sure want to save", "Save Brand"))
                {
                    if (StatusEdit)
                    {
                        brand = new BrandModel
                        {
                            BrandCD = Txt_Brand_CD.Text,
                            BrandName = txt_Brand_Name.Text,
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now,
                        };
                        layerBrand.UpdatetBrand(brand, id);
                    }
                    else
                    {
                        brand = new BrandModel()
                        {
                            bGUID = Guid.NewGuid().ToString(),
                            BrandCD = Txt_Brand_CD.Text,
                            BrandName = txt_Brand_Name.Text,
                            Comp = clsWin.GetComputerName(),
                            UserName = _frmMain.activeuser,
                            LastUpdate = DateTime.Now,
                        };
                        layerBrand.InSertBrand(brand);
                    }
                    clsWin.SuccessMessage("Brand 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();
            }
            ////BomContext db = new BomContext();
            ////BrandModel Brand;
            ////try
            ////{
            ////    if (clsWin.QuestionMessage("Are you sure want to save", "Save Brand"))
            ////    {
            ////        if (StatusEdit)
            ////        {
            ////            Brand = db.Brands.First(i => i.bGUID == id.ToString());
            ////            {

            ////                Brand.BrandCD = Txt_Brand_CD.Text;
            ////                Brand.BrandName = txt_Brand_Name.Text;
            ////                Brand.sGUID = (Cbo_supplier_Brand.SelectedValue.ToString());
            ////                Brand.Comp = clsWin.GetComputerName();
            ////                Brand.UserName = "******";
            ////                Brand.LastUpdate = DateTime.Now;
            ////            }
            ////            db.SaveChanges();
            ////        }
            ////        else
            ////        {
            ////            Brand = new BrandModel()
            ////            {

            ////                bGUID = Guid.NewGuid().ToString(),

            ////                BrandCD = Txt_Brand_CD.Text.ToString(),
            ////                BrandName = txt_Brand_Name.Text.ToString(),
            ////                sGUID =  (Cbo_supplier_Brand.SelectedValue.ToString()),//Guid.Parse(this.Cbo_supplier_Brand.ValueMember.ToString()),
            ////                Comp = clsWin.GetComputerName(),
            ////                UserName = "******",
            ////                LastUpdate = DateTime.Now
            ////            };
            ////            db.Brands.Add(Brand);
            ////        }

            ////        db.SaveChanges();
            ////        clsWin.SuccessMessage("Brand 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();
            ////}
        }