Exemplo n.º 1
0
    protected void OnButtonSaveClick(object sender, EventArgs e)
    {
        CompanyContactTelephoneRepository contactInfoRepo = new CompanyContactTelephoneRepository();
        CompanyContactTelephone contactInfo = new CompanyContactTelephone();
        if (!string.IsNullOrEmpty(Request.QueryString["contactInfoId"]))
        {
            try
            {
                int contactInfoID = Int32.Parse(Request.QueryString["contactInfoId"]);
                contactInfo = contactInfoRepo.FindOne(new CompanyContactTelephone(contactInfoID));
                if (contactInfo != null)
                {
                    contactInfo.Type = ddlType.SelectedValue;
                    contactInfo.TelephoneZone = txtZone.Text.Trim();
                    contactInfo.Tel = txtPhoneMail.Text.Trim();
                    contactInfo.Location = txtPlace.Text.Trim();

                    contactInfoRepo.Update(contactInfo);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else if (!string.IsNullOrEmpty(Request.QueryString["contactId"]))
        {
            contactInfo.Type = ddlType.SelectedValue;
            contactInfo.TelephoneZone = txtZone.Text.Trim();
            contactInfo.Tel = txtPhoneMail.Text.Trim();
            contactInfo.Location = txtPlace.Text.Trim();

            int contactId = Int16.Parse(Request.QueryString["contactId"]);
            if (contactId > 0)
            {
                contactInfo.ContactID = contactId;
                contactInfoRepo.Insert(contactInfo);
            }
            else
            {
                CompanyContact existedItem = SessionManager.NewCompanyContactList.Find(delegate(CompanyContact t) { return t.ContactID == contactId; });
                if (existedItem != null)
                {
                    contactInfo.ContactID = existedItem.ContactID;
                    contactInfo.ContactTelephoneID = 0 - existedItem.ContactInfo.Count - 2;
                    existedItem.ContactInfo.Add(contactInfo);
                }
            }
        }

        string script = "<script type=\"text/javascript\">";
        script += " OnBtnSaveClientClicked();";
        script += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("saveAndCloseWindow"))
            ClientScript.RegisterStartupScript(this.GetType(), "saveAndCloseWindow", script);
    }
Exemplo n.º 2
0
    protected void OnMyAjaxManagerAjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument.IndexOf("RebindContactGrid") != -1)
        {
            //System.Threading.Thread.Sleep(1000);
            //divContact.Visible = true;
            //divContact.Style.Add("display", "block");
            CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, CompanyContactGrid);
            CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, pnlAddContact);
            string[] args = e.Argument.Split('/');
            if (args.Length == 3)
            {
                try
                {
                    int companyID = Int32.Parse(args[1]);
                    int rowIndex = Int32.Parse(args[2]);
                    CompanyGrid.MasterTableView.ClearSelectedItems();
                    CompanyGrid.MasterTableView.Items[rowIndex - 1].Selected = true;
                }
                catch (Exception ex) { throw ex; }
                CompanyContactGrid.Rebind();
            }
        }
        else if (e.Argument.IndexOf("RebindContactInfoGrid") != -1)
        {
            //divContactInfo.Style.Add("display","block");
            CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, ContactInfoGrid);
            CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, pnlAddContactInfo);
            string[] args = e.Argument.Split('/');
            if (args.Length == 3)
            {
                try
                {
                    int contactID = Int32.Parse(args[1]);
                    int rowIndex = Int32.Parse(args[2]);
                    CompanyContactGrid.MasterTableView.ClearSelectedItems();
                    CompanyContactGrid.MasterTableView.Items[rowIndex - 1].Selected = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                ContactInfoGrid.Rebind();
            }

        }
        else if (e.Argument.IndexOf("AddCompanyContact") != -1)
        {
            CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, CompanyContactGrid);
            string[] args = e.Argument.Split('/');
            if (args.Length == 2)
            {
                try
                {
                    int companyID = Int32.Parse(args[1]);
                    CompanyContactRepository contactRepo = new CompanyContactRepository();
                    CompanyContact contact = new CompanyContact();
                    contact.CompanyID = companyID;
                    contact.LastName = txtLastName.Text.Trim();
                    contact.FirstName = txtFirstName.Text.Trim();
                    contact.Position = ddlFunction.Text;

                    contactRepo.Insert(contact);

                    CompanyContactGrid.Rebind();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        else if (e.Argument.IndexOf("AddContactInfo") != -1)
        {
            CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, ContactInfoGrid);
            string[] args = e.Argument.Split('/');
            if (args.Length == 2)
            {
                try
                {
                    int contactID = Int32.Parse(args[1]);
                    CompanyContactTelephoneRepository contactInfoRepo = new CompanyContactTelephoneRepository();
                    CompanyContactTelephone contactInfo = new CompanyContactTelephone();
                    contactInfo.ContactID = contactID;
                    contactInfo.Type = ddlType.SelectedValue;
                    contactInfo.TelephoneZone = txtPhoneZone.Text.Trim();
                    contactInfo.Tel = txtInfo.Text.Trim();
                    contactInfo.Location = txtPlace.Text.Trim();

                    contactInfoRepo.Insert(contactInfo);

                    ContactInfoGrid.Rebind();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        else if (e.Argument.IndexOf("DeleteSelectedCompany") != -1)
        {
            if (CompanyGrid.SelectedItems.Count == 1)
            {
                CompanyAjaxManager.AjaxSettings.AddAjaxSetting(CompanyAjaxManager, CompanyGrid);
                CompanyRepository companyRepo = new CompanyRepository();
                companyRepo.Delete(new Company(GetSelectedCompanyID()));
                CompanyGrid.Rebind();
            }
        }
        else if (e.Argument.IndexOf("OpenSeletectedCompany") != -1)
        {
            if (CompanyGrid.SelectedItems.Count == 1)
            {
                Response.Redirect(string.Format("~/CompanyProfile.aspx?CompanyId={0}&mode=edit&backurl=visible", GetSelectedCompanyID()), true);
            }
        }
        else if (e.Argument.IndexOf("ViewCompanyActions") != -1)
        {
            if (CompanyGrid.SelectedItems.Count == 1)
            {
                Response.Redirect(string.Format("~/CompanyProfile.aspx?CompanyId={0}&tab=action&mode=edit&backurl=visible", GetSelectedCompanyID()), true);
            }
        }
        else if (e.Argument.IndexOf("ViewCompanyJobs") != -1)
        {
            if (CompanyGrid.SelectedItems.Count == 1)
            {
                Response.Redirect(string.Format("~/CompanyProfile.aspx?CompanyId={0}&tab=job&mode=edit&backurl=visible", GetSelectedCompanyID()), true);
            }
        }
        else if (e.Argument.IndexOf("ViewCompanyInvoices") != -1)
        {
            if (CompanyGrid.SelectedItems.Count == 1)
            {
                Response.Redirect(string.Format("~/InvoicesPage.aspx?type=search&customer={0}", GetSelectedCompanyID()), true);
            }
        }
    }