コード例 #1
0
    protected void OnButtonSaveClick(object sender, EventArgs e)
    {
        CompanyContactRepository contactRepo = new CompanyContactRepository();
        CompanyContact contact = GetCompanyContact();
        if (!string.IsNullOrEmpty(Request.QueryString["contactID"])) //edit contact
        {
            int contactID = Int32.Parse(Request.QueryString["contactID"]);
            if (contactID > 0)
            {
                contact.ContactID = contactID;
                contactRepo.Update(contact);
            }
            else
            {
                List<CompanyContact> list = SessionManager.NewCompanyContactList;
                CompanyContact existedItem = list.Find(delegate(CompanyContact t) { return t.ContactID == contactID; });
                if (existedItem != null)
                {
                    int index = list.IndexOf(existedItem);
                    contact.ContactInfo = existedItem.ContactInfo;
                    list.Remove(existedItem);
                    contact.ContactID = existedItem.ContactID;
                    list.Insert(index, contact);
                    SessionManager.NewCompanyContactList = list;
                }
            }

        }
        else //add new
        {
            if (!string.IsNullOrEmpty(Request.QueryString["companyID"]))
            {
                contact.CompanyID = Int32.Parse(Request.QueryString["companyID"]);
                contactRepo.Insert(contact);
            }
            else
            {
                //save to session
                List<CompanyContact> list = SessionManager.NewCompanyContactList;
                contact.ContactID = 0 - list.Count - 2;
                list.Add(contact);
                SessionManager.NewCompanyContactList = list;
            }
        }
        string script = "<script type=\"text/javascript\">";
        script += " OnBtnSaveClientClicked();";
        script += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("saveAndCloseWindow"))
            ClientScript.RegisterStartupScript(this.GetType(), "saveAndCloseWindow", script);
    }
コード例 #2
0
ファイル: Companies.aspx.cs プロジェクト: netthanhhung/Neos
    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);
            }
        }
    }
コード例 #3
0
    private void BindContactListByCompany(int companyId)
    {
        ddlContact.DataTextField = "FullName";
        ddlContact.DataValueField = "ContactID";
        List<CompanyContact> list = new CompanyContactRepository().GetContactOfCompany(companyId);
        list.Insert(0, new CompanyContact(-1));

        ddlContact.DataSource = list;
        ddlContact.DataBind();
    }
コード例 #4
0
    private void SaveCompanyContact(Company currentCompany)
    {
        if (SessionManager.NewCompanyContactList != null
            && SessionManager.NewCompanyContactList.Count > 0
            && currentCompany != null)
        {
            CompanyContactRepository contactRepo = new CompanyContactRepository();
            foreach (CompanyContact contact in SessionManager.NewCompanyContactList)
            {
                contact.CompanyID = currentCompany.CompanyID;
                contactRepo.Insert(contact);
                CompanyContact realContact = contactRepo.FindOne(contact);

                CompanyContactTelephoneRepository telephoneRepo = new CompanyContactTelephoneRepository();
                foreach (CompanyContactTelephone telephone in contact.ContactInfo)
                {
                    telephone.ContactID = realContact.ContactID;
                    telephoneRepo.Insert(telephone);
                }

            }
        }
    }