Beispiel #1
0
    /// <summary>
    /// Loads the current profiles from a file.
    /// </summary>
    public void LoadCurrentProfiles()
    {
        // The on error action when loading the file:
        Action onError = () => {
            UserProfiles = new ProfileData[CoreManager.MAX_PROFILES] {
                new ProfileData(), new ProfileData(),
                new ProfileData(), new ProfileData()
            };
        };

        // Find if the profiles file exists:
        var dataPath = Path.GetFullPath(Path.Combine(Application.persistentDataPath, PROFILES_FILE));

        if (File.Exists(dataPath))
        {
            // Try to load the descriptor:
            var descriptor = LoadXml <ProfilesXml>(dataPath);
            if (descriptor == null)
            {
                onError();
            }
            else
            {
                // Create the current profile data:
                UserProfiles = ProfileData.Create(descriptor);
            }
        }
        else
        {
            onError();
        }
    }
        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);
                }
            }
        }