private void BindContactCompany()
    {
        try
        {
            ContactCompanies             company = new ContactCompanies();
            LPWeb.Model.ContactCompanies model   = new LPWeb.Model.ContactCompanies();
            DataSet ds = company.GetList(0, "", " [Name] asc");
            //DataSet ds = company.GetAllList();
            if (ds == null)
            {
                return;
            }

            ddlCompany.DataValueField = "ContactCompanyID";
            ddlCompany.DataTextField  = "Name";
            ddlCompany.Items.Add(new ListItem("--select--", "0"));
            ddlCompany.SelectedIndex = 0;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ddlCompany.Items.Add(new ListItem(dr["Name"].ToString(), dr["ContactCompanyID"].ToString()));
            }
        }
        catch
        { }
    }
Exemple #2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <LPWeb.Model.ContactCompanies> DataTableToList(DataTable dt)
        {
            List <LPWeb.Model.ContactCompanies> modelList = new List <LPWeb.Model.ContactCompanies>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                LPWeb.Model.ContactCompanies model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new LPWeb.Model.ContactCompanies();
                    if (dt.Rows[n]["ContactCompanyId"].ToString() != "")
                    {
                        model.ContactCompanyId = int.Parse(dt.Rows[n]["ContactCompanyId"].ToString());
                    }
                    model.Name          = dt.Rows[n]["Name"].ToString();
                    model.Address       = dt.Rows[n]["Address"].ToString();
                    model.City          = dt.Rows[n]["City"].ToString();
                    model.State         = dt.Rows[n]["State"].ToString();
                    model.Zip           = dt.Rows[n]["Zip"].ToString();
                    model.ServiceTypes  = dt.Rows[n]["ServiceTypes"].ToString();
                    model.Enabled       = dt.Rows[n]["Enabled"] == DBNull.Value ? false : Convert.ToBoolean(dt.Rows[n]["Enabled"]);
                    model.ServiceTypeId = dt.Rows[n]["ServiceTypeId"] == DBNull.Value ? 0 : Convert.ToInt32(dt.Rows[n]["ServiceTypeId"]);

                    modelList.Add(model);
                }
            }
            return(modelList);
        }
    private void BindContactCompany(int ContactCompanyID)
    {
        try
        {
            BindContactCompany();
            ContactCompanies             company = new ContactCompanies();
            LPWeb.Model.ContactCompanies model   = new LPWeb.Model.ContactCompanies();
            model = company.GetModel(ContactCompanyID);
            if (model == null)
            {
                return;
            }

            ddlCompany.SelectedValue          = ContactCompanyID.ToString();
            ddlServiceTypes.SelectedItem.Text = model.ServiceTypes;
        }
        catch
        { }
    }
    protected void ddlCompany_onSelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCompany.SelectedIndex == 0)
        {
            PageCommon.AlertMsg(this, "Please select a partner company.");
            return;
        }
        int companyId = Convert.ToInt32(ddlCompany.SelectedValue.Trim());

        LPWeb.Model.ContactCompanies model = new LPWeb.Model.ContactCompanies();

        LPWeb.BLL.ContactCompanies cCompany = new ContactCompanies();
        model = cCompany.GetModel(companyId);

        ddlState.SelectedValue = model.State.Trim();
        txbZip.Text            = model.Zip.Trim();
        txbAddress.Text        = model.Address.Trim();
        txbCity.Text           = model.City.Trim();
        BindContactBranch();
    }
    protected void btImportARM_Click(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["upfile"] == null)
            {
                Write(0, "");
                return;
            }

            if (!fileUpARM.HasFile)
            {
                Write(0, "no file");
                return;
            }

            DataTable dtExcelData = new DataTable();

            #region   文件数据 读取
            string FilePath = this.fileUpARM.FileName;
            //string strUploadUrl = Server.MapPath("./");//此"."可以换成项目文件里的其它文件夹名称
            string strUploadUrl = Server.MapPath("~/");//此"."可以换成项目文件里的其它文件夹名称
            strUploadUrl = strUploadUrl.Replace("Settings\\", "");

            #region   文件到临时文件夹
            string strUploadFolder = @"\UploadFiles\\Temp\\";
            // 临时文件夹
            //string sTempUploadFold = strUploadUrl + strUploadFolder;  // this.MapPath("~/UploadFiles/Temp/");
            string sTempUploadFold = strUploadUrl;
            string sFileExt1       = Path.GetExtension(this.fileUpARM.FileName).ToLower();
            string sTempFileName1  = Guid.NewGuid().ToString() + sFileExt1;

            // 临时文件路径
            string sTempFilePath1 = Path.Combine(sTempUploadFold, sTempFileName1); // "D:\\Test\\" + FilePath;//

            try
            {
                // 文件上传到临时文件夹
                this.fileUpARM.SaveAs(sTempFilePath1);
            }
            catch (Exception ex)
            {
                string exmsg = string.Format("Failed to upload the file due to insufficient privilege: {0}", ex.Message);
                PageCommon.WriteJsEnd(this, exmsg, PageCommon.Js_RefreshSelf);
            }

            #endregion
            try
            {
                PageCommon commonMgr = new PageCommon();
                if (sTempFilePath1.Substring(sTempFilePath1.LastIndexOf(".")).ToLower() == ".xlsx")
                {
                    dtExcelData = commonMgr.GetTableFromXlsx(sTempFilePath1);
                }
                else if (sTempFilePath1.Substring(sTempFilePath1.LastIndexOf(".")).ToLower() == ".xls")
                {
                    dtExcelData = commonMgr.GetTableFromXls(sTempFilePath1);
                }
                else if (sTempFilePath1.Substring(sTempFilePath1.LastIndexOf(".")).ToLower() == ".csv")
                {
                    dtExcelData = commonMgr.GetTableFromCsv(sTempFilePath1);
                }
            }
            catch (Exception ex)
            {
                Write(0, "Import Error. Please make sure row 1 of the file has data.");
                return;
            }
            finally
            {
                if (File.Exists(sTempFilePath1))
                {
                    File.Delete(sTempFilePath1);
                }
            }
            #endregion

            if (dtExcelData == null || dtExcelData.Rows.Count == 0)
            {
                Write(0, "No Data");
                return;
            }

            List <LPWeb.Model.Company_LoanProgramDetails> detailList = new List <LPWeb.Model.Company_LoanProgramDetails>();
            #region Check Data

            if (dtExcelData.Columns.Count < 7)
            {
                Write(0, "Columns err");
                return;
            }
            int  rowNum = 2;
            bool isErr  = false;
            foreach (DataRow dr in dtExcelData.Rows)
            {
                var lpDetail = new LPWeb.Model.Company_LoanProgramDetails();

                lpDetail.Enabled = true;

                if (dr["Investor"] != DBNull.Value)
                {
                    lpDetail.Investor = dr["Investor"].ToString();
                }

                if (dr["Program"] != DBNull.Value)
                {
                    lpDetail.Program = dr["Program"].ToString();
                }

                if (dr["Index"] != DBNull.Value)
                {
                    lpDetail.IndexType = dr["Index"].ToString();
                }

                if (dr["Margin"] != DBNull.Value)
                {
                    try
                    {
                        lpDetail.Margin = Convert.ToDecimal(ReplaceEToD(dr["Margin"]));
                    }
                    catch
                    {
                        Write(0, "The following rows/Column contain invalid data:Row <" + rowNum + "> Column <Margin> must be decimal.");
                        isErr = true;
                        break;
                    }
                }

                if (dr["1st Adj"] != DBNull.Value)
                {
                    try
                    {
                        lpDetail.FirstAdj = Convert.ToDecimal(ReplaceEToD(dr["1st Adj"]));
                    }
                    catch
                    {
                        Write(0, "The following rows/Column contain invalid data:Row <" + rowNum + "> Column <FirstAdj> must be decimal.");
                        isErr = true;
                        break;
                    }
                }

                if (dr["Sub Adj"] != DBNull.Value)
                {
                    try
                    {
                        lpDetail.SubAdj = Convert.ToDecimal(ReplaceEToD(dr["Sub Adj"]));
                    }
                    catch
                    {
                        Write(0, "The following rows/Column contain invalid data:Row <" + rowNum + "> Column <Sub Adj> must be decimal.");
                        isErr = true;
                        break;
                    }
                }

                if (dr["Lifetime"] != DBNull.Value)
                {
                    try
                    {
                        lpDetail.LifetimeCap = Convert.ToDecimal(ReplaceEToD(dr["Lifetime"]));
                    }
                    catch
                    {
                        Write(0, "The following rows/Column contain invalid data:Row <" + rowNum + "> Column <Lifetime> must be decimal.");
                        isErr = true;
                        break;
                    }
                }


                rowNum++;

                detailList.Add(lpDetail);
            }

            if (isErr)
            {
                return;
            }

            #endregion


            #region Import

            ServiceTypes bllServiceTypes = new ServiceTypes();
            LPWeb.BLL.ContactCompanies bllContactCompanies   = new ContactCompanies();
            Company_LoanProgramDetails bllLoanProgramDetails = new Company_LoanProgramDetails();
            foreach (LPWeb.Model.Company_LoanProgramDetails detail in detailList)
            {
                #region LoanProgramID
                LPWeb.Model.Company_Loan_Programs loanpro = bllLoanProgram.GetModelList(" LoanProgram ='" + detail.Program.Trim() + "'").FirstOrDefault();

                if (loanpro != null && loanpro.LoanProgram.Trim() == detail.Program.Trim())
                {
                    detail.LoanProgramID = loanpro.LoanProgramID;

                    if (!loanpro.IsARM)
                    {
                        loanpro.IsARM = true;
                        bllLoanProgram.Update(loanpro);
                    }
                }
                else
                {
                    loanpro             = new LPWeb.Model.Company_Loan_Programs();
                    loanpro.IsARM       = true;
                    loanpro.LoanProgram = detail.Program;

                    int loanprogramsId = bllLoanProgram.Add(loanpro);

                    detail.LoanProgramID = loanprogramsId;
                }
                #endregion


                #region InvestorID

                //detail.LenderCompanyId; 已取出  在CR67
                var    ServiceType           = bllServiceTypes.GetModelList(" Name ='Investor'").FirstOrDefault(); //cr67
                int    InvestorServiceTypeId = ServiceType == null ? 0 : ServiceType.ServiceTypeId;
                string sWhere = string.Format("[Name]='{0}'", detail.Investor.Trim());
                if (InvestorServiceTypeId > 0)
                {
                    sWhere += " AND ServiceTypeId=" + InvestorServiceTypeId;
                }

                LPWeb.Model.ContactCompanies contactComp = bllContactCompanies.GetModelList(sWhere).FirstOrDefault();

                if (contactComp != null && contactComp.Name.Trim() == detail.Investor.Trim())
                {
                    detail.InvestorID = contactComp.ContactCompanyId;
                }
                else
                {
                    contactComp = new LPWeb.Model.ContactCompanies();

                    contactComp.Name = detail.Investor.Trim();
                    //var type = bllServiceTypes.GetModelList(" Name ='Lender' or Name = 'Lending '").FirstOrDefault();
                    if (ServiceType != null)
                    {
                        contactComp.ServiceTypeId = ServiceType.ServiceTypeId;
                        contactComp.ServiceTypes  = ServiceType.Name;
                    }
                    contactComp.Enabled = true;

                    var contactCompanyId = bllContactCompanies.Add(contactComp);

                    detail.InvestorID = contactCompanyId;
                }



                #endregion

                if (bllLoanProgramDetails.Exists(detail.LoanProgramID, detail.InvestorID))
                {
                    bllLoanProgramDetails.Update(detail);
                }
                else
                {
                    bllLoanProgramDetails.Add(detail);
                }
            }


            #endregion


            Write(1, "");
        }
        catch (Exception ex)
        {
            Write(0, ex.Message.Replace("'", "").Replace("\r\n", ""));
        }
    }
Exemple #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(LPWeb.Model.ContactCompanies model)
 {
     dal.Update(model);
 }
Exemple #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(LPWeb.Model.ContactCompanies model)
 {
     return(dal.Add(model));
 }
    private void BindLables()
    {
        if (iContactID == 0)
        {
            return;
        }
        int    iContactBranchID = 0;
        int    iCompanyID       = 0;
        string raw_data         = "";
        string processed_data   = " ";

        try
        {
            Contacts             bllContact = new Contacts();
            LPWeb.Model.Contacts mContact   = new LPWeb.Model.Contacts();
            mContact = bllContact.GetModel(iContactID);

            lbName.Text    = mContact.LastName + ", " + mContact.FirstName;
            lbEnabled.Text = mContact.Enabled?"Yes":"No";

            if (mContact.CellPhone != null)
            {
                raw_data = mContact.CellPhone.Trim();

                raw_data = System.Text.RegularExpressions.Regex.Replace(raw_data, @"[-() ]", String.Empty);

                if (raw_data.Length > 10)
                {
                    raw_data = raw_data.Substring(0, 10);
                }

                if (raw_data.Length == 10)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 4);
                }
                else if (raw_data.Length == 9)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 3);
                }
                else if (raw_data.Length == 8)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 2);
                }
                else if (raw_data.Length == 7)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 1);
                }
                else if (raw_data.Length == 6)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-";
                }
                else if (raw_data.Length == 5)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 2) + " -";
                }
                else if (raw_data.Length == 4)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 1) + "  -";
                }
                else if (raw_data.Length == 3)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + "   -";
                }
                else if (raw_data.Length == 2)
                {
                    processed_data = "(" + raw_data.Substring(0, 2) + " ) " + "   -";
                }
                else if (raw_data.Length == 1)
                {
                    processed_data = "(" + raw_data.Substring(0, 1) + "  ) " + "   -";
                }
                else
                {
                    processed_data = "(   )    -    ";
                }
            }
            else
            {
                processed_data = "(   )    -    ";
            }
            lbCellPhone.Text = processed_data;

            if (mContact.BusinessPhone != null)
            {
                raw_data = mContact.BusinessPhone.Trim();

                raw_data = System.Text.RegularExpressions.Regex.Replace(raw_data, @"[-() ]", String.Empty);
                if (raw_data.Length > 10)
                {
                    raw_data = raw_data.Substring(0, 10);
                }

                if (raw_data.Length == 10)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 4);
                }
                else if (raw_data.Length == 9)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 3);
                }
                else if (raw_data.Length == 8)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 2);
                }
                else if (raw_data.Length == 7)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 1);
                }
                else if (raw_data.Length == 6)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-";
                }
                else if (raw_data.Length == 5)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 2) + " -";
                }
                else if (raw_data.Length == 4)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 1) + "  -";
                }
                else if (raw_data.Length == 3)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + "   -";
                }
                else if (raw_data.Length == 2)
                {
                    processed_data = "(" + raw_data.Substring(0, 2) + " ) " + "   -";
                }
                else if (raw_data.Length == 1)
                {
                    processed_data = "(" + raw_data.Substring(0, 1) + "  ) " + "   -";
                }
                else
                {
                    processed_data = "(   )    -    ";
                }
            }
            else
            {
                processed_data = "(   )    -    ";
            }
            lbBussinessPhone.Text = processed_data;

            raw_data = mContact.Fax;
            if (mContact.Fax != null)
            {
                raw_data = mContact.Fax.Trim();

                raw_data = System.Text.RegularExpressions.Regex.Replace(raw_data, @"[-() ]", String.Empty);
                if (raw_data.Length > 10)
                {
                    raw_data = raw_data.Substring(0, 10);
                }

                if (raw_data.Length == 10)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 4);
                }
                else if (raw_data.Length == 9)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 3);
                }
                else if (raw_data.Length == 8)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 2);
                }
                else if (raw_data.Length == 7)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 1);
                }
                else if (raw_data.Length == 6)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-";
                }
                else if (raw_data.Length == 5)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 2) + " -";
                }
                else if (raw_data.Length == 4)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 1) + "  -";
                }
                else if (raw_data.Length == 3)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + "   -";
                }
                else if (raw_data.Length == 2)
                {
                    processed_data = "(" + raw_data.Substring(0, 2) + " ) " + "   -";
                }
                else if (raw_data.Length == 1)
                {
                    processed_data = "(" + raw_data.Substring(0, 1) + "  ) " + "   -";
                }
                else
                {
                    processed_data = "(   )    -    ";
                }
            }
            else
            {
                processed_data = "(   )    -    ";
            }
            lbFax.Text = processed_data;

            lbEmail.Text = mContact.Email;
            if (mContact.ContactCompanyId.HasValue)
            {
                iCompanyID = mContact.ContactCompanyId.Value;
            }
            if (mContact.ContactBranchId.HasValue)
            {
                iContactBranchID = mContact.ContactBranchId.Value;
            }
        }
        catch (Exception ex)
        {
        }

        try
        {
            ContactBranches             bllCB = new ContactBranches();
            LPWeb.Model.ContactBranches mCB   = new LPWeb.Model.ContactBranches();
            mCB           = bllCB.GetModel(iContactBranchID);
            lbBranch.Text = mCB.Name;

            if (mCB.Phone != null)
            {
                raw_data = mCB.Phone.Trim();

                raw_data = System.Text.RegularExpressions.Regex.Replace(raw_data, @"[-() ]", String.Empty);
                if (raw_data.Length > 10)
                {
                    raw_data = raw_data.Substring(0, 10);
                }

                if (raw_data.Length == 10)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 4);
                }
                else if (raw_data.Length == 9)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 3);
                }
                else if (raw_data.Length == 8)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 2);
                }
                else if (raw_data.Length == 7)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 1);
                }
                else if (raw_data.Length == 6)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-";
                }
                else if (raw_data.Length == 5)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 2) + " -";
                }
                else if (raw_data.Length == 4)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 1) + "  -";
                }
                else if (raw_data.Length == 3)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + "   -";
                }
                else if (raw_data.Length == 2)
                {
                    processed_data = "(" + raw_data.Substring(0, 2) + " ) " + "   -";
                }
                else if (raw_data.Length == 1)
                {
                    processed_data = "(" + raw_data.Substring(0, 1) + "  ) " + "   -";
                }
                else
                {
                    processed_data = "(   )    -    ";
                }
            }
            else
            {
                processed_data = "(   )    -    ";
            }
            lbPhone.Text = processed_data;

            if (mCB.Fax != null)
            {
                raw_data = mCB.Fax.Trim();

                raw_data = System.Text.RegularExpressions.Regex.Replace(raw_data, @"[-() ]", String.Empty);
                if (raw_data.Length > 10)
                {
                    raw_data = raw_data.Substring(0, 10);
                }

                if (raw_data.Length == 10)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 4);
                }
                else if (raw_data.Length == 9)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 3);
                }
                else if (raw_data.Length == 8)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 2);
                }
                else if (raw_data.Length == 7)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-" + raw_data.Substring(6, 1);
                }
                else if (raw_data.Length == 6)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 3) + "-";
                }
                else if (raw_data.Length == 5)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 2) + " -";
                }
                else if (raw_data.Length == 4)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + raw_data.Substring(3, 1) + "  -";
                }
                else if (raw_data.Length == 3)
                {
                    processed_data = "(" + raw_data.Substring(0, 3) + ") " + "   -";
                }
                else if (raw_data.Length == 2)
                {
                    processed_data = "(" + raw_data.Substring(0, 2) + " ) " + "   -";
                }
                else if (raw_data.Length == 1)
                {
                    processed_data = "(" + raw_data.Substring(0, 1) + "  ) " + "   -";
                }
                else
                {
                    processed_data = "(   )    -    ";
                }
            }
            else
            {
                processed_data = "(   )    -    ";
            }
            lbFax1.Text    = processed_data;
            lbAddress.Text = mCB.Address;
            lbCity.Text    = mCB.City + " " + mCB.State + " " + mCB.Zip;
            if (mCB.ContactCompanyId.HasValue && iCompanyID == 0)
            {
                iCompanyID = mCB.ContactCompanyId.Value;
            }
        }
        catch (Exception ex)
        { }

        int iServiceTypeID = 0;

        try
        {
            ContactCompanies             bllCC = new ContactCompanies();
            LPWeb.Model.ContactCompanies mCC   = new LPWeb.Model.ContactCompanies();
            mCC = bllCC.GetModel(iCompanyID);
            //lbServiceType.Text = mCC.ServiceTypes;
            lbCompany.Text = mCC.Name;
            iServiceTypeID = mCC.ServiceTypeId;
        }
        catch
        { }


        try
        {
            ServiceTypes             blST = new ServiceTypes();
            LPWeb.Model.ServiceTypes mST  = new LPWeb.Model.ServiceTypes();
            mST = blST.GetModel(iServiceTypeID);
            lbServiceType.Text = mST.Name;
        }
        catch
        { }

        #region Referral Amount/Referral Funded/Wind Ratio

        string sSql = "select dbo.lpfn_GetTotalReferral(" + this.iContactID + ", " + this.CurrUser.iUserID + ") as TotalReferral, "
                      + "dbo.lpfn_GetTotalReferralFunded(" + this.iContactID + ", " + this.CurrUser.iUserID + ") as TotalReferralFunded, "
                      + "dbo.lpfn_GetTotalReferral_FileIDs(" + this.iContactID + ", " + this.CurrUser.iUserID + ") as TotalReferralFileIDs, "
                      + "isnull(dbo.lpfn_GetTotalReferralFunded(" + this.iContactID + ", " + this.CurrUser.iUserID + "),0)/dbo.lpfn_GetTotalReferral(" + this.iContactID + ", " + this.CurrUser.iUserID + ") as WinRatio";
        DataTable ReferralAmountInfo = LPWeb.DAL.DbHelperSQL.ExecuteDataTable(sSql);
        if (ReferralAmountInfo.Rows.Count > 0)
        {
            if (ReferralAmountInfo.Rows[0]["TotalReferral"] == DBNull.Value)
            {
                this.aTotalReferral.InnerText = string.Empty;
                this.aTotalReferral.HRef      = string.Empty;
            }
            else
            {
                this.aTotalReferral.InnerText = Convert.ToDecimal(ReferralAmountInfo.Rows[0]["TotalReferral"]).ToString("c0");
                this.aTotalReferral.HRef      = "javascript:window.parent.SetTab('PartnerContactDetailReferralstab.aspx',3);";
            }

            if (ReferralAmountInfo.Rows[0]["TotalReferralFunded"] == DBNull.Value)
            {
                this.lbTotalReferralFunded.Text = string.Empty;
            }
            else
            {
                this.lbTotalReferralFunded.Text = Convert.ToDecimal(ReferralAmountInfo.Rows[0]["TotalReferralFunded"]).ToString("c0");
            }

            if (ReferralAmountInfo.Rows[0]["WinRatio"] == DBNull.Value)
            {
                this.lbWinRatio.Text = string.Empty;
            }
            else
            {
                this.lbWinRatio.Text = Convert.ToDecimal(ReferralAmountInfo.Rows[0]["WinRatio"]).ToString("p0");
            }
        }

        #endregion
    }
    private void InitControl()
    {
        #region 加载Primary Contact
        Contacts ContactsManager = new Contacts();

        ContactCompanies ContactCompaniesManager = new ContactCompanies();

        LPWeb.Model.ContactCompanies mContactCompanies = (LPWeb.Model.ContactCompanies)ContactCompaniesManager.GetModelbyName(sCompanyName);

        int iContactCompanyId = 0;

        if (mContactCompanies != null)
        {
            iContactCompanyId = (int)mContactCompanies.ContactCompanyId;
        }

        int iContactBranchID = 0;

        DataTable ContactsList = ContactsManager.GetEnableCompanyContactInfo(iContactCompanyId, iContactBranchID);

        if (ContactsList == null)
        {
            ContactsList = ContactsManager.GetEnableContactInfo();
        }

        DataRow NewContactsRow = ContactsList.NewRow();
        NewContactsRow["ContactId"] = DBNull.Value;
        NewContactsRow["Contact"]   = "—select—";
        ContactsList.Rows.InsertAt(NewContactsRow, 0);
        ContactsList.AcceptChanges();

        this.ddlContact.DataSource = ContactsList;
        this.ddlContact.DataBind();

        #endregion

        #region 加载Company
        //ContactCompanies ContactCompaniesManager = new ContactCompanies();
        DataSet ContactCompaniesList = ContactCompaniesManager.GetList("(Enabled='true')");
        //if (ContactCompaniesList != null && ContactCompaniesList.Tables[0].Rows.Count > 0)
        //{
        DataRow NewContactCompaniesRow = ContactCompaniesList.Tables[0].NewRow();
        NewContactCompaniesRow["ContactCompanyId"] = DBNull.Value;
        NewContactCompaniesRow["Name"]             = "All Companies";
        ContactCompaniesList.Tables[0].Rows.InsertAt(NewContactCompaniesRow, 0);
        ContactCompaniesList.Tables[0].AcceptChanges();

        this.ddlCompany.DataSource = ContactCompaniesList.Tables[0];
        this.ddlCompany.DataBind();

        if (this.Request.QueryString["CompanyName"] != null)
        {
            sCompanyName = this.Request.QueryString["CompanyName"].ToString();
            this.ddlCompany.SelectedItem.Text = sCompanyName;
            string sSelCompanyID = "";
            if (ContactCompaniesList != null && ContactCompaniesList.Tables[0].Rows.Count > 0)
            {
                sSelCompanyID = ContactCompaniesList.Tables[0].Select("Name='" + sCompanyName + "'")[0]["ContactCompanyId"].ToString();
            }
            this.ddlCompany.SelectedValue = sSelCompanyID;
        }
        //}

        #endregion

        #region 加载States
        LPWeb.Layouts.LPWeb.Common.USStates.Init(this.ddlStates);
        #endregion

        #region 加载Company列表

        this.BranchSqlDataSource.ConnectionString = LPWeb.DAL.DbHelperSQL.connectionString;

        string sWhere = " and ContactBranchId=" + sContactBranchID;



        int iRowCount = LPWeb.DAL.DbHelperSQL.Count(this.BranchSqlDataSource.SelectParameters["DbTable"].DefaultValue, sWhere);

        // empty data text
        if (iRowCount == 0)
        {
            this.gridContactList.EmptyDataText = "There is no branch contact.";
        }
        else
        {
            this.gridContactList.EmptyDataText = "There is no partner branch.";
        }

        this.AspNetPager1.RecordCount = iRowCount;

        this.BranchSqlDataSource.SelectParameters["Where"].DefaultValue = sWhere;
        this.gridContactList.DataBind();

        #endregion
    }