public virtual void Remove(int id)
 {
     try
     {
         PROFILE_NEW b = this.GetById(id);
         this.Remove(b);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public virtual void Create(PROFILE_NEW cus)
 {
     try
     {
         this.db.PROFILE_NEWs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Remove(PROFILE_NEW b)
 {
     try
     {
         db.PROFILE_NEWs.DeleteOnSubmit(b);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public virtual void Create(PROFILE_NEW cus)
 {
     try
     {
         this.db.PROFILE_NEWs.InsertOnSubmit(cus);
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Update(PROFILE_NEW cus)
 {
     try
     {
         PROFILE_NEW cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void Update(PROFILE_NEW cus)
 {
     try
     {
         PROFILE_NEW cusOld = this.GetById(cus.ID);
         cusOld = cus;
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void InsertDuplicate(PROFILE_NEW cus, int type, int status, int id_prof, int have_services)
 {
     try
     {
         db.PROFILE_NEWs.InsertOnSubmit(
             new PROFILE_NEW {
             PROF_TYPE          = type,
             PROF_NAME          = cus.PROF_NAME,
             PROF_TRANSACTION   = cus.PROF_TRANSACTION,
             PROF_ATC           = cus.PROF_ATC,
             PROF_ADDRESS       = cus.PROF_ADDRESS,
             PROF_TAXCODE       = cus.PROF_TAXCODE,
             PROF_TOTAL_CAPITAL = cus.PROF_TOTAL_CAPITAL == null ? 0 : cus.PROF_TOTAL_CAPITAL,
             PROF_CAPITAL       = cus.PROF_CAPITAL == null ? 0 : cus.PROF_CAPITAL,
             PROF_PHONE         = cus.PROF_PHONE,
             PROF_EMAIL         = cus.PROF_EMAIL,
             PROF_NOTE          = cus.PROF_NOTE,
             PROF_DATE          = DateTime.Now,
             PROF_ACTIVE        = cus.PROF_ACTIVE,
             PROF_STATUS        = status,
             PROF_LEVEL         = cus.PROF_LEVEL,
             PROF_COST1         = cus.PROF_COST1,
             PROF_COST2         = cus.PROF_COST2,
             PROF_DATE_COST     = cus.PROF_DATE_COST,
             PROF_REG1          = cus.PROF_REG1,
             PROF_REG2          = cus.PROF_REG2,
             PROF_FIELD1        = cus.PROF_FIELD1,
             PROF_FIELD2        = cus.PROF_FIELD2,
             PROF_FIELD3        = cus.PROF_FIELD3,
             TRADES_ID          = cus.TRADES_ID,
             MEM_ID             = cus.MEM_ID,
             CAT_ID             = cus.CAT_ID,
             ATT_ID             = cus.ATT_ID,
             USER_ID            = cus.USER_ID,
             HAVE_SERVICES      = have_services,
             PROF_PARENT        = id_prof
         });
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
 public virtual void InsertDuplicate(PROFILE_NEW cus, int type, int status, int id_prof, int have_services)
 {
     try
     {
         db.PROFILE_NEWs.InsertOnSubmit(
             new PROFILE_NEW {
                 PROF_TYPE = type, 
                 PROF_NAME = cus.PROF_NAME,
                 PROF_TRANSACTION = cus.PROF_TRANSACTION,
                 PROF_ATC = cus.PROF_ATC,
                 PROF_ADDRESS = cus.PROF_ADDRESS,
                 PROF_TAXCODE = cus.PROF_TAXCODE,
                 PROF_TOTAL_CAPITAL = cus.PROF_TOTAL_CAPITAL == null ? 0 : cus.PROF_TOTAL_CAPITAL,
                 PROF_CAPITAL = cus.PROF_CAPITAL == null ? 0 : cus.PROF_CAPITAL,
                 PROF_PHONE = cus.PROF_PHONE,
                 PROF_EMAIL = cus.PROF_EMAIL,
                 PROF_NOTE = cus.PROF_NOTE,
                 PROF_DATE = DateTime.Now,
                 PROF_ACTIVE = cus.PROF_ACTIVE,
                 PROF_STATUS = status,
                 PROF_LEVEL = cus.PROF_LEVEL,
                 PROF_COST1 = cus.PROF_COST1,
                 PROF_COST2 = cus.PROF_COST2,
                 PROF_DATE_COST = cus.PROF_DATE_COST,
                 PROF_REG1 = cus.PROF_REG1,
                 PROF_REG2 = cus.PROF_REG2,
                 PROF_FIELD1 = cus.PROF_FIELD1,
                 PROF_FIELD2 = cus.PROF_FIELD2,
                 PROF_FIELD3 = cus.PROF_FIELD3,
                 TRADES_ID = cus.TRADES_ID,
                 MEM_ID = cus.MEM_ID,
                 CAT_ID = cus.CAT_ID,
                 ATT_ID = cus.ATT_ID,
                 USER_ID = cus.USER_ID,
                 HAVE_SERVICES = have_services,
                 PROF_PARENT = id_prof
             });
         db.SubmitChanges();
     }
     catch //(Exception e)
     {
         //throw new Exception(e.Message);
     }
 }
        private void Save(string strLink = "")
        {
            try
            {
                //gán lại session
                _getCookies.getCookiesNew();

                string img          = string.Empty;
                string pathfile     = string.Empty;
                string fullpathfile = string.Empty;
                string path         = string.Empty;
                int    type         = Utils.CIntDef(ddlType.SelectedValue);
                if (_id == 0)
                {
                    /*--------------File-------------*/
                    if (fileUpload.PostedFile.FileName != null)
                    {
                        img = fileUpload.PostedFile.FileName;
                    }
                    /*------------------------------*/

                    PROFILE_NEW i = new PROFILE_NEW();
                    i.PROF_TYPE      = type;
                    i.PROF_FILE      = img;
                    i.PROF_COST1     = Utils.CDecDef(txtTongPhi.Text.Replace(",", ""));
                    i.PROF_COST2     = Utils.CDecDef(txtDaThu.Text.Replace(",", ""));
                    i.PROF_ACTIVE    = 1;
                    i.PROF_STATUS    = 1;
                    i.PROF_LEVEL     = 1;
                    i.PROF_DATE      = DateTime.Now;
                    i.PROF_DATE_COST = txtFromDate.Value != "" ? fmDate(txtFromDate.Value) : i.PROF_DATE_COST = null;
                    i.USER_ID        = Utils.CIntDef(Session["Userid"]);

                    if (type == 2)
                    {
                        i.PROF_NAME    = txtChTenCty.Text;
                        i.PROF_ADDRESS = txtChDiaChi.Text;
                        i.PROF_TAXCODE = txtChMST.Text;
                        i.PROF_PHONE   = txtChDienThoai.Text;
                        i.PROF_NOTE    = txtChContent.Text;
                        i.PROF_EMAIL   = txtChEmail.Text;
                        if (_CongNoData.CheckByMST(txtChMST.Text))
                        {//Chỉ gửi mail cho bên kế toán là hồ sơ có thay đổi
                            if (_CongNoData.GetIdKeToan(txtChMST.Text) == 0)
                            {
                                SendEmailNVKeToanCongNo(txtChMST.Text, _CongNoData.GetIdKeToan(txtChMST.Text));
                            }
                            SendEmailChangeCongNo(txtChMST.Text);
                        }
                    }
                    else
                    {
                        i.PROF_NAME          = txtTenCty.Text;
                        i.PROF_TRANSACTION   = txtTenGiaoDich.Text;
                        i.PROF_ATC           = txtTenVietTat.Text;
                        i.PROF_ADDRESS       = txtTruSoChinh.Text;
                        i.PROF_TOTAL_CAPITAL = Utils.CDecDef(txtTongSoVonGop.Text.Replace(",", ""), 0);
                        i.PROF_CAPITAL       = Utils.CDecDef(txtVonPhapDinh.Text.Replace(",", ""), 0);
                        i.PROF_PHONE         = txtDienThoai.Text;
                        i.PROF_EMAIL         = txtEmail.Text;
                    }
                    _ProjectData.Create(i);
                    SendEmail(type);
                    var getlink = db.PROFILE_NEWs.OrderByDescending(n => n.ID).Take(1).ToList();
                    if (getlink.Count > 0)
                    {
                        if (type == 3)
                        {
                            Save_Employ(getlink[0].ID); //Nếu ở giai đoạn 3 mới cho người nhận là NVXLHS
                        }
                        SaveTypeReg(getlink[0].ID);     //Save TypeReg
                        if (!string.IsNullOrEmpty(fileUpload.PostedFile.FileName))
                        {
                            pathfile     = Server.MapPath("/File/Profile/" + Utils.CStrDef(getlink[0].ID));
                            path         = System.Configuration.ConfigurationManager.AppSettings["URLWebsite"] + "/File/Profile/" + Utils.CStrDef(getlink[0].ID + "/" + img);
                            fullpathfile = pathfile + "/" + img;

                            if (!Directory.Exists(pathfile))
                            {
                                Directory.CreateDirectory(pathfile);
                            }
                            fileUpload.PostedFile.SaveAs(fullpathfile);
                        }

                        strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-ho-so.aspx?id=" + getlink[0].ID : strLink;
                    }
                }
                else
                {
                    /*--------------File-------------*/
                    if (fileUpload.PostedFile.FileName != null && fileUpload.PostedFile.FileName != "")
                    {
                        img = fileUpload.PostedFile.FileName;
                        string pathfileOld     = Server.MapPath("/File/Profile/" + Utils.CStrDef(_id));
                        string fullpathfileOld = pathfileOld + "/" + _ProjectData.GetById(_id).PROF_FILE;
                        /*Trước khi Update file mới ta phải xóa file cũ*/
                        if (File.Exists(fullpathfileOld))
                        {
                            File.Delete(fullpathfileOld);
                        }
                        /*=============================================*/
                    }/*------------------------------*/

                    var list = db.PROFILE_NEWs.Where(n => n.ID == _id).ToList();
                    foreach (var i in list)
                    {
                        if (img != "")
                        {
                            i.PROF_FILE = img;
                        }
                        i.PROF_COST1     = Utils.CDecDef(txtTongPhi.Text.Replace(",", ""));
                        i.PROF_COST2     = Utils.CDecDef(txtDaThu.Text.Replace(",", ""));
                        i.PROF_DATE      = DateTime.Now;
                        i.PROF_DATE_COST = txtFromDate.Value != "" ? fmDate(txtFromDate.Value) : i.PROF_DATE_COST = null;
                        i.USER_ID        = Utils.CIntDef(ddlNameUser.SelectedValue);

                        if (type == 2)
                        {
                            i.PROF_NAME    = txtChTenCty.Text;
                            i.PROF_ADDRESS = txtChDiaChi.Text;
                            i.PROF_TAXCODE = txtChMST.Text;
                            i.PROF_PHONE   = txtChDienThoai.Text;
                            i.PROF_NOTE    = txtChContent.Text;
                            i.PROF_EMAIL   = txtChEmail.Text;
                        }
                        else
                        {
                            i.PROF_NAME        = txtTenCty.Text;
                            i.PROF_TRANSACTION = txtTenGiaoDich.Text;
                            i.PROF_ATC         = txtTenVietTat.Text;
                            i.PROF_ADDRESS     = txtTruSoChinh.Text;
                            //i.TRADES_ID = Utils.CIntDef(ddlNganhKD.SelectedValue);
                            i.PROF_TOTAL_CAPITAL = Utils.CDecDef(txtTongSoVonGop.Text.Replace(",", ""));
                            i.PROF_CAPITAL       = Utils.CDecDef(txtVonPhapDinh.Text.Replace(",", ""));
                            i.PROF_PHONE         = txtDienThoai.Text;
                            i.PROF_EMAIL         = txtEmail.Text;
                            //i.PROF_REG1 = Utils.CIntDef(rdbTypeReg.SelectedValue);
                        }

                        _ProjectData.Update(i);
                    }
                    db.SubmitChanges();
                    SaveTypeReg(Utils.CIntDef(_id));//Save TypeReg
                    if (!string.IsNullOrEmpty(fileUpload.PostedFile.FileName))
                    {
                        pathfile     = Server.MapPath("/File/Profile/" + Utils.CStrDef(_id));
                        path         = System.Configuration.ConfigurationManager.AppSettings["URLWebsite"] + "/File/Profile/" + Utils.CStrDef(_id + "/" + img);
                        fullpathfile = pathfile + "/" + img;
                        if (!Directory.Exists(pathfile))
                        {
                            Directory.CreateDirectory(pathfile);
                        }
                        fileUpload.PostedFile.SaveAs(fullpathfile);
                    }

                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-ho-so.aspx?id=" + _id : strLink;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (!string.IsNullOrEmpty(strLink))
                {
                    //Response.Redirect(strLink);
                    string strScript = "<script>";
                    strScript += "alert('Hồ sơ đã được cập nhật thành công!');";
                    strScript += "window.location='" + strLink + "';";
                    strScript += "</script>";
                    Page.RegisterClientScriptBlock("strScript", strScript);
                }
            }
        }
        private void Save(string strLink = "")
        {
            try
            {
                //gán lại session
                _getCookies.getCookiesNew();

                string img = string.Empty;
                string pathfile = string.Empty;
                string fullpathfile = string.Empty;
                string path = string.Empty;
                int type = Utils.CIntDef(ddlType.SelectedValue);
                if (_id == 0)
                {
                    /*--------------File-------------*/
                    if (fileUpload.PostedFile.FileName != null)
                    {
                        img = fileUpload.PostedFile.FileName;
                    }
                    /*------------------------------*/

                    PROFILE_NEW i = new PROFILE_NEW();
                    i.PROF_TYPE = type;
                    i.PROF_FILE = img;
                    i.PROF_COST1 = Utils.CDecDef(txtTongPhi.Text.Replace(",", ""));
                    i.PROF_COST2 = Utils.CDecDef(txtDaThu.Text.Replace(",", ""));
                    i.PROF_ACTIVE = 1;
                    i.PROF_STATUS = 1;
                    i.PROF_LEVEL = 1;
                    i.PROF_DATE = DateTime.Now;
                    i.PROF_DATE_COST = txtFromDate.Value != "" ? fmDate(txtFromDate.Value) : i.PROF_DATE_COST = null;
                    i.USER_ID = Utils.CIntDef(Session["Userid"]);

                    if (type == 2)
                    {
                        i.PROF_NAME = txtChTenCty.Text;
                        i.PROF_ADDRESS = txtChDiaChi.Text;
                        i.PROF_TAXCODE = txtChMST.Text;
                        i.PROF_PHONE = txtChDienThoai.Text;
                        i.PROF_NOTE = txtChContent.Text;
                        i.PROF_EMAIL = txtChEmail.Text;
                        if (_CongNoData.CheckByMST(txtChMST.Text))
                        {//Chỉ gửi mail cho bên kế toán là hồ sơ có thay đổi
                            if (_CongNoData.GetIdKeToan(txtChMST.Text) == 0)
                                SendEmailNVKeToanCongNo(txtChMST.Text, _CongNoData.GetIdKeToan(txtChMST.Text));
                            SendEmailChangeCongNo(txtChMST.Text);
                        }
                    }
                    else
                    {
                        i.PROF_NAME = txtTenCty.Text;
                        i.PROF_TRANSACTION = txtTenGiaoDich.Text;
                        i.PROF_ATC = txtTenVietTat.Text;
                        i.PROF_ADDRESS = txtTruSoChinh.Text;
                        i.PROF_TOTAL_CAPITAL = Utils.CDecDef(txtTongSoVonGop.Text.Replace(",", ""), 0);
                        i.PROF_CAPITAL = Utils.CDecDef(txtVonPhapDinh.Text.Replace(",", ""), 0);
                        i.PROF_PHONE = txtDienThoai.Text;
                        i.PROF_EMAIL = txtEmail.Text;
                    }
                    _ProjectData.Create(i);
                    SendEmail(type);
                    var getlink = db.PROFILE_NEWs.OrderByDescending(n => n.ID).Take(1).ToList();
                    if (getlink.Count > 0)
                    {
                        if(type == 3) Save_Employ(getlink[0].ID);//Nếu ở giai đoạn 3 mới cho người nhận là NVXLHS
                        SaveTypeReg(getlink[0].ID);//Save TypeReg
                        if (!string.IsNullOrEmpty(fileUpload.PostedFile.FileName))
                        {
                            pathfile = Server.MapPath("/File/Profile/" + Utils.CStrDef(getlink[0].ID));
                            path = System.Configuration.ConfigurationManager.AppSettings["URLWebsite"] + "/File/Profile/" + Utils.CStrDef(getlink[0].ID + "/" + img);
                            fullpathfile = pathfile + "/" + img;

                            if (!Directory.Exists(pathfile))
                            {
                                Directory.CreateDirectory(pathfile);
                            }
                            fileUpload.PostedFile.SaveAs(fullpathfile);
                        }

                        strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-ho-so.aspx?id=" + getlink[0].ID : strLink;
                    }
                }
                else
                {
                    /*--------------File-------------*/
                    if (fileUpload.PostedFile.FileName != null && fileUpload.PostedFile.FileName != "")
                    {
                        img = fileUpload.PostedFile.FileName;
                        string pathfileOld = Server.MapPath("/File/Profile/" + Utils.CStrDef(_id));
                        string fullpathfileOld = pathfileOld + "/" + _ProjectData.GetById(_id).PROF_FILE;
                        /*Trước khi Update file mới ta phải xóa file cũ*/
                        if (File.Exists(fullpathfileOld))
                        {
                            File.Delete(fullpathfileOld);
                        }
                        /*=============================================*/
                    }/*------------------------------*/

                    var list = db.PROFILE_NEWs.Where(n => n.ID == _id).ToList();
                    foreach (var i in list)
                    {
                        if (img != "")
                        {
                            i.PROF_FILE = img;
                        }
                        i.PROF_COST1 = Utils.CDecDef(txtTongPhi.Text.Replace(",", ""));
                        i.PROF_COST2 = Utils.CDecDef(txtDaThu.Text.Replace(",", ""));
                        i.PROF_DATE = DateTime.Now;
                        i.PROF_DATE_COST = txtFromDate.Value != "" ? fmDate(txtFromDate.Value) : i.PROF_DATE_COST = null;
                        i.USER_ID = Utils.CIntDef(ddlNameUser.SelectedValue);

                        if (type == 2)
                        {
                            i.PROF_NAME = txtChTenCty.Text;
                            i.PROF_ADDRESS = txtChDiaChi.Text;
                            i.PROF_TAXCODE = txtChMST.Text;
                            i.PROF_PHONE = txtChDienThoai.Text;
                            i.PROF_NOTE = txtChContent.Text;
                            i.PROF_EMAIL = txtChEmail.Text;
                        }
                        else
                        {
                            i.PROF_NAME = txtTenCty.Text;
                            i.PROF_TRANSACTION = txtTenGiaoDich.Text;
                            i.PROF_ATC = txtTenVietTat.Text;
                            i.PROF_ADDRESS = txtTruSoChinh.Text;
                            //i.TRADES_ID = Utils.CIntDef(ddlNganhKD.SelectedValue);
                            i.PROF_TOTAL_CAPITAL = Utils.CDecDef(txtTongSoVonGop.Text.Replace(",", ""));
                            i.PROF_CAPITAL = Utils.CDecDef(txtVonPhapDinh.Text.Replace(",", ""));
                            i.PROF_PHONE = txtDienThoai.Text;
                            i.PROF_EMAIL = txtEmail.Text;
                            //i.PROF_REG1 = Utils.CIntDef(rdbTypeReg.SelectedValue);
                        }

                        _ProjectData.Update(i);
                    }
                    db.SubmitChanges();
                    SaveTypeReg(Utils.CIntDef(_id));//Save TypeReg
                    if (!string.IsNullOrEmpty(fileUpload.PostedFile.FileName))
                    {

                        pathfile = Server.MapPath("/File/Profile/" + Utils.CStrDef(_id));
                        path = System.Configuration.ConfigurationManager.AppSettings["URLWebsite"] + "/File/Profile/" + Utils.CStrDef(_id + "/" + img);
                        fullpathfile = pathfile + "/" + img;
                        if (!Directory.Exists(pathfile))
                        {
                            Directory.CreateDirectory(pathfile);
                        }
                        fileUpload.PostedFile.SaveAs(fullpathfile);
                    }

                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-ho-so.aspx?id=" + _id : strLink;
                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {

                if (!string.IsNullOrEmpty(strLink))
                {
                    //Response.Redirect(strLink);
                    string strScript = "<script>";
                    strScript += "alert('Hồ sơ đã được cập nhật thành công!');";
                    strScript += "window.location='" + strLink + "';";
                    strScript += "</script>";
                    Page.RegisterClientScriptBlock("strScript", strScript);
                }
            }
        }
 public virtual void Remove(PROFILE_NEW b)
 {
     try
     {
         db.PROFILE_NEWs.DeleteOnSubmit(b);
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }