/// <summary> /// Event raise when user click save button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { try { Entities.Member member = new Entities.Member(); //memberId member.MemberId = staticmemberId; //validate member code string strMemberCode = ""; if (chBAutoID.Checked) { member.MemberCode = GetAutoMemberCode(cbbNationality.SelectedValue.ToString()); } else { strMemberCode = txtMemberCode.Text.Trim(); if (string.IsNullOrEmpty(strMemberCode)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM37"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { member.MemberCode = strMemberCode; } } //validate membername or company name not ether null if (string.IsNullOrEmpty(txtMemerName.Text.Trim()) && string.IsNullOrEmpty(txtCompanyName.Text.Trim())) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM628"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Error, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { member.MemberName = txtMemerName.Text.Trim(); member.CompanyName = txtCompanyName.Text.Trim(); } //validate birthdate DateTime birthdate = dtpBirthDate.Value; member.BirthDate = birthdate; if (chkNgaySinh.Checked == true) { member.birthDay = true; } else { member.birthDay = false; } //validate email string strEmail = txtCompanyEmail.Text.Trim(); string[] emails = strEmail.Split(';'); int lenght = emails.Length; string opSpace = ""; strEmail = ""; for (int i = 0; i < lenght; i++) { if (!string.IsNullOrEmpty(emails[i]) && !Common.Validation.ValidateEmail(emails[i].Trim())) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM311"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } strEmail += opSpace + emails[i]; opSpace = ";"; } member.CompanyEmail = strEmail; member.Email = strEmail; //phone number member.PhoneNumber = System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber.Text.Trim(), "( ( )*)", " "); //address if (!string.IsNullOrEmpty(txtAddress.Text.Trim())) { member.Address = txtAddress.Text.Trim(); } //validate nationality if (cbbNationality.Text == "") { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM373"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { member.Country.CountryId = cbbNationality.SelectedValue.ToString(); } //creator member.Creator.EmployeeId = Program.employee1.EmployeeId; try { member.Curator.EmployeeId = cbbCurator.SelectedValue.ToString(); } catch { member.Curator.EmployeeId = null; } try { if (cbBCategoryAction.SelectedValue.ToString() != "") { member.CategoryID.CategoryActionID = cbBCategoryAction.SelectedValue.ToString(); } else { member.CategoryID.CategoryActionID = ""; } } catch (Exception) { member.CategoryID.CategoryActionID = ""; } //chuc vu member.Regency = txtChucDanh.Text.Trim(); //total score string strTotalScore = txtTotalScore.Text.Trim(); if (!string.IsNullOrEmpty(strTotalScore)) { if (!Common.Validation.ValidateNumber(strTotalScore)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM98"), Common.clsLanguages.GetResource("CRM12"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Error, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { member.TotalScore = Int32.Parse(strTotalScore); } } //total CurrentScore string strCurrentScore = txtCurrentScore.Text.Trim(); if (!string.IsNullOrEmpty(strCurrentScore)) { if (!Common.Validation.ValidateNumber(strCurrentScore)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM98"), Common.clsLanguages.GetResource("CRM12"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Error, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { member.CurrentScore = Int32.Parse(strCurrentScore); } } //numberOfVissits string strNumberOfVissits = txtNumberOfVissits.Text.Trim(); if (!string.IsNullOrEmpty(strNumberOfVissits)) { if (!Common.Validation.ValidateNumber(strNumberOfVissits)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM98"), Common.clsLanguages.GetResource("CRM12"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Error, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { member.NumberOfVissits = Int32.Parse(strNumberOfVissits); } } //member type //List<string> lstMemberTypeName = new List<string>(); List <Entities.MemberType> lstMemberTypeName = new List <Entities.MemberType>(); int otherIndex = -1; for (int i = 0; i < lstMemberType.Items.Count; i++) { DataRowView dr = (DataRowView)lstMemberType.Items[i]; if (lstMemberType.GetItemChecked(i)) { Entities.MemberType mt = new Entities.MemberType(); mt.MemberTypeId = int.Parse(dr["MemberTypeId"].ToString()); mt.MemberTypeName = dr["MemberTypeName"].ToString(); mt.MemberTypeName2 = dr["MemberTypeName2"].ToString(); mt.MemberTypeName3 = dr["MemberTypeName3"].ToString(); //mt.MemberTypeId lstMemberTypeName.Add(mt); } if (dr["MemberTypeCode"].ToString().Equals("OT")) // other type { otherIndex = i; } } if (lstMemberTypeName.Count != 0) { member.List_MemberType = lstMemberTypeName; } else { if (otherIndex >= 0) { DataRowView dr = (DataRowView)lstMemberType.Items[otherIndex]; Entities.MemberType mt = new Entities.MemberType(); mt.MemberTypeId = int.Parse(dr["MemberTypeId"].ToString()); mt.MemberTypeName = dr["MemberTypeName"].ToString(); mt.MemberTypeName2 = dr["MemberTypeName2"].ToString(); mt.MemberTypeName3 = dr["MemberTypeName3"].ToString(); lstMemberTypeName.Add(mt); member.List_MemberType = lstMemberTypeName; } else { member.List_MemberType = null; } } //member.MemberType.MemberTypeId = Int32.Parse(memberType); //Lastest Date member.LastestDate = DateTime.Now; //Created date member.CreatedDate = DateTime.Now; //Updated date member.UpdatedDate = DateTime.Now; //islock int isLock = 0; if (chbIsLock.Checked) { isLock = 1; } member.IsLock = isLock; //LockDate member.LockDate = DateTime.Now; member.MobilePhone = txtMobilePhone.Text.Trim(); //validate website string url = txtWebsite.Text.Trim(); if (!string.IsNullOrEmpty(url) && !Common.Validation.ValidateWebsite(url)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRMErrorURLNotValid"), Common.clsLanguages.GetResource("CRM12"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Error, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } member.Website = url; member.TaxCode = txtTaxCode.Text.Trim(); member.Description = txtDescription.Text.Trim(); if (cbBCallName.SelectedValue != null) { member.CallName.CallNameID = (int)cbBCallName.SelectedValue; } DialogResult dialog = CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM227"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.YESNO); if (dialog == DialogResult.Yes) { //If is add if (blag) { if (memberBLL.CheckMemberCodeExist(strMemberCode)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM539"), Common.clsLanguages.GetResource("CRM12"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Error, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); this.txtMemberCode.Clear(); this.txtMemberCode.Focus(); return; } memberBLL.Add(member); if (staticmemberId != null) { staticmemberId = member.MemberId; } } //If is edit else { memberBLL.Edit(member); } this.Close(); } } catch (Exception ex) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM292"), Common.clsLanguages.GetResource("CRM12"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } }
private void btnSave_Click(object sender, EventArgs e) { //rTxtLog.Text = string.Empty; Cursor.Current = Cursors.WaitCursor; string connString = string.Empty; string status = "Status: \t"; string serror = "Error: \t"; string swaring = "Waring: \t"; BusinessLayer.BLLCRM.MemberBLL memberBLL = new BusinessLayer.BLLCRM.MemberBLL(); if (validation()) { rTxtLog.AppendText(status + "Opening Excel File...\n"); rTxtLog.AppendText(status + "File is opened, waiting for welcome message...\n"); DataTable dtExcel = VVPosM1.BusinessLayer.BLLCRM.ImportMember.ReadExcelFile(filepath); Boolean bFlagUpdate = false; int iRowError = 0; int iRowSuccess = 0; int iTotalRecord = 0; //Set Column Label string strMemberCode = txtMemberCode.Text.Trim(); string[] strFullName = txtMemerName.Text.Split(';'); string strChucDanh = txtChucDanh.Text.Trim(); string strCompanyName = txtCompanyName.Text.Trim(); string strAddress = txtAddress.Text.Trim(); string[] strEmails = txtCompanyEmail.Text.Split(';'); string strPhone = txtPhoneNumber.Text; string strmPhone = txtMobilePhone.Text; string strWebsite = txtWebsite.Text; string strTaxCode = txtTaxCode.Text; string[] strNotes = txtDescription.Text.Split(';'); string strBirthDay = txtBirthday.Text; int iTemps = -1; string strTemp = string.Empty; int iBegin = (int.Parse(txtFirstLine.Text) - 1) > 0 ? int.Parse(txtFirstLine.Text) - 1 : 0; for (int iCount = iBegin; iCount < int.Parse(txtEndLine.Text); iCount++) { if (iCount >= dtExcel.Rows.Count) { break; } DataRow dr = dtExcel.Rows[iCount]; Entities.Member member = new Entities.Member(); int iLineError = 0; //Count total record iTotalRecord++; rTxtLog.AppendText("Reading line: " + iTotalRecord.ToString() + "\n"); //Get Col MemberCode if (chBAutoID.Checked == true) { try { member.MemberCode = BusinessLayer.BLLCRM.ImportMember.GetAutoMemberCode(); } catch (Exception) { rTxtLog.AppendText(swaring + "Customer code is null.\n"); iLineError++; } } else { iTemps = BusinessLayer.BLLCRM.ImportMember.returnCellName(strMemberCode); try { if (dr[iTemps].ToString() != string.Empty) { member.MemberCode = dr[iTemps].ToString(); //Check exists if (chBOveride.Checked == true) { if (memberBLL.CheckMemberCodeExist(member.MemberCode)) { if (memberBLL.getMemberId(member.MemberCode) != string.Empty) { member.MemberId = memberBLL.getMemberId(member.MemberCode); bFlagUpdate = true; } else { rTxtLog.AppendText(serror + "Customer ID is not getted. SQL command error.\n"); iLineError++; } } } } else { rTxtLog.AppendText(serror + "Customer code is null.\n"); iLineError++; } } catch (Exception) { rTxtLog.AppendText(serror + "Customer code is null.\n"); iLineError++; } } //Get Fullname strTemp = string.Empty; if (strFullName.Length > 0) { foreach (var item in strFullName) { if (item != "") { iTemps = BusinessLayer.BLLCRM.ImportMember.returnCellName(item.Trim()); try { strTemp += dr[iTemps].ToString() + " "; } catch (Exception) { rTxtLog.AppendText(serror + "Column " + item + ": data not found.\n"); //iLineError++; } } } } member.MemberName = strTemp.Trim(); //Get Chuc Danh if (strChucDanh != string.Empty) { iTemps = BusinessLayer.BLLCRM.ImportMember.returnCellName(strChucDanh); try { member.Regency = dr[iTemps].ToString(); } catch (Exception) { member.Regency = string.Empty; rTxtLog.AppendText(serror + "Column " + strChucDanh + ": data not found.\n"); } } else { member.Regency = string.Empty; } //Get Company name if (strCompanyName != string.Empty) { iTemps = BusinessLayer.BLLCRM.ImportMember.returnCellName(strCompanyName); try { member.CompanyName = dr[iTemps].ToString(); } catch (Exception) { member.CompanyName = string.Empty; rTxtLog.AppendText(serror + "Column " + strCompanyName + ": data not found.\n"); } } else { member.CompanyName = string.Empty; } //Check Member name or Company name is not null if (member.MemberName == string.Empty && member.CompanyName == string.Empty) { iLineError++; rTxtLog.AppendText(serror + "Customer name or company name are not null.\n"); } else { if (member.MemberName == string.Empty) { rTxtLog.AppendText(swaring + "Customer name is null\n"); } if (member.CompanyName == string.Empty) { rTxtLog.AppendText(swaring + "Company name is null\n"); } } //Get Address if (strAddress != string.Empty) { iTemps = BusinessLayer.BLLCRM.ImportMember.returnCellName(strAddress); try { member.Address = dr[iTemps].ToString(); } catch (Exception) { member.Address = string.Empty; rTxtLog.AppendText(serror + "Column " + strAddress + ": data not found.\n"); } } else { member.Address = string.Empty; } //Get Email strTemp = string.Empty; int iTemp = 1; if (strEmails.Length > 0) { foreach (var item in strEmails) { if (item != "") { try { iTemps = BusinessLayer.BLLCRM.ImportMember.returnCellName(item.Trim()); if (Common.Validation.ValidateEmail(dr[iTemps].ToString())) { strTemp += dr[iTemps].ToString() + ";"; } else { rTxtLog.AppendText(swaring + "Email " + iTemp + ": incorrect email format.\n"); iTemp++; //iLineError++; } } catch (Exception) { rTxtLog.AppendText(swaring + "Column " + item + ": data not found.\n"); //iLineError++; } } } } char[] charsToTrim = { ',', '.', ' ', ';' }; strTemp = strTemp.Trim(); strTemp = strTemp.TrimEnd(charsToTrim); member.CompanyEmail = strTemp; member.Email = strTemp; //Get Phone number if (strPhone != string.Empty) { iTemps = ImportMember.returnCellName(strPhone); try { member.PhoneNumber = dr[iTemps].ToString(); } catch (Exception) { member.PhoneNumber = string.Empty; rTxtLog.AppendText(swaring + "Column " + strPhone + ": data not found.\n"); } } else { member.PhoneNumber = string.Empty; } //Get mobile phone if (strmPhone != string.Empty) { iTemps = ImportMember.returnCellName(strmPhone); try { member.MobilePhone = dr[iTemps].ToString(); } catch (Exception) { member.MobilePhone = string.Empty; rTxtLog.AppendText(swaring + "Column " + strmPhone + ": data not found.\n"); } } else { member.MobilePhone = string.Empty; } //Get Tax code if (strTaxCode != string.Empty) { iTemps = ImportMember.returnCellName(strTaxCode); try { member.TaxCode = dr[iTemps].ToString(); } catch (Exception) { member.TaxCode = string.Empty; rTxtLog.AppendText(swaring + "Column " + strTaxCode + ": data not found.\n"); } } else { member.TaxCode = string.Empty; } //Get website if (strWebsite != string.Empty) { iTemps = ImportMember.returnCellName(strWebsite); try { if (Common.Validation.ValidateWebsite(dr[iTemps].ToString())) { member.Website = dr[iTemps].ToString(); } else { rTxtLog.AppendText(swaring + "Website incorrect format.\n"); } } catch (Exception) { member.Website = string.Empty; rTxtLog.AppendText(swaring + "Column " + strWebsite + ": data not found.\n"); } } else { member.Website = string.Empty; } strTemp = string.Empty; iTemp = 1; if (strNotes.Length > 0) { foreach (var item in strNotes) { iTemps = ImportMember.returnCellName(item.Trim()); try { strTemp += (dr[iTemps].ToString() + "'\r\n'"); } catch (Exception) { rTxtLog.AppendText(swaring + "Column " + item + ": data not found.\n"); } } } member.Description = strTemp; //Get birthday if (strBirthDay != string.Empty) { iTemps = ImportMember.returnCellName(strBirthDay); try { member.birthDay = true; member.BirthDate = DateTime.ParseExact(dr[iTemps].ToString(), cbbDatetimeFormat.SelectedItem.ToString(), System.Globalization.DateTimeFormatInfo.CurrentInfo, System.Globalization.DateTimeStyles.None); //Common.Utility.StringToDateTimeVer2(dr[iTemps].ToString()); } catch (Exception) { member.birthDay = false; //member.BirthDate = DateTime.Now; rTxtLog.AppendText(swaring + "Column " + strBirthDay + ": data not found.\n"); } } else { member.birthDay = false; member.BirthDate = DateTime.Now; } //creator member.Creator.EmployeeId = Program.employee1.EmployeeId; member.Curator.EmployeeId = cbbCreator.SelectedValue.ToString(); //Get Country ID OT member.Country.CountryId = countryID; //Member Type List <Entities.MemberType> lstMemberTypeName = new List <Entities.MemberType>(); MemberTypeBLL mt = new MemberTypeBLL(); DataTable dt = mt.GetLists(); Entities.MemberType mbt = new Entities.MemberType(); int iFlag = 0; foreach (DataRow drtemp in dt.Rows) { if (drtemp["MemberTypeCode"].ToString().Equals("OT")) { mbt.MemberTypeId = int.Parse(drtemp["MemberTypeId"].ToString()); mbt.MemberTypeName = drtemp["MemberTypeName"].ToString(); mbt.MemberTypeName2 = drtemp["MemberTypeName2"].ToString(); mbt.MemberTypeName3 = drtemp["MemberTypeName3"].ToString(); mbt.MemberTypeCode = drtemp["MemberTypeCode"].ToString(); iFlag = 1; break; } } if (iFlag == 0) { mbt.MemberTypeId = int.Parse(dt.Rows[0]["MemberTypeId"].ToString()); mbt.MemberTypeName = dt.Rows[0]["MemberTypeName"].ToString(); mbt.MemberTypeName2 = dt.Rows[0]["MemberTypeName2"].ToString(); mbt.MemberTypeName3 = dt.Rows[0]["MemberTypeName3"].ToString(); mbt.MemberTypeCode = dt.Rows[0]["MemberTypeCode"].ToString(); } lstMemberTypeName.Add(mbt); member.List_MemberType = lstMemberTypeName; //member.Email = string.Empty; member.TotalScore = 0; member.CurrentScore = 0; member.NumberOfVissits = 0; member.IsLock = 0; member.CallName.CallNameID = CallNameID; //Lastest Date member.LastestDate = DateTime.Now; //Created date member.CreatedDate = DateTime.Now; //Updated date member.UpdatedDate = DateTime.Now; if (chBOveride.Checked == true) { if (bFlagUpdate == true) { try { memberBLL.Edit(member); } catch (Exception) { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + " is not update.\n"); iLineError++; } } else { try { if (!memberBLL.CheckMemberCodeExist(member.MemberCode)) { memberBLL.Add(member); } else { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + ": member code is exists.\n"); iLineError++; } } catch (Exception) { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + " is not insert.\n"); iLineError++; } } } else { try { if (!memberBLL.CheckMemberCodeExist(member.MemberCode)) { memberBLL.Add(member); } else { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + ": member code is exists.\n"); iLineError++; } } catch (Exception) { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + " is not insert.\n"); iLineError++; } } if (iLineError == 0) { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + " is inserted database.\n"); iRowSuccess++; } else { rTxtLog.AppendText(status + "Row " + iTotalRecord.ToString() + " is error.\n"); iRowError++; } iLineError = 0; } rTxtLog.AppendText(status + "Closing Excel File...\n"); rTxtLog.AppendText(status + "File is closed\n"); rTxtLog.AppendText(iRowError + " error record. " + iRowSuccess + " success record.\n"); rTxtLog.AppendText("Total " + iTotalRecord.ToString() + " record.\n"); CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM629"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); } }