private void Save(string strLink = "")
        {
            try
            {
                if (_id == 0)
                {
                    if (_NhaCungCapData.CheckCodeExists(txtMaNCC.Text.Trim()))
                    {
                        CKS_NHACUNGCAP i = new CKS_NHACUNGCAP();
                        i.NCC_MA = txtMaNCC.Text;
                        i.NCC_TEN = txtTenNCC.Text;
                        i.NCC_HOA_HONG = Utils.CDecDef(txtHoaHong.Text.Replace(",", ""));
                        i.NCC_ORDER = Utils.CIntDef(txtThuTu.Text);
                        i.NCC_ACTIVE = Utils.CIntDef(rblActive.SelectedValue);
                        i.NCC_TYPE = Utils.CIntDef(rdoType.SelectedValue);
                        _NhaCungCapData.Create(i);
                        var getlink = db.CKS_NHACUNGCAPs.OrderByDescending(n => n.ID).Take(1).ToList();
                        if (getlink.Count > 0)
                        {
                            strLink = string.IsNullOrEmpty(strLink) ? "nha-cung-cap.aspx?id=" + getlink[0].ID : strLink;
                        }
                    }
                    else {
                        string strScript = "<script>";
                        strScript += "alert('Cập nhật thất bại. Mã nhà cung cấp này đã tồn tại!');";
                        strScript += "</script>";
                        Page.RegisterClientScriptBlock("strScript", strScript);
                    }
                }
                else
                {
                    var i = _NhaCungCapData.GetById(_id);
                    if(i != null)
                    {
                        i.NCC_MA = txtMaNCC.Text;
                        i.NCC_TEN = txtTenNCC.Text;
                        i.NCC_HOA_HONG = Utils.CDecDef(txtHoaHong.Text.Replace(",", ""));
                        i.NCC_ORDER = Utils.CIntDef(txtThuTu.Text);
                        i.NCC_ACTIVE = Utils.CIntDef(rblActive.SelectedValue);
                        i.NCC_TYPE = Utils.CIntDef(rdoType.SelectedValue);
                        _NhaCungCapData.Update(i);
                    }
                    db.SubmitChanges();
                    strLink = string.IsNullOrEmpty(strLink) ? "nha-cung-cap.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 (_NhaCungCapData.CheckCodeExists(txtMaNCC.Text.Trim()))
             {
                 CKS_NHACUNGCAP i = new CKS_NHACUNGCAP();
                 i.NCC_MA       = txtMaNCC.Text;
                 i.NCC_TEN      = txtTenNCC.Text;
                 i.NCC_HOA_HONG = Utils.CDecDef(txtHoaHong.Text.Replace(",", ""));
                 i.NCC_ORDER    = Utils.CIntDef(txtThuTu.Text);
                 i.NCC_ACTIVE   = Utils.CIntDef(rblActive.SelectedValue);
                 i.NCC_TYPE     = Utils.CIntDef(rdoType.SelectedValue);
                 _NhaCungCapData.Create(i);
                 var getlink = db.CKS_NHACUNGCAPs.OrderByDescending(n => n.ID).Take(1).ToList();
                 if (getlink.Count > 0)
                 {
                     strLink = string.IsNullOrEmpty(strLink) ? "nha-cung-cap.aspx?id=" + getlink[0].ID : strLink;
                 }
             }
             else
             {
                 string strScript = "<script>";
                 strScript += "alert('Cập nhật thất bại. Mã nhà cung cấp này đã tồn tại!');";
                 strScript += "</script>";
                 Page.RegisterClientScriptBlock("strScript", strScript);
             }
         }
         else
         {
             var i = _NhaCungCapData.GetById(_id);
             if (i != null)
             {
                 i.NCC_MA       = txtMaNCC.Text;
                 i.NCC_TEN      = txtTenNCC.Text;
                 i.NCC_HOA_HONG = Utils.CDecDef(txtHoaHong.Text.Replace(",", ""));
                 i.NCC_ORDER    = Utils.CIntDef(txtThuTu.Text);
                 i.NCC_ACTIVE   = Utils.CIntDef(rblActive.SelectedValue);
                 i.NCC_TYPE     = Utils.CIntDef(rdoType.SelectedValue);
                 _NhaCungCapData.Update(i);
             }
             db.SubmitChanges();
             strLink = string.IsNullOrEmpty(strLink) ? "nha-cung-cap.aspx?id=" + _id : strLink;
         }
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         if (!string.IsNullOrEmpty(strLink))
         {
             Response.Redirect(strLink);
         }
     }
 }
Exemple #3
0
 public virtual void Remove(int id)
 {
     try
     {
         CKS_NHACUNGCAP b = this.GetById(id);
         this.Remove(b);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #4
0
 public virtual void Remove(CKS_NHACUNGCAP b)
 {
     try
     {
         db.CKS_NHACUNGCAPs.DeleteOnSubmit(b);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #5
0
 public virtual void Create(CKS_NHACUNGCAP cus)
 {
     try
     {
         this.db.CKS_NHACUNGCAPs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Remove(CKS_NHACUNGCAP b)
 {
     try
     {
         db.CKS_NHACUNGCAPs.DeleteOnSubmit(b);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public virtual void Create(CKS_NHACUNGCAP cus)
 {
     try
     {
         this.db.CKS_NHACUNGCAPs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
Exemple #8
0
 public virtual void Update(CKS_NHACUNGCAP cus)
 {
     try
     {
         CKS_NHACUNGCAP cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Update(CKS_NHACUNGCAP cus)
 {
     try
     {
         CKS_NHACUNGCAP cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }