Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (SessionManager.CurrentUser == null)
        {
            Common.RedirectToLoginPage(this);
            return;
        }
        else if (!IsPostBack)
        {
            FillLabelLanguage();
            InitData();
            if (!string.IsNullOrEmpty(SessionManager.BackUrl)
                && SessionManager.BackUrl.Contains("Companies.aspx")
                && !string.IsNullOrEmpty(Request.QueryString["backurl"])
                && Request.QueryString["backurl"] == "visible")
            {
                lnkBack.Visible = true;
            }
            else
            {
                SessionManager.BackUrl = null;
                lnkBack.Visible = false;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["CompanyId"]))
            {
                lnkAddNewDocument.Attributes.Add("onclick", string.Format("OnComDocumentEditClientClicked({0},\"\")", Request.QueryString["CompanyID"]));

                int companyD = int.Parse(Request.QueryString["CompanyId"]);
                CompanyRepository companyRepo = new CompanyRepository();
                Company currentCompany = companyRepo.FindOne(companyD);
                SessionManager.CurrentCompany = currentCompany;
                SaveLastViewCompaniesToCookie(currentCompany);
                string script1 = "<script type='text/javascript'>";
                script1 += "onSaveOrLoadCompanyProfilePage();";
                script1 += "</script>";
                if (!ClientScript.IsClientScriptBlockRegistered("onSaveOrLoadCompanyProfilePage"))
                    ClientScript.RegisterStartupScript(this.GetType(), "onSaveOrLoadCompanyProfilePage", script1);

                //Fill data for grids.
                FillDataGrid(currentCompany);
                FillCurrentCompanyInfo(currentCompany);
                if (Request.QueryString["originalPage"] == "Action")
                {
                    lnkBackToAction.Visible = true;
                    lnkBack.Visible = false;
                    hidActionUrl.Value = Request.UrlReferrer.PathAndQuery;
                }
                else
                {
                    lnkBackToAction.Visible = false;
                }
                if (Request.QueryString["mode"] == "view")
                {
                    EnableCompanyControls(false);
                }
                else
                    EnableCompanyControls(true);

                if (!string.IsNullOrEmpty(Request.QueryString["tab"]))// == "action")
                {
                    switch (Request.QueryString["tab"])
                    {
                        case "action":
                            radTabStripCompany.FindTabByValue("Actions").Selected = true;
                            radTabStripCompany.FindTabByValue("Actions").PageView.Selected = true;
                            break;
                        case "job":
                            radTabStripCompany.FindTabByValue("Job").Selected = true;
                            radTabStripCompany.FindTabByValue("Job").PageView.Selected = true;
                            break;
                        case "invoice":
                            radTabStripCompany.FindTabByValue("Invoice").Selected = true;
                            radTabStripCompany.FindTabByValue("Invoice").PageView.Selected = true;
                            break;
                    }
                }
                //show the company title
                lblCompanyProfileTitle.Text = string.Format(ResourceManager.GetString("lblRightPaneCompanyProfileTitle"), currentCompany.CompanyName);
            }
            else
            {
                SessionManager.CurrentCompany = null;
                SessionManager.NewCompanyContactList = new List<CompanyContact>();

                FillDataGrid(null);
                EnableCompanyControls(true);

                btnEditSave.Text = ResourceManager.GetString("saveText");
                //lnkAddContact.Visible = false;
                //lnkAddContactInfo.Visible = false;
                lnkAddContact.OnClientClick = "return OnAddNewCompanyContactClientClicked('')";
                SessionManager.NewCompanyContactList = null;
                lnkAddNewAction.Visible = false;
                chkRemoveLogo.Visible = false;
                lnkAddNewDocument.Visible = false;
                //show the title
                lblCompanyProfileTitle.Text = ResourceManager.GetString("lblRightPaneAddNewCompanyTitle");
            }
        }
        string script = "<script type='text/javascript'>";
        script += "onLoadCompanyProfilePage();";
        script += "</script>";
        if (!ClientScript.IsClientScriptBlockRegistered("LoadCompanyProfilePage"))
            ClientScript.RegisterStartupScript(this.GetType(), "LoadCompanyProfilePage", script);
    }
Ejemplo n.º 2
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;
    }