public virtual void Remove(CKS_SANPHAM b)
 {
     try
     {
         db.CKS_SANPHAMs.DeleteOnSubmit(b);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public virtual void Remove(int id)
 {
     try
     {
         CKS_SANPHAM b = this.GetById(id);
         this.Remove(b);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public virtual void Create(CKS_SANPHAM cus)
 {
     try
     {
         this.db.CKS_SANPHAMs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Remove(CKS_SANPHAM b)
 {
     try
     {
         db.CKS_SANPHAMs.DeleteOnSubmit(b);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public virtual void Create(CKS_SANPHAM cus)
 {
     try
     {
         this.db.CKS_SANPHAMs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Update(CKS_SANPHAM cus)
 {
     try
     {
         CKS_SANPHAM cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Update(CKS_SANPHAM cus)
 {
     try
     {
         CKS_SANPHAM cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
        private void Save(string strLink = "")
        {
            try
            {
                if (_id == 0)
                {
                    if (_SanPhamData.CheckCodeExists(txtMaSP.Text.Trim()))
                    {
                        CKS_SANPHAM i = new CKS_SANPHAM();
                        i.SP_MA = txtMaSP.Text;
                        i.SP_TEN = txtTenSP.Text;
                        i.SP_PHIDV = Utils.CDecDef(txtPhiDV.Text.Replace(",", ""));
                        i.SP_GIATB = Utils.CDecDef(txtGiaTB.Text.Replace(",", ""));
                        i.SP_VAT = Utils.CDecDef(txtVAT.Text.Replace(",", ""));
                        i.SP_TONGPHI = Utils.CDecDef(txtTongGia.Text.Replace(",", ""));
                        i.SP_SOTHANG = Utils.CIntDef(txtSoThang.Text.Replace(",", ""));
                        i.NCC_MA = ddlMaNCC.SelectedValue;
                        i.SP_ACTIVE = Utils.CIntDef(rblActive.SelectedValue);
                        _SanPhamData.Create(i);
                        var getlink = db.CKS_SANPHAMs.OrderByDescending(n => n.ID).Take(1).ToList();
                        if (getlink.Count > 0)
                        {
                            strLink = string.IsNullOrEmpty(strLink) ? "san-pham.aspx?id=" + getlink[0].ID : strLink;
                        }
                    }
                    else {
                        string strScript = "<script>";
                        strScript += "alert('Cập nhật thất bại. Mã sản phẩm này đã tồn tại!');";
                        strScript += "</script>";
                        Page.RegisterClientScriptBlock("strScript", strScript);
                    }
                }
                else
                {
                    var i = _SanPhamData.GetById(_id);
                    if(i != null)
                    {
                        i.SP_MA = txtMaSP.Text;
                        i.SP_TEN = txtTenSP.Text;
                        i.SP_PHIDV = Utils.CDecDef(txtPhiDV.Text.Replace(",", ""));
                        i.SP_GIATB = Utils.CDecDef(txtGiaTB.Text.Replace(",", ""));
                        i.SP_VAT = Utils.CDecDef(txtVAT.Text.Replace(",", ""));
                        i.SP_TONGPHI = Utils.CDecDef(txtTongGia.Text.Replace(",", ""));
                        i.SP_SOTHANG = Utils.CIntDef(txtSoThang.Text.Replace(",", ""));
                        i.NCC_MA = ddlMaNCC.SelectedValue;
                        i.SP_ACTIVE = Utils.CIntDef(rblActive.SelectedValue);
                        _SanPhamData.Update(i);
                    }
                    db.SubmitChanges();
                    strLink = string.IsNullOrEmpty(strLink) ? "san-pham.aspx?id=" + _id : strLink;
                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {

                if (!string.IsNullOrEmpty(strLink))
                {
                    Response.Redirect(strLink);
                }
            }
        }
 private void Save(string strLink = "")
 {
     try
     {
         if (_id == 0)
         {
             if (_SanPhamData.CheckCodeExists(txtMaSP.Text.Trim()))
             {
                 CKS_SANPHAM i = new CKS_SANPHAM();
                 i.SP_MA      = txtMaSP.Text;
                 i.SP_TEN     = txtTenSP.Text;
                 i.SP_PHIDV   = Utils.CDecDef(txtPhiDV.Text.Replace(",", ""));
                 i.SP_GIATB   = Utils.CDecDef(txtGiaTB.Text.Replace(",", ""));
                 i.SP_VAT     = Utils.CDecDef(txtVAT.Text.Replace(",", ""));
                 i.SP_TONGPHI = Utils.CDecDef(txtTongGia.Text.Replace(",", ""));
                 i.SP_SOTHANG = Utils.CIntDef(txtSoThang.Text.Replace(",", ""));
                 i.NCC_MA     = ddlMaNCC.SelectedValue;
                 i.SP_ACTIVE  = Utils.CIntDef(rblActive.SelectedValue);
                 _SanPhamData.Create(i);
                 var getlink = db.CKS_SANPHAMs.OrderByDescending(n => n.ID).Take(1).ToList();
                 if (getlink.Count > 0)
                 {
                     strLink = string.IsNullOrEmpty(strLink) ? "san-pham.aspx?id=" + getlink[0].ID : strLink;
                 }
             }
             else
             {
                 string strScript = "<script>";
                 strScript += "alert('Cập nhật thất bại. Mã sản phẩm này đã tồn tại!');";
                 strScript += "</script>";
                 Page.RegisterClientScriptBlock("strScript", strScript);
             }
         }
         else
         {
             var i = _SanPhamData.GetById(_id);
             if (i != null)
             {
                 i.SP_MA      = txtMaSP.Text;
                 i.SP_TEN     = txtTenSP.Text;
                 i.SP_PHIDV   = Utils.CDecDef(txtPhiDV.Text.Replace(",", ""));
                 i.SP_GIATB   = Utils.CDecDef(txtGiaTB.Text.Replace(",", ""));
                 i.SP_VAT     = Utils.CDecDef(txtVAT.Text.Replace(",", ""));
                 i.SP_TONGPHI = Utils.CDecDef(txtTongGia.Text.Replace(",", ""));
                 i.SP_SOTHANG = Utils.CIntDef(txtSoThang.Text.Replace(",", ""));
                 i.NCC_MA     = ddlMaNCC.SelectedValue;
                 i.SP_ACTIVE  = Utils.CIntDef(rblActive.SelectedValue);
                 _SanPhamData.Update(i);
             }
             db.SubmitChanges();
             strLink = string.IsNullOrEmpty(strLink) ? "san-pham.aspx?id=" + _id : strLink;
         }
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         if (!string.IsNullOrEmpty(strLink))
         {
             Response.Redirect(strLink);
         }
     }
 }