Пример #1
0
    private Company SaveCompanyData()
    {
        if (string.IsNullOrEmpty(txtCompanyName.Text))
        {
            string message = ResourceManager.GetString("messageComNameMustNotBeEmpty");
            string script = "<script type=\"text/javascript\">";
            script += " alert(\"" + message + "\")";
            script += " </script>";

            if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
            return null;
        }
        bool isNew = false;
        //Save Company
        Company currentCompany = new Company();
        if (SessionManager.CurrentCompany != null)
        {
            currentCompany = SessionManager.CurrentCompany;
        }
        else
        {
            isNew = true;
            currentCompany = new Company();
        }

        //header
        currentCompany.CompanyName = txtCompanyName.Text.Trim();
        currentCompany.WebLink = txtWebsite.Text.Trim();
        if (!string.IsNullOrEmpty(ddlNeosResp.SelectedValue))
            currentCompany.Responsible = ddlNeosResp.SelectedValue;
        else
            currentCompany.Responsible = null;
        //tab contact info
        currentCompany.Address = txtCompanyAddress.Text.Trim();
        currentCompany.ZipCode = txtCompanyZipCode.Text.Trim();
        currentCompany.City = txtCompanyCity.Text.Trim();
        currentCompany.Email = txtCompanyEmail.Text.Trim();
        currentCompany.TelephoneZone = txtCompanyPhoneArea.Text.Trim();
        currentCompany.Group = txtCompanyGroup.Text.Trim();
        currentCompany.Telephone = txtCompanyPhone.Text.Trim();
        currentCompany.Fax = txtCompanyFax.Text.Trim();
        currentCompany.NVAT = txtCompanyVAT.Text.Trim();
        if (!string.IsNullOrEmpty(ddlCompanyLegalForm.SelectedValue))
            currentCompany.LegalForm = ddlCompanyLegalForm.SelectedValue;
        else
            currentCompany.LegalForm = null;

        if (!string.IsNullOrEmpty(ddlParamClientStatus.SelectedValue))
            currentCompany.Status = int.Parse(ddlParamClientStatus.SelectedValue);
        else
            currentCompany.Status = null;

        //tab client info
        currentCompany.Activity = txtActivity.Text.Trim();
        currentCompany.Remark = txtRemark.Text.Trim();
        currentCompany.CreatedDate = datCreatedDate.SelectedDate;
        if (!string.IsNullOrEmpty(ddlUnit.SelectedValue))
            currentCompany.UnitCode = ddlUnit.SelectedValue;
        else
            currentCompany.UnitCode = null;
        currentCompany.SponsorArea = chkSponsor.Checked;

        CompanyRepository repo = new CompanyRepository();
        if (isNew)
        {
            currentCompany.CreatedDate = DateTime.Now;
            repo.Insert(currentCompany);
        }
        else
            repo.Update(currentCompany);
        //insert company logo
        if (chkRemoveLogo.Checked)
        {
            CompanyLogoRepository companyLogoRepo = new CompanyLogoRepository();
            companyLogoRepo.Delete(new CompanyLogo(currentCompany.CompanyID));
        }
        else
        {
            if (fileCompanyLogo.HasFile)
            {
                string fileName = string.Format("{0}_{1}", currentCompany.CompanyID, System.IO.Path.GetFileName(fileCompanyLogo.PostedFile.FileName.ToString()));//fileCompanyLogo.PostedFile.FileName
                CompanyLogoRepository companyLogoRepo = new CompanyLogoRepository();
                CompanyLogo logo = companyLogoRepo.FindOne(new CompanyLogo(currentCompany.CompanyID));
                if (logo != null)
                {
                    logo.LogoPath = WebConfig.UserImagePath + fileName;
                    companyLogoRepo.Update(logo);
                }
                else
                {
                    logo = new CompanyLogo();
                    logo.CompanyID = currentCompany.CompanyID;
                    logo.LogoPath = WebConfig.UserImagePath + fileName;
                    companyLogoRepo.Insert(logo);
                }
                fileCompanyLogo.SaveAs(WebConfig.UserImages + fileName);
            }
        }
        currentCompany = repo.FindOne(currentCompany);
        SessionManager.CurrentCompany = currentCompany;
        SaveLastViewCompaniesToCookie(currentCompany);
        if (isNew)
        {
            string script1 = "<script type='text/javascript'>";
            script1 += "onSaveOrLoadCompanyProfilePage();";
            script1 += "</script>";
            if (!ClientScript.IsClientScriptBlockRegistered("onSaveOrLoadCompanyProfilePage"))
                ClientScript.RegisterStartupScript(this.GetType(), "onSaveOrLoadCompanyProfilePage", script1);
        }

        //Save company contact
        SaveCompanyContact(currentCompany);

        return currentCompany;
    }
Пример #2
0
    private void FillCurrentCompanyInfo(Company currentCompany)
    {
        //header
        txtCompanyName.Text = currentCompany.CompanyName;
        txtCompanyID.Text = currentCompany.CompanyID.ToString();
        txtWebsite.Text = currentCompany.WebLink;
        lnkWebsite.Text = !string.IsNullOrEmpty(currentCompany.WebLink) ? currentCompany.WebLink : "n/a";
        lnkWebsite.NavigateUrl = !string.IsNullOrEmpty(currentCompany.WebLink) ? (currentCompany.WebLink.StartsWith("http://") ? currentCompany.WebLink : "http://" + currentCompany.WebLink) : "";

        lnkWebsiteTitle.NavigateUrl = !string.IsNullOrEmpty(currentCompany.WebLink) ? (currentCompany.WebLink.StartsWith("http://") ? currentCompany.WebLink : "http://" + currentCompany.WebLink) : "";

        CompanyLogo logo = new CompanyLogoRepository().FindOne(new CompanyLogo(currentCompany.CompanyID));
        if (logo != null)
        {
            lnkLogo.Text = !string.IsNullOrEmpty(logo.LogoPath) ? logo.LogoPath.Substring(logo.LogoPath.LastIndexOf('/') + 1) : "n/a";
            lnkLogo.NavigateUrl = "#";
            imgCompanyLogo.ImageUrl = logo.LogoPath;
        }
        else
        {
            imgCompanyLogo.Visible = false;
        }

        ddlNeosResp.SelectedValue = currentCompany.Responsible;
        //tab contact info
        txtCompanyAddress.Text = currentCompany.Address;
        txtCompanyZipCode.Text = currentCompany.ZipCode;
        txtCompanyCity.Text = currentCompany.City;
        txtCompanyEmail.Text = currentCompany.Email;
        txtCompanyPhoneArea.Text = currentCompany.TelephoneZone;
        txtCompanyGroup.Text = currentCompany.Group;
        txtCompanyPhone.Text = currentCompany.Telephone;
        txtCompanyFax.Text = currentCompany.Fax;
        txtCompanyVAT.Text = currentCompany.NVAT;
        lnkAddContact.OnClientClick = string.Format("return OnAddNewCompanyContactClientClicked('{0}')", currentCompany.CompanyID);
        ddlCompanyLegalForm.SelectedValue = currentCompany.LegalForm;
        ddlParamClientStatus.SelectedValue = currentCompany.Status.HasValue ? currentCompany.Status.Value.ToString() : "";
        //tab client info
        txtActivity.Text = currentCompany.Activity;
        txtRemark.Text = currentCompany.Remark;
        datCreatedDate.SelectedDate = currentCompany.CreatedDate;
        ddlUnit.SelectedValue = currentCompany.UnitCode;
        chkSponsor.Checked = currentCompany.SponsorArea.HasValue ? currentCompany.SponsorArea.Value : false;

        //tab job
        lnkAddNewJob.NavigateUrl = string.Format("~/JobProfile.aspx?CompanyId={0}&mode=edit", currentCompany.CompanyID);
    }