public SAPCust job_getCustomer(CCJOB job) { SAPCust sapcust = new SAPCust(); try { CCCUST c = null; List<CCCUST> q = findCCCust(string.Format(" where \"U_CustomerID\"='{0}' AND \"U_methodDescription\"='{1}'",job.CustomerID, job.PaymentID )); if(q.Count() == 0) { List<CCCUST> q2 = findCCCust(string.Format(" where \"U_CustomerID\"='{0}'", job.CustomerID)); foreach (CCCUST c1 in q2) c = c1; } else { foreach (CCCUST c1 in q) c = c1; } if(c == null) { string err = "No payment method found"; job.Result = err; job.LastRunDate = DateTime.Today; update(job); return null; } sapcust.cccust = c; string id = ""; string cardcode = getCardAcctByCustNum(c.CustNum, ref id); SecurityToken token = getToken(cardcode); sapcust.custObj = ebiz.GetCustomer(token, c.CustomerID, null); return sapcust; } catch (Exception ex) { errorLog("Failed to Create Customer Obj." + "\r\nJobID:" + job.jobID + "\r\n" + ex.Message); job.Result = "Failed on get payment method"; job.LastRunDate = DateTime.Today; update(job); } return null; }
private void CustImpFormHandler(SAPbouiCOM.Form form, SAPbouiCOM.ItemEvent pVal) { try { if (pVal.BeforeAction) { } else { switch (pVal.EventType) { case SAPbouiCOM.BoEventTypes.et_CLICK: break; case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED: { switch (pVal.ItemUID) { case btnClose: oCustImpForm.Close(); break; case btnImp: try { if (custObjForImport == null) { form.Items.Item(btnFind).Click(); } else { string cardcode = getComboBoxVal(form, cbCustomerID); if (cardcode == "") { showMessage("Please select a customer."); } else { if (custObjForImport == null) { form.Items.Item(btnFind).Click(); } else { if (SBO_Application.MessageBox("Import payment method(s) to " + cardcode + "?", 1, "Yes", "No") == 1) { int i = 0; foreach (PaymentMethod pm in custObjForImport.PaymentMethods) { if (!isPaymentMethodExists(cardcode, pm.CardNumber, pm.CardExpiration)) { CCCUST cccust = new CCCUST(); cccust.CustomerID = cardcode; cccust.active = 'Y'; cccust.email = custObjForImport.BillingAddress.Email; cccust.firstName = custObjForImport.BillingAddress.FirstName; cccust.lastName = custObjForImport.BillingAddress.LastName; cccust.street = custObjForImport.BillingAddress.Street; cccust.city = custObjForImport.BillingAddress.City; cccust.state = custObjForImport.BillingAddress.State; cccust.zip = custObjForImport.BillingAddress.Zip; cccust.expDate = pm.CardExpiration; cccust.cardCode = pm.CardCode; cccust.routingNumber = pm.Routing; cccust.checkingAccount = pm.Account; cccust.GroupName = getGroupName(cardcode); cccust.CustNum = custObjForImport.CustNum; cccust.MethodID = pm.MethodID; try { if (pm.MethodName != null && pm.MethodName != "") { if (pm.MethodName.IndexOf(" ") > 0) { string name = pm.MethodName; string[] s = name.Split(' '); cccust.firstName = s[0]; cccust.lastName = s[s.Length - 1]; } } } catch (Exception) { } int id = getNextTableID("@CCCUST"); string desc = cccust.firstName + " " + cccust.lastName; if (pm.MethodName != null && pm.MethodName != "") { desc = pm.MethodName; } if (pm.MethodType == "check") { cccust.methodDescription = id.ToString() + "_" + pm.Routing + " " + pm.Account + "(" + desc + ")"; cccust.checkingAccount = pm.Account; cccust.routingNumber = pm.Routing; } else { cccust.cardNum = pm.CardNumber; cccust.methodDescription = id.ToString() + "_" + pm.CardNumber + " " + pm.CardExpiration + "(" + desc + ")"; cccust.checkingAccount = pm.Account; cccust.cardType = pm.CardType; } string cardid = ""; cccust.CardName = getCardName(cccust.GroupName, cccust.cardType, "", ref cardid); cccust.CCAccountID = cardid; cccust.methodName = pm.MethodName; insert(cccust); SBO_Application.SetStatusBarMessage(string.Format("Import payment method {0} to {1}.", cccust.cardNum, cardcode), SAPbouiCOM.BoMessageTime.bmt_Medium, false); } i++; } } } } } }catch (Exception ex) { SBO_Application.SetStatusBarMessage(string.Format("Import payment method error: {0}.", ex.Message), SAPbouiCOM.BoMessageTime.bmt_Medium, true); } break; case btnFind: try { string custNum = getFormEditVal(form, editCustNum); if (custNum == "") { showMessage("Please enter customer number."); } else { SBO_Application.SetStatusBarMessage("Finding customer please wait...", SAPbouiCOM.BoMessageTime.bmt_Medium, false); ueSecurityToken token = getToken(""); custObjForImport = ebiz.getCustomer(token, custNum); SAPbouiCOM.ComboBox oCB = (SAPbouiCOM.ComboBox)form.Items.Item(cbPaymentMethod).Specific; try { while (oCB.ValidValues.Count > 0) { oCB.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index); } } catch (Exception) { } ComboAddItem(oCB, ""); foreach (PaymentMethod pm in custObjForImport.PaymentMethods) { string s = ""; string name = ""; name = custObjForImport.BillingAddress.FirstName + " " + custObjForImport.BillingAddress.LastName; if (pm.MethodName != null && pm.MethodName != "") { if (pm.MethodName.IndexOf(" ") > 0) { name = pm.MethodName; } } if (pm.MethodType == "check") { s = pm.Routing + " " + pm.Account + "(" + name + ")"; } else { s = pm.CardNumber + " " + pm.CardExpiration + "(" + name + ")"; } ComboAddItem(oCB, s); } oCB.Select(""); SBO_Application.SetStatusBarMessage(string.Format("{0} payment method(s) ready to import.", oCB.ValidValues.Count - 1), SAPbouiCOM.BoMessageTime.bmt_Medium, false); // form.Items.Item(btnImp).Click(); } }catch (Exception ex) { custObjForImport = null; SAPbouiCOM.ComboBox oCB = (SAPbouiCOM.ComboBox)form.Items.Item(cbPaymentMethod).Specific; try { while (oCB.ValidValues.Count > 0) { oCB.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index); } } catch (Exception) { } ComboAddItem(oCB, ""); oCB.Select(""); SBO_Application.SetStatusBarMessage(string.Format("Find customer error: {0}.", ex.Message), SAPbouiCOM.BoMessageTime.bmt_Medium, true); errorLog(ex); } break; } } break; } } } catch (Exception ex) { errorLog(ex); } }
private void ExpImportThread() { try { oCustImpForm.Items.Item(btnExpFImp).Enabled = false; oCustImpForm.Items.Item(btnFImp).Enabled = false; oCustImpForm.Items.Item(btnFind).Enabled = false; oCustImpForm.Items.Item(btnImp).Enabled = false; List <ImportData> dataList = new List <ImportData>(); string fn = getFormItemVal(oCustImpForm, editExpFileName); var fileLines = File.ReadAllLines(fn).Skip(1).ToList(); foreach (string line in fileLines) { string[] i = line.Split('\t'); ImportData data = new ImportData(); try { data.CustomerID = i[0]; data.CustNum = i[1]; /* * if(data.CustomerID != "") * { * data.CustomerID = "A1"; * data.CustNum = "8545319"; * } */ } catch (Exception) { } if (data.CustomerID != null && data.CustomerID != "") { dataList.Add(data); } } foreach (ImportData imp in dataList) { SAPCust sapcust = new SAPCust(); try { sapcust.cccust = new CCCUST(); sapcust.cccust.CustomerID = imp.CustomerID; sapcust.cccust.GroupName = getGroupName(imp.CustomerID); string code = ""; sapcust.cccust.CardName = getCardName(sapcust.cccust.GroupName, sapcust.cccust.cardType, "", ref code); sapcust.cccust.CCAccountID = code; sapcust.cccust.CustNum = imp.CustNum; SecurityToken token = getToken(sapcust.cccust.CCAccountID); sapcust.custObj = ebiz.GetCustomer(token, imp.CustomerID, ""); sapcust.cccust.city = sapcust.custObj.BillingAddress.City; sapcust.cccust.email = sapcust.custObj.Email; sapcust.cccust.street = sapcust.custObj.BillingAddress.Address1; sapcust.cccust.state = sapcust.custObj.BillingAddress.State; sapcust.cccust.zip = sapcust.custObj.BillingAddress.ZipCode; sapcust.cccust.firstName = sapcust.custObj.BillingAddress.FirstName; sapcust.cccust.lastName = sapcust.custObj.BillingAddress.LastName; sapcust.cccust.MethodID = sapcust.custObj.PaymentMethodProfiles[0].MethodID; sapcust.cccust.methodName = sapcust.custObj.PaymentMethodProfiles[0].MethodName; try { if (imp.defaultCard != null && imp.defaultCard != "") { sapcust.cccust.@default = imp.defaultCard[0]; } } catch (Exception) { } CCCUST ccust = sapcust.cccust; int id = getNextTableID("@CCCUST"); string desc = sapcust.custObj.BillingAddress.FirstName + " " + sapcust.custObj.BillingAddress.LastName; if (sapcust.custObj.PaymentMethodProfiles[0].MethodName != "" && sapcust.custObj.PaymentMethodProfiles[0].MethodName != null) { desc = sapcust.custObj.PaymentMethodProfiles[0].MethodName; } if (sapcust.custObj.PaymentMethodProfiles[0].MethodType == "check") { sapcust.cccust.methodDescription = id.ToString() + "_" + sapcust.custObj.PaymentMethodProfiles[0].Routing + " " + sapcust.custObj.PaymentMethodProfiles[0].Account + "(" + desc + ")"; sapcust.cccust.checkingAccount = sapcust.custObj.PaymentMethodProfiles[0].Account; sapcust.cccust.routingNumber = sapcust.custObj.PaymentMethodProfiles[0].Routing; } else { sapcust.cccust.expDate = DateTime.Parse(sapcust.custObj.PaymentMethodProfiles[0].CardExpiration).ToString("MMyy"); sapcust.cccust.cardNum = sapcust.custObj.PaymentMethodProfiles[0].CardNumber; sapcust.cccust.methodDescription = id.ToString() + "_" + sapcust.custObj.PaymentMethodProfiles[0].CardNumber + " " + sapcust.custObj.PaymentMethodProfiles[0].CardExpiration + "(" + desc + ")"; sapcust.cccust.cardType = sapcust.custObj.PaymentMethodProfiles[0].CardType; sapcust.cccust.CardName = getCardName(sapcust.cccust.GroupName, sapcust.cccust.cardType, "", ref code); sapcust.cccust.CCAccountID = code; } insert(ccust); SetText("\r\n" + string.Format("Customer {0} card {1} added", sapcust.cccust.CustomerID, sapcust.cccust.cardNum)); } catch (Exception ex) { SetText("\r\n" + string.Format("Failed to add customer {0} card {1}. {2}", sapcust.cccust.CustomerID, sapcust.cccust.cardNum, ex.Message)); } } SetText("\r\nImport Completed."); } catch (Exception ex) { showMessage(ex.Message); } finally { try { oCustImpForm.Items.Item(btnExpFImp).Enabled = true; oCustImpForm.Items.Item(btnFind).Enabled = true; oCustImpForm.Items.Item(btnFImp).Enabled = true; oCustImpForm.Items.Item(btnFind).Enabled = true; oCustImpForm.Items.Item(btnImp).Enabled = true; } catch (Exception) { } } }
private void importThread() { try { oCustImpForm.Items.Item(btnFImp).Enabled = false; oCustImpForm.Items.Item(btnFind).Enabled = false; oCustImpForm.Items.Item(btnImp).Enabled = false; List <ImportData> dataList = new List <ImportData>(); string fn = getFormItemVal(oCustImpForm, editFileName); var fileLines = File.ReadAllLines(fn).Skip(1).ToList(); foreach (string line in fileLines) { string[] i = line.Split('\t'); ImportData data = new ImportData(); try { data.CustomerID = i[0]; data.CompanyName = i[1]; data.FirstName = i[2]; data.LastName = i[3]; data.Street = i[4]; data.Street2 = i[5]; data.Zip = i[6]; data.City = i[7]; data.State = i[8]; data.Phone = i[9]; data.Fax = i[10]; data.Email = i[11]; data.URL = i[12]; data.CardNumber = i[13]; data.CardExpiration = i[14]; data.MethodName = i[15]; if (i.Length >= 16) { data.defaultCard = i[16]; } } catch (Exception) { } if (data.CustomerID != null && data.CustomerID != "") { dataList.Add(data); } } foreach (ImportData imp in dataList) { SAPCust sapcust = new SAPCust(); sapcust.cccust = new CCCUST(); sapcust.cccust.city = imp.City; sapcust.cccust.email = imp.Email; sapcust.cccust.street = imp.Street; sapcust.cccust.state = imp.State; sapcust.cccust.zip = imp.Zip; sapcust.cccust.firstName = imp.FirstName; sapcust.cccust.lastName = imp.LastName; sapcust.cccust.CustomerID = imp.CustomerID; sapcust.cccust.GroupName = getGroupName(imp.CustomerID); sapcust.cccust.cardType = getCardType(imp.CardNumber); sapcust.cccust.methodName = imp.MethodName; try { if (imp.defaultCard != null && imp.defaultCard != "") { sapcust.cccust.@default = imp.defaultCard[0]; } } catch (Exception) { } string code = ""; sapcust.cccust.CardName = getCardName(sapcust.cccust.GroupName, sapcust.cccust.cardType, "", ref code); sapcust.cccust.CCAccountID = code; sapcust.cccust.cardNum = imp.CardNumber; sapcust.cccust.expDate = imp.CardExpiration; CCCUST cust = sapcust.cccust; sapcust.custObj = new Customer(); sapcust.custObj.BillingAddress = new Address(); sapcust.custObj.Email = cust.email; sapcust.custObj.BillingAddress.FirstName = cust.firstName; sapcust.custObj.BillingAddress.LastName = cust.lastName; sapcust.custObj.BillingAddress.State = cust.state; sapcust.custObj.BillingAddress.City = cust.city; sapcust.custObj.BillingAddress.ZipCode = cust.zip; sapcust.custObj.BillingAddress.Address1 = cust.street; sapcust.custObj.PaymentMethodProfiles = new PaymentMethodProfile[1]; sapcust.custObj.PaymentMethodProfiles[0] = new PaymentMethodProfile(); sapcust.custObj.PaymentMethodProfiles[0].CardNumber = cust.cardNum; sapcust.custObj.PaymentMethodProfiles[0].CardType = cust.cardType; sapcust.custObj.PaymentMethodProfiles[0].CardExpiration = cust.expDate; sapcust.custObj.PaymentMethodProfiles[0].CardCode = cust.cardCode; sapcust.custObj.PaymentMethodProfiles[0].MethodName = imp.MethodName; sapcust.custObj.PaymentMethodProfiles[0].MethodType = "cc"; if (AddCustomer(ref sapcust)) { SetText("\r\n" + string.Format("Customer {0} card {1} added", sapcust.cccust.CustomerID, sapcust.cccust.cardNum)); } else { SetText("\r\n" + string.Format("Failed to add Customer {0} card {1}", sapcust.cccust.CustomerID, sapcust.cccust.cardNum)); } } SetText("\r\nImport Completed."); } catch (Exception ex) { showMessage(ex.Message); } finally { try { oCustImpForm.Items.Item(btnFImp).Enabled = true; oCustImpForm.Items.Item(btnFind).Enabled = true; oCustImpForm.Items.Item(btnImp).Enabled = true; } catch (Exception) { } } }
private void CustImpFormHandler(SAPbouiCOM.Form form, SAPbouiCOM.ItemEvent pVal) { try { if (pVal.BeforeAction) { } else { switch (pVal.EventType) { case SAPbouiCOM.BoEventTypes.et_CLICK: break; case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED: { switch (pVal.ItemUID) { case btnClose: try { if (tImpProcess != null) { tImpProcess.Abort(); } } catch (Exception) { } oCustImpForm.Close(); break; case btnImp: try { if (custObjForImport == null) { form.Items.Item(btnFind).Click(); } else { string cardcode = getFormItemVal(form, editCustomerID); if (cardcode == "") { showMessage("Enter customer ID."); } else { if (custObjForImport == null) { form.Items.Item(btnFind).Click(); } else { string code = FindCustomerByID(cardcode); if (code == "") { showMessage("Customer not found"); return; } if (SBO_Application.MessageBox("Import payment method(s) to " + cardcode + "?", 1, "Yes", "No") == 1) { foreach (PaymentMethodProfile pm in custObjForImport.PaymentMethodProfiles) { if (!isPaymentMethodExists(cardcode, pm.CardNumber, pm.CardExpiration)) { CCCUST cccust = new CCCUST(); cccust.CustomerID = cardcode; cccust.active = 'Y'; cccust.email = custObjForImport.Email; cccust.firstName = custObjForImport.BillingAddress.FirstName; cccust.lastName = custObjForImport.BillingAddress.LastName; cccust.street = custObjForImport.BillingAddress.Address1; cccust.city = custObjForImport.BillingAddress.City; cccust.state = custObjForImport.BillingAddress.State; cccust.zip = custObjForImport.BillingAddress.ZipCode; cccust.expDate = pm.CardExpiration; cccust.cardCode = pm.CardCode; try { if (pm.MethodName != null && pm.MethodName != "") { if (pm.MethodName.IndexOf(" ") >= 0) { string name = pm.MethodName; string[] s = name.Split(' '); cccust.firstName = s[0]; cccust.lastName = s[s.Length - 1]; } } } catch (Exception) { } cccust.routingNumber = pm.Routing; cccust.checkingAccount = pm.Account; cccust.GroupName = getGroupName(cardcode); cccust.CustNum = custObjForImport.CustomerToken; cccust.MethodID = pm.MethodID; int id = getNextTableID("@CCCUST"); string ccname = cccust.firstName + " " + cccust.lastName; string desc = ccname; if (pm.MethodName != "" && pm.MethodName != "") { desc = pm.MethodName; } if (pm.MethodType == "check") { cccust.methodDescription = id.ToString() + "_" + pm.Routing + " " + pm.Account + "(" + desc + ")"; cccust.checkingAccount = pm.Account; cccust.routingNumber = pm.Routing; } else { cccust.cardNum = pm.CardNumber; cccust.methodDescription = id.ToString() + "_" + pm.CardNumber + " " + pm.CardExpiration + "(" + desc + ")"; cccust.cardType = pm.CardType; } string cardid = ""; cccust.CardName = getCardName(cccust.GroupName, cccust.cardType, "", ref cardid); cccust.CCAccountID = cardid; insert(cccust); SBO_Application.SetStatusBarMessage(string.Format("Import payment method {0} to {1}.", cccust.cardNum, cardcode), SAPbouiCOM.BoMessageTime.bmt_Medium, false); } } } } } } } catch (Exception ex) { SBO_Application.SetStatusBarMessage(string.Format("Import payment method error: {0}.", ex.Message), SAPbouiCOM.BoMessageTime.bmt_Medium, true); } break; case btnFImp: string fn = getFormItemVal(form, editFileName); if (fn == "") { showMessage("Please enter file name."); } else { if (!File.Exists(fn)) { showMessage("File: " + fn + " not found."); } else { if (SBO_Application.MessageBox("Import payment method(s) from file " + fn + "?", 1, "Yes", "No") == 1) { SetText("Import Begin. Please wait...\r\n"); tImpProcess = new Thread(importThread); tImpProcess.Start(); } } } break; case btnExpFImp: fn = getFormItemVal(form, editExpFileName); if (fn == "") { showMessage("Please enter exported customer file name."); } else { if (!File.Exists(fn)) { showMessage("File: " + fn + " not found."); } else { if (SBO_Application.MessageBox("Import payment method(s) from file " + fn + "?", 1, "Yes", "No") == 1) { SetText("Import Begin. Please wait...\r\n"); tImpProcess = new Thread(ExpImportThread); tImpProcess.Start(); } } } break; } } break; } } } catch (Exception ex) { errorLog(ex); } }