Beispiel #1
0
        private void DoSearchRanking(string uploadleadid)
        {
            UploadLeadData uploadLead = UploadLeadBiz.SearchUploadLeadData(uploadleadid);

            hidUploadLeadId.Value = uploadLead.slm_UploadLeadId.ToString();
            hidLeadCount.Value    = uploadLead.slm_LeadCount.ToString();

            txtFileName.Text = uploadLead.slm_FileName.ToString();

            hidFileName.Value         = uploadLead.slm_FileName.ToString();
            cmbCampaign.SelectedValue = uploadLead.slm_CampaignCode;
        }
Beispiel #2
0
        protected void btnSaveAll_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateData())
                {
                    UploadLeadData data = new UploadLeadData();

                    data.slm_UploadLeadId = AppUtil.SafeInt(hidUploadLeadId.Value);
                    data.slm_LeadCount    = AppUtil.SafeInt(hidLeadCount.Value);
                    data.slm_Status       = "Submit";
                    //data.FileName = txtFileName.Text;
                    data.slm_FileName     = hidFileName.Value;
                    data.slm_CampaignCode = cmbCampaign.SelectedItem.Value;


                    if (hidUploadLeadId.Value == "")
                    {
                        UploadLeadBiz.AddUploadLead(data, (List <UploadLeadDetailData>)ViewState["Result"], HttpContext.Current.User.Identity.Name);
                    }
                    else
                    {
                        UploadLeadBiz.EditUploadLead(data, (List <UploadLeadDetailData>)ViewState["Result"], HttpContext.Current.User.Identity.Name);
                    }

                    AppUtil.ClientAlertAndRedirect(Page, "บันทึกข้อมูล UploadLead สำเร็จ", "SLM_SCR_101.aspx");
                }
                else
                {
                    AppUtil.ClientAlert(Page, "กรุณาระบุข้อมูลให้ครบถ้วน");
                }
            }
            catch (Exception ex)
            {
                string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                _log.Debug(message);
                AppUtil.ClientAlert(Page, message);
            }
        }
Beispiel #3
0
        private bool ReadExcel(string fileName, out List <UploadLeadData> dataList, out List <UploadLeadDataError> errorList)
        {
            IExcelDataReader excelReader = null;

            try
            {
                dataList  = new List <UploadLeadData>();
                errorList = new List <UploadLeadDataError>();

                string ext = System.IO.Path.GetExtension(fileName);
                excelReader = ext == ".xls" ? ExcelReaderFactory.CreateBinaryReader(fuLead.FileContent) : ExcelReaderFactory.CreateOpenXmlReader(fuLead.FileContent);
                excelReader.IsFirstRowAsColumnNames = true;

                int           rowNum = 0;
                int           maxRow = SLMConstant.UploadLead.UploadLeadMaxRow;
                StringBuilder sb     = new StringBuilder();
                //Regex regxSpecialChr = new Regex(@"[`]"); //@"[~`!@#$%^&*()+=|\\{}':;.,<>/?[\]""_-]"
                Regex regxEng = new Regex(@"[a-zA-Z]");         //@"([\-ก-๙0-9()., ]+)"

                UploadLeadBiz biz          = new UploadLeadBiz();
                var           cardTypeList = biz.GetCardTypeList();
                bool          isHeader     = true;
                while (excelReader.Read())
                {
                    if (isHeader)
                    {
                        isHeader = false;
                        continue;
                    }

                    //errText = "";
                    sb.Clear();
                    rowNum += 1;
                    if (rowNum > maxRow)
                    {
                        ErrorMessage = string.Format("Excel file มีข้อมูลเกิน {0} rows", maxRow);
                        return(false);
                    }

                    string nameThai        = excelReader.GetString((int)ExcelColumnName.Firstname);
                    string lastnameThai    = excelReader.GetString((int)ExcelColumnName.Lastname);
                    string cardtypeDesc    = excelReader.GetString((int)ExcelColumnName.CardTypeDesc);
                    string citizenId       = excelReader.GetString((int)ExcelColumnName.CitizenId);
                    string ownerEmpCode    = excelReader.GetString((int)ExcelColumnName.OwnerEmpCode);
                    string delegateEmpCode = excelReader.GetString((int)ExcelColumnName.DelegateEmpCode);
                    string telNo1          = excelReader.GetString((int)ExcelColumnName.TelNo1);
                    string telNo2          = excelReader.GetString((int)ExcelColumnName.TelNo2);
                    string detail          = excelReader.GetString((int)ExcelColumnName.Detail);

                    nameThai        = string.IsNullOrWhiteSpace(nameThai) ? "" : nameThai.Trim();
                    lastnameThai    = string.IsNullOrWhiteSpace(lastnameThai) ? "" : lastnameThai.Trim();
                    cardtypeDesc    = string.IsNullOrWhiteSpace(cardtypeDesc) ? "" : cardtypeDesc.Trim();
                    citizenId       = string.IsNullOrWhiteSpace(citizenId) ? "" : citizenId.Trim();
                    ownerEmpCode    = string.IsNullOrWhiteSpace(ownerEmpCode) ? "" : ownerEmpCode.Trim();
                    delegateEmpCode = string.IsNullOrWhiteSpace(delegateEmpCode) ? "" : delegateEmpCode.Trim();
                    telNo1          = string.IsNullOrWhiteSpace(telNo1) ? "" : telNo1.Trim();
                    telNo2          = string.IsNullOrWhiteSpace(telNo2) ? "" : telNo2.Trim();
                    detail          = string.IsNullOrWhiteSpace(detail) ? "" : detail.Trim();

                    if (string.IsNullOrWhiteSpace(nameThai) && string.IsNullOrWhiteSpace(lastnameThai) && string.IsNullOrWhiteSpace(cardtypeDesc) &&
                        string.IsNullOrWhiteSpace(citizenId) && string.IsNullOrWhiteSpace(ownerEmpCode) && string.IsNullOrWhiteSpace(delegateEmpCode) &&
                        string.IsNullOrWhiteSpace(telNo1) && string.IsNullOrWhiteSpace(telNo2) && string.IsNullOrWhiteSpace(detail))
                    {
                        //row ว่าง, skip ไป row ถัดไป
                        continue;
                    }

                    //ชื่อลูกค้า
                    if (string.IsNullOrWhiteSpace(nameThai))
                    {
                        sb.Append("Column A : กรุณาระบุชื่อลูกค้า<br />");
                    }
                    else
                    {
                        if (regxEng.IsMatch(nameThai))
                        {
                            sb.Append("Column A : กรุณาระบุชื่อลูกค้าเป็นภาษาไทย<br />");
                        }
                        else if (nameThai.Trim().Length > SLMConstant.UploadLead.FieldFirstNameSize)
                        {
                            sb.AppendFormat("Column A : ชื่อลูกค้ายาวเกิน {0} ตัวอักษร<br />", SLMConstant.UploadLead.FieldFirstNameSize.ToString());
                        }
                    }

                    //นามสกุลลูกค้า
                    if (!string.IsNullOrWhiteSpace(lastnameThai))
                    {
                        if (regxEng.IsMatch(lastnameThai))
                        {
                            sb.Append("Column B : กรุณาระบุนามสกุลลูกค้าเป็นภาษาไทย<br />");
                        }
                        else if (lastnameThai.Trim().Length > SLMConstant.UploadLead.FieldLastNameSize)
                        {
                            sb.AppendFormat("Column B : นามสกุลลูกค้ายาวเกิน {0} ตัวอักษร<br />", SLMConstant.UploadLead.FieldLastNameSize.ToString());
                        }
                    }

                    //ประเภทลูกค้า
                    if (!string.IsNullOrWhiteSpace(cardtypeDesc) && !cardTypeList.Any(p => p.TextField == cardtypeDesc))
                    {
                        sb.Append("Column C : ประเภทลูกค้าไม่ถูกต้อง<br />");
                    }

                    //เลขที่บัตร
                    if (!string.IsNullOrWhiteSpace(citizenId))
                    {
                        var cardtype_id = cardTypeList.Where(p => p.TextField == cardtypeDesc).Select(p => p.ValueField).FirstOrDefault();

                        if (cardtype_id == AppConstant.CardType.Person)
                        {
                            if (!AppUtil.VerifyCitizenId(citizenId))
                            {
                                sb.Append("Column D : เลขบัตรประชาชนไม่ถูกต้อง<br />");
                            }
                        }
                        else
                        {
                            if (citizenId.Trim().Length > SLMConstant.UploadLead.FieldCardIdSize)
                            {
                                sb.AppendFormat("Column D : เลขนิติบุคคล/บุคคลต่างชาติ ยาวเกิน {0} ตัวอักษร<br />", SLMConstant.UploadLead.FieldCardIdSize.ToString());
                            }
                        }
                    }

                    //Validate ประเภทลูกค้า, เลขที่บัตร
                    if (!string.IsNullOrWhiteSpace(cardtypeDesc) && string.IsNullOrWhiteSpace(citizenId))
                    {
                        sb.Append("Column D : กรุณระบุบัตรประชาชน/นิติบุคคล<br />");
                    }
                    else if (string.IsNullOrWhiteSpace(cardtypeDesc) && !string.IsNullOrWhiteSpace(citizenId))
                    {
                        sb.Append("Column C : กรุณาระบุประเภทลูกค้า<br />");
                    }

                    //OwnerLead
                    if (string.IsNullOrWhiteSpace(ownerEmpCode))
                    {
                        sb.Append("Column E : กรุณระบุ Owner Lead ID<br />");
                    }

                    //DelegateLead No validate

                    //TelNo1
                    if (string.IsNullOrWhiteSpace(telNo1))
                    {
                        sb.Append("Column G : กรุณาระบุเบอร์โทร 1<br />");
                    }
                    else
                    {
                        //Validate TelNo1 with CardTypeDesc
                        string cardTypeId = cardTypeList.Where(p => p.TextField == cardtypeDesc).Select(p => p.ValueField).FirstOrDefault();
                        cardTypeId = string.IsNullOrEmpty(cardTypeId) ? "" : cardTypeId;

                        if (!AppUtil.ValidateTelNo1(cardTypeId, telNo1))
                        {
                            sb.Append("Column G : เบอร์โทร 1 ไม่ถูกต้อง<br />");
                        }
                    }

                    //TelNo2
                    if (!string.IsNullOrWhiteSpace(telNo2) && !AppUtil.ValidateTelNo2(telNo2))
                    {
                        sb.Append("Column H : เบอร์โทร 2 ไม่ถูกต้อง<br />");
                    }

                    //Detail
                    if (!string.IsNullOrWhiteSpace(detail))
                    {
                        if (detail.Length > SLMConstant.UploadLead.FieldDetailSize)
                        {
                            sb.AppendFormat("Column I : รายละเอียดยาวเกิน {0} ตัวอักษร<br />", SLMConstant.UploadLead.FieldDetailSize.ToString());
                        }
                        else
                        {
                            var ret = detail.ToCharArray().Any(c => (c >= 128 && c <= 3584));
                            if (ret)
                            {
                                sb.Append("Column I : ข้อมูลรายละเอียดมีอักขระพิเศษที่ไม่อนุญาตให้ใช้งาน<br />");
                            }
                        }
                    }

                    if (sb.Length > 0)
                    {
                        UploadLeadDataError err = new UploadLeadDataError
                        {
                            Row         = (rowNum + 1).ToString(),
                            ErrorDetail = sb.ToString()
                        };
                        errorList.Add(err);
                    }
                    else
                    {
                        UploadLeadData data = new UploadLeadData
                        {
                            Firstname       = nameThai,
                            Lastname        = lastnameThai,
                            CardTypeDesc    = cardtypeDesc,
                            CitizenId       = citizenId,
                            OwnerEmpCode    = ownerEmpCode,
                            DelegateEmpCode = delegateEmpCode,
                            TelNo1          = telNo1,
                            TelNo2          = telNo2,
                            Detail          = detail,
                            StatusDesc      = "-"
                        };
                        dataList.Add(data);
                    }
                }

                return(true);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (excelReader != null)
                {
                    excelReader.Close();
                }
            }
        }
        public void EditUploadLead(UploadLeadData UploadLead, List <UploadLeadDetailData> UploadLeadDetailData, string username)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    kkslm_tr_upload_lead rk = slmdb.kkslm_tr_upload_lead.Where(r => r.slm_UploadLeadId == UploadLead.slm_UploadLeadId).FirstOrDefault();


                    rk.slm_LeadCount = UploadLead.slm_LeadCount;
                    //rk.Status = UploadLead.Status;
                    //rk.AssignedDate = UploadLead.AssignedDate;
                    rk.slm_CampaignCode = UploadLead.slm_CampaignCode;

                    rk.slm_UpdatedBy   = username;
                    rk.slm_UpdatedDate = DateTime.Now;



                    //slmdb.UploadLead.AddObject(rk);
                    slmdb.SaveChanges();


                    //delete old UploadLead_Campaign
                    List <kkslm_tr_upload_lead_detail> oldUploadLeadDetail = slmdb.kkslm_tr_upload_lead_detail.Where(r => r.slm_UploadLeadId == UploadLead.slm_UploadLeadId).ToList();

                    if (oldUploadLeadDetail != null)
                    {
                        foreach (kkslm_tr_upload_lead_detail orc in oldUploadLeadDetail)
                        {
                            slmdb.kkslm_tr_upload_lead_detail.DeleteObject(orc);
                            slmdb.SaveChanges();
                        }
                    }



                    //add UploadLeadcampaigns
                    if (UploadLeadDetailData != null)
                    {
                        foreach (UploadLeadDetailData rcd in UploadLeadDetailData)
                        {
                            //if (slmdb.UploadLeadDetail.Where(r => r.CampaignCode == rcd.CampaignCode && r.CampaignCode == rcd.CampaignName).Count() == 0)
                            //{
                            kkslm_tr_upload_lead_detail rc = new kkslm_tr_upload_lead_detail();

                            rc.slm_UploadLeadId        = rcd.slm_UploadLeadId;
                            rc.slm_ContractBranchName  = rcd.slm_ContractBranchName;
                            rc.slm_OwnerLead           = rcd.slm_OwnerLead;
                            rc.slm_ThaiFirstName       = rcd.slm_ThaiFirstName;
                            rc.slm_ThaiLastName        = rcd.slm_ThaiLastName;
                            rc.slm_CardIdType          = rcd.slm_CardIdType;
                            rc.slm_CardId              = rcd.slm_CardId;
                            rc.slm_CustTelephoneMobile = rcd.slm_CustTelephoneMobile;
                            rc.slm_CustTelephoneHome   = rcd.slm_CustTelephoneHome;
                            rc.slm_CustTelephoneOther  = rcd.slm_CustTelephoneOther;
                            rc.slm_BrandName           = rcd.slm_BrandName;
                            rc.slm_ModelName           = rcd.slm_ModelName;
                            rc.slm_ModelYear           = rcd.slm_ModelYear;
                            rc.slm_HpBscodeXsell       = rcd.slm_HpBscodeXsell;
                            rc.slm_Remark              = rcd.slm_Remark;
                            rc.slm_TicketID            = rcd.slm_TicketID;

                            slmdb.kkslm_tr_upload_lead_detail.AddObject(rc);
                            slmdb.SaveChanges();
                            //}
                        }
                    }



                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void EditUploadLead(UploadLeadData UploadLead, List <UploadLeadDetailData> UploadLeadDetail, string username)
        {
            KKSlmTrUploadLeadModel search = new KKSlmTrUploadLeadModel();

            search.EditUploadLead(UploadLead, UploadLeadDetail, username);
        }
        public static int AddUploadLead(UploadLeadData UploadLead, List <UploadLeadDetailData> UploadLeadDetail, string username)
        {
            KKSlmTrUploadLeadModel search = new KKSlmTrUploadLeadModel();

            return(search.AddUploadLead(UploadLead, UploadLeadDetail, username));
        }