Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- //using System.Drawing;
- using System.Linq;
- using System.Text;
- //using System.Windows.Forms;
- using System.Data.Odbc;
- using System.Data.OleDb;
- using System.Xml;
- using System.IO;
- using System.IO.Ports;
- using System.Net.Mail;
- using System.Diagnostics;
- using System.Security;
- using System.Security.Permissions;
- using System.Text.RegularExpressions;
- namespace aGQaInvoiceMonitoringSystem
- {
- class InvoiceMonitor
- {
- public AutoCert.AutoCert ac = new AutoCert.AutoCert();
- public DateTime daysBack = (DateTime)Properties.Settings.Default["SeedDate"];
- public FileSystemWatcher watcher = new FileSystemWatcher();
- [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
- private void OnChanged(object source, FileSystemEventArgs e)
- {
- try
- {
- DoInvoice();
- }
- catch (Exception err)
- {
- LogMonitorEvent(err.ToString(), true);
- SendEmail(true, "tkrapf@agqa.com", "IDD_AIMS@aGqa.com", "", "", "MONITORING FAILED!!!!", err.ToString());
- }
- }
- public void MonitorStart()
- {
- watcher.Path = Properties.Settings.Default["WatchPath"].ToString();
- watcher.NotifyFilter = NotifyFilters.LastWrite;
- watcher.Filter = "recvbls.dbf";
- watcher.Changed += new FileSystemEventHandler(OnChanged);
- watcher.EnableRaisingEvents = true;
- }
- public void MonitorStop()
- {
- watcher.EnableRaisingEvents = false;
- }
- private void DoInvoice()
- {
- try
- {
- OdbcConnection conn = new OdbcConnection();
- conn.ConnectionString = Properties.Settings.Default["ConnStrFoxPro"].ToString();
- conn.Open();
- string sqlSt = "SELECT salesman.name as 'supplierSalesman', * FROM recvbls JOIN customer ON recvbls.cust_no = customer.cust_no JOIN salesman ON recvbls.salesman1 = salesman.salesman ";
- sqlSt += " WHERE d_type='I' AND date >= {^" + daysBack.ToString("yyyy-MM-dd") + "} ";
- if ((bool)Properties.Settings.Default["WhitelistedRetailersOnly"]) { sqlSt += " AND customer.cust_no IN (SELECT alias FROM agaRetailers WHERE active = 1) "; }
- sqlSt += " ORDER BY INVOICE_NO";
- OdbcDataAdapter dAdapter = new OdbcDataAdapter(sqlSt, conn);
- DataSet dsInvoices = new DataSet();
- dAdapter.Fill(dsInvoices, "invoices");
- string invoices = "";
- DataSet dsItems;
- Boolean isNotLooseStoneItem;
- foreach (DataRow i in dsInvoices.Tables["invoices"].Rows)
- {
- //is this a new invoice or one that has been processed to aGQa AutoCert already?
- //if this invoice has been processed already, change it's revision number and carry on without sending again to aGQa.
- if (iMonHasInvoiceBeenRecordedPreviously(i["invoice_no"].ToString()))
- { continue; } //invoice has already been processed, so just skip and goto the next in the list
- //Get invoice items for this invoice
- string itemsJew = " ";
- itemsJew += " jewhst.item_no as 'style', "; //style
- itemsJew += " q2 as 'itemQty', "; //item qty
- itemsJew += " jewhst.price as 'price', "; //invoice price
- itemsJew += " category2 as 'cut', "; //cut
- itemsJew += " color as 'color', "; //color
- itemsJew += " clarity as 'clarity', "; //clarity
- itemsJew += " sto_no as 'carat', "; //carat
- itemsJew += " category1 as 'department', "; //department
- itemsJew += " category3 as 'category', "; //category
- itemsJew += " metal as 'metal', "; //metal
- itemsJew += " sty_no as 'StyleForImage' "; //special order
- sqlSt = "SELECT " + itemsJew + " FROM jewhst JOIN jewelry ON jewhst.item_no = jewelry.item_no JOIN qualities ON jewelry.dia_qual = qualities.quality WHERE d_no = " + i["d_no"] + " ORDER BY jewhst.item_no ";
- isNotLooseStoneItem = true;
- dAdapter = new OdbcDataAdapter(sqlSt, conn);
- dsItems = new DataSet();
- dAdapter.Fill(dsItems, "items");
- if (dsItems.Tables["items"].Rows.Count < 1) //invoice had no manufacturered items, maybe it has loose gem items from the diaHst table?
- {
- isNotLooseStoneItem = false;
- string itemsDia = " ";
- itemsDia += " descrip as 'description', "; //invoice description line
- itemsDia += " cerhst.item_no as 'style', "; //style
- itemsDia += " q2 as 'itemQty', "; //item qty
- itemsDia += " cerhst.price as 'price', "; //invoice price
- itemsDia += " category1 as 'cut', "; //cut
- itemsDia += " category2 as 'color', "; //color
- itemsDia += " category3 as 'clarity', "; //clarity
- itemsDia += " avg_wght as 'carat', "; //carat
- itemsDia += " 'Loose Diamond(s)' as 'department', "; //department
- itemsDia += " 'Loose Diamond(s)' as 'category', "; //department
- itemsDia += " category4 as 'labName', "; //metal
- itemsDia += " cert_no as 'labCertNo', "; //qty1
- itemsDia += " length, width, depth "; //qty2
- sqlSt = " SELECT " + itemsDia + " FROM cerhst JOIN certs ON cerhst.item_no = certs.item_no WHERE d_no = " + i["d_no"] + " ORDER BY cerhst.item_no ";
- dAdapter = new OdbcDataAdapter(sqlSt, conn);
- dsItems = new DataSet();
- dAdapter.Fill(dsItems, "items");
- if (dsItems.Tables["items"].Rows.Count < 1) //no manufactured items or loose stones found.... strange! just continue on, skipping this invoice.
- { continue; }
- }
- XmlDocument doc = new XmlDocument();
- XmlElement root = doc.CreateElement("Invoices");
- XmlElement nInv;
- XmlElement node;
- nInv = doc.CreateElement("Invoice");
- root.AppendChild(nInv);
- //Invoice Date
- node = doc.CreateElement("Date");
- node.InnerText = ((DateTime)i["date"]).ToShortDateString();
- nInv.AppendChild(node);
- //Invoice No
- node = doc.CreateElement("Number");
- node.InnerText = i["invoice_no"].ToString().Trim();
- nInv.AppendChild(node);
- //Retailer Node
- XmlElement nRetailer;
- nRetailer = doc.CreateElement("Retailer");
- nInv.AppendChild(nRetailer);
- //Retailer ID
- node = doc.CreateElement("ID");
- node.InnerText = i["cust_no"].ToString().Trim();
- nRetailer.AppendChild(node);
- //Retailer Name
- node = doc.CreateElement("Name");
- node.InnerText = i["Name"].ToString().Trim();
- nRetailer.AppendChild(node);
- //Retailer Address
- string addStr = "";
- if (i["Address"].ToString().Trim() != "") { addStr += i["Address"].ToString().Trim() + ", "; }
- if (i["Address2"].ToString().Trim() != "") { addStr += i["Address2"].ToString().Trim() + ", "; }
- if (i["City"].ToString().Trim() != "") { addStr += i["City"].ToString().Trim() + ", "; }
- if (i["State"].ToString().Trim() != "") { addStr += i["State"].ToString().Trim() + ", "; }
- if (i["Zip"].ToString().Trim() != "") { addStr += i["Zip"].ToString().Trim(); }
- node = doc.CreateElement("Address");
- node.InnerText = addStr;
- nRetailer.AppendChild(node);
- //Emails Node
- XmlElement nEmails;
- nEmails = doc.CreateElement("Emails");
- nInv.AppendChild(nEmails);
- //Retailer Salesperson Email
- node = doc.CreateElement("Email");
- node.SetAttribute("type", "retailerSalesperson");
- node.InnerText = i["email"].ToString().Trim();
- nEmails.AppendChild(node);
- XmlElement nSupplierSpecificInvoice;
- nSupplierSpecificInvoice = doc.CreateElement("SupplierSpecific");
- nInv.AppendChild(nSupplierSpecificInvoice);
- node = doc.CreateElement("AddressStreet");
- node.InnerText = i["Address"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("AddressStreet2");
- node.InnerText = i["Address2"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("AddressCity");
- node.InnerText = i["City"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("AddressState");
- node.InnerText = i["State"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("AddressZip");
- node.InnerText = i["Zip"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("ShipMethod");
- node.InnerText = i["shipvia"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("Shippable");
- node.InnerText = "true";
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("PONumber");
- node.InnerText = i["po_no"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("Salesman");
- node.InnerText = i["supplierSalesman"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- node = doc.CreateElement("orderedby");
- node.InnerText = i["attention"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- //Terms
- node = doc.CreateElement("Terms");
- node.InnerText = i["Terms"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- //Due Date
- node = doc.CreateElement("DueDate");
- node.InnerText = ((DateTime)i["d_date"]).ToShortDateString();
- nSupplierSpecificInvoice.AppendChild(node);
- //put in Cert/Item nodes
- XmlElement nCerts;
- nCerts = doc.CreateElement("Certificates");
- nInv.AppendChild(nCerts);
- XmlElement nCert;
- foreach (DataRow r in dsItems.Tables["items"].Rows)
- {
- nCert = doc.CreateElement("Certificate");
- nCert.SetAttribute("templatable", "true");
- nCerts.AppendChild(nCert);
- node = doc.CreateElement("SpecialOrder");
- if (isNotLooseStoneItem) { if (r["StyleForImage"].ToString().Trim() == "SP ORDER") { node.InnerText = "true"; } else { node.InnerText = "false"; } }
- else { node.InnerText = "false"; }
- nCert.AppendChild(node);
- node = doc.CreateElement("RingSize");
- if (isNotLooseStoneItem)
- {
- if (r["Style"].ToString().Trim().Substring(0, 1).ToUpper().Contains("R") || r["Style"].ToString().Trim().Substring(0, 1).ToUpper().Contains("Y"))
- { node.InnerText = "Stock"; }
- else
- { node.InnerText = ""; }
- }
- else { node.InnerText = ""; }
- nCert.AppendChild(node);
- node = doc.CreateElement("Style");
- node.InnerText = r["style"].ToString().Trim();
- nCert.AppendChild(node);
- node = doc.CreateElement("Stock");
- node.InnerText = r["style"].ToString().Trim();
- nCert.AppendChild(node);
- node = doc.CreateElement("Quantity");
- node.InnerText = (Convert.ToInt32(r["itemQty"]) * -1).ToString().Trim(); //quantities are negative in their tables because they are being sold out of inventory
- nCert.AppendChild(node);
- node = doc.CreateElement("Price");
- node.InnerText = r["price"].ToString().Trim();
- nCert.AppendChild(node);
- //---------------------------------------------------------------Supplier Specific Items-------------------------
- XmlElement nSupplierSpecific;
- nSupplierSpecific = doc.CreateElement("SupplierSpecific");
- nCert.AppendChild(nSupplierSpecific);
- node = doc.CreateElement("Valid");
- node.InnerText = "1";
- nSupplierSpecific.AppendChild(node);
- node = doc.CreateElement("Templatable");
- node.InnerText = "true";
- nSupplierSpecific.AppendChild(node);
- string aliasedCategoryID = "0";
- string aliasedQty = "";
- node = doc.CreateElement("Image");
- node.InnerText = AliasImageFromStyle(r["style"].ToString().Trim(), isNotLooseStoneItem, aliasQualityCut(r["cut"].ToString().Trim()), out aliasedCategoryID);
- nSupplierSpecific.AppendChild(node);
- if (aliasedCategoryID != "0") { aliasedQty = aliasQualityQty(aliasedCategoryID); }
- node = doc.CreateElement("CategoryID");
- if (isNotLooseStoneItem) { node.InnerText = aliasedCategoryID; }
- else { node.InnerText = "85"; }
- nSupplierSpecific.AppendChild(node);
- if (isNotLooseStoneItem)
- {
- node = doc.CreateElement("Metal");
- node.InnerText = aliasMetal(r["metal"].ToString().Trim());
- nSupplierSpecific.AppendChild(node);
- }
- node = doc.CreateElement("ItemTypeID");
- node.InnerText = "1";
- nSupplierSpecific.AppendChild(node);
- if (isNotLooseStoneItem)
- {
- node = doc.CreateElement("ProductLineID");
- node.InnerText = "6";
- nSupplierSpecific.AppendChild(node);
- node = doc.CreateElement("Subcategory");
- node.InnerText = aliasProductCategory(r["category"].ToString().Trim());
- nSupplierSpecific.AppendChild(node);
- XmlElement nOrns;
- nOrns = doc.CreateElement("Ornamentals");
- nSupplierSpecific.AppendChild(nOrns);
- XmlElement nOrn;
- nOrn = doc.CreateElement("Ornamental");
- nOrns.AppendChild(nOrn);
- node = doc.CreateElement("Label");
- node.InnerText = "Diamond(s)";
- nOrn.AppendChild(node);
- //4 C's
- node = doc.CreateElement("Cut");
- if (aliasQualityCut(r["cut"].ToString().Trim()).Length > 0)
- { node.InnerText = aliasQualityCut(r["cut"].ToString().Trim()); }
- else
- { node.InnerText = r["cut"].ToString().Trim(); }
- nOrn.AppendChild(node);
- node = doc.CreateElement("Color");
- if (aliasQualityColor(r["style"].ToString().Trim()).Length > 0)
- { node.InnerText = aliasQualityColor(r["style"].ToString().Trim()); }
- else
- { if (r["color"].ToString().Trim() != "") { node.InnerText = r["color"].ToString().Trim(); } }
- nOrn.AppendChild(node);
- node = doc.CreateElement("Clarity");
- if (aliasQualityClarity(r["style"].ToString().Trim()).Length > 0)
- { node.InnerText = aliasQualityClarity(r["style"].ToString().Trim()); }
- else
- { if (r["clarity"].ToString().Trim() != "") { node.InnerText = r["clarity"].ToString().Trim(); } }
- nOrn.AppendChild(node);
- node = doc.CreateElement("Carat");
- node.InnerText = FractionToDecimal(r["carat"].ToString().Trim());
- nOrn.AppendChild(node);
- node = doc.CreateElement("TQty");
- node.InnerText = aliasedQty;
- nOrn.AppendChild(node);
- }
- else //loose stones go thru this section
- {
- node = doc.CreateElement("ProductLineID");
- node.InnerText = "9";
- nSupplierSpecific.AppendChild(node);
- node = doc.CreateElement("Description");
- node.InnerText = r["description"].ToString().Trim();
- nSupplierSpecificInvoice.AppendChild(node);
- XmlElement nStones;
- nStones = doc.CreateElement("CenterStones");
- nSupplierSpecific.AppendChild(nStones);
- XmlElement nStone;
- nStone = doc.CreateElement("CenterStone");
- nStones.AppendChild(nStone);
- node = doc.CreateElement("Label");
- node.InnerText = "Diamond(s)";
- nStone.AppendChild(node);
- //4 C's
- node = doc.CreateElement("Cut");
- if (aliasQualityCut(r["cut"].ToString().Trim()).Length > 0)
- { node.InnerText = aliasQualityCut(r["cut"].ToString().Trim()); }
- else
- { node.InnerText = r["cut"].ToString().Trim(); }
- nStone.AppendChild(node);
- node = doc.CreateElement("Color");
- if (r["color"].ToString().Trim() != "") { node.InnerText = r["color"].ToString().Trim(); }
- nStone.AppendChild(node);
- node = doc.CreateElement("Clarity");
- if (r["clarity"].ToString().Trim() != "") { node.InnerText = r["clarity"].ToString().Trim(); }
- nStone.AppendChild(node);
- node = doc.CreateElement("Carat");
- node.InnerText = FractionToDecimal(r["carat"].ToString().Trim());
- nStone.AppendChild(node);
- node = doc.CreateElement("TQty");
- node.InnerText = "1";
- nStone.AppendChild(node);
- node = doc.CreateElement("LabName");
- node.InnerText = r["labName"].ToString().Trim();
- nStone.AppendChild(node);
- node = doc.CreateElement("LabCertNo");
- node.InnerText = r["labCertNo"].ToString().Trim();
- nStone.AppendChild(node);
- node = doc.CreateElement("DiamondDimensions");
- string dimensions = "";
- if (Convert.ToDecimal(r["length"]) > 0) { dimensions += r["length"].ToString().Trim() + " x "; }
- if (Convert.ToDecimal(r["width"]) > 0) { dimensions += r["width"].ToString().Trim(); }
- if (Convert.ToDecimal(r["depth"]) > 0) { dimensions += " x " + r["depth"].ToString().Trim(); }
- node.InnerText = dimensions;
- nStone.AppendChild(node);
- }
- }
- doc.AppendChild(root);
- invoices = IndentXMLString(doc.InnerXml) + Environment.NewLine + Environment.NewLine;
- SendEmail(false, "tkrapf@agqa.com", "IDD_Invoices@aGQa.com", "", "", "IDD Invoice: " + i["invoice_no"].ToString().Trim() + " Doc#: " + i["d_no"].ToString().Trim() + " Date: " + ((DateTime)i["date"]).ToShortDateString() + " - No of Item(s): " + dsItems.Tables["items"].Rows.Count.ToString() + " - Orn: " + isNotLooseStoneItem.ToString(), invoices);
- try
- {
- ac.UpdateDatabase("IDD", "diamonds", invoices);
- }
- catch (Exception err)
- {
- SendEmail(true, "tkrapf@agqa.com", "IDD_Invoice@aGqa.com", "", "", "MONITORING FAILED!!!!" + i["Invoice_No"].ToString().Trim(), err.ToString());
- }
- //this invoice has now been processed, mark it as such in the agaIMon table.
- iMonInsertNewInvoice(i["invoice_no"].ToString());
- }
- conn.Close();
- }
- catch (Exception err)
- {
- LogMonitorEvent(err.ToString(), true);
- SendEmail(true, "tkrapf@agqa.com", "IDD_Invoice@aGqa.com", "", "", "DO_INVOICE FAILED!!!!", err.ToString());
- }
- }
- #region utilsGeneral
- private bool iMonHasInvoiceBeenRecordedPreviously(string invoiceNo)
- {
- OdbcConnection conn = new OdbcConnection();
- conn.ConnectionString = Properties.Settings.Default["ConnStrFoxPro"].ToString();
- conn.Open();
- string sqlSt = "SELECT * FROM agaIMon WHERE invoice = '" + invoiceNo + "'";
- OdbcDataAdapter dAdapter = new OdbcDataAdapter(sqlSt, conn);
- DataSet dsInvoices = new DataSet();
- dAdapter.Fill(dsInvoices, "inv");
- if (dsInvoices.Tables["inv"].Rows.Count > 0)
- { return true; }
- else
- { return false; }
- }
- public void LogMonitorEvent(string sEvent, bool isError)
- {
- string sSource;
- string sLog;
- sSource = "aGQa Invoice Monitoring System";
- sLog = "Application";
- if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);
- if (!isError)
- { EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information); }
- else
- { EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Error); }
- }
- private string IndentXMLString(string xml)
- {
- string outXml = string.Empty;
- MemoryStream ms = new MemoryStream();
- XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.Unicode);
- XmlDocument doc = new XmlDocument();
- try
- {
- doc.LoadXml(xml);
- xtw.Formatting = Formatting.Indented;
- doc.WriteContentTo(xtw);
- xtw.Flush();
- ms.Seek(0, SeekOrigin.Begin);
- StreamReader sr = new StreamReader(ms);
- return sr.ReadToEnd();
- }
- catch (Exception err)
- {
- LogMonitorEvent(err.ToString(), true);
- SendEmail(true, "tkrapf@agqa.com", "IDD_Invoice@aGqa.com", "", "", "Formating XML for Email FAILED!!!!", err.ToString());
- return string.Empty;
- }
- }
- public void SendEmail(bool isHtml, string eTo, string eFrom, string eCC, string eBCC, string eSubject, string eBody)
- {
- if (!eTo.Contains("@")) { return; }
- MailMessage mail = new MailMessage(eFrom, eTo, eSubject, eBody);
- mail.To.Add("dwendorf@aGQa.com");
- mail.To.Add("scalhoun@aGQa.com");
- if (isHtml) { mail.IsBodyHtml = true; }
- if (eCC.Length > 0) { mail.CC.Add(eCC); };
- if (eBCC.Length > 0) { mail.Bcc.Add(eBCC); };
- SmtpClient sender = new SmtpClient();
- sender.Host = "24.196.66.22"; //Properties.Settings.Default["MailServer"].ToString();
- sender.Port = 25;
- try
- {
- sender.Send(mail);
- }
- catch (Exception ex)
- { }
- }
- private void iMonInsertNewInvoice(string invoiceNo)
- {
- OdbcConnection conn = new OdbcConnection();
- conn.ConnectionString = Properties.Settings.Default["ConnStrFoxPro"].ToString();
- conn.Open();
- string sqlSt = "SELECT guid, date, invoice, revision FROM agaIMon";
- OdbcDataAdapter dAdapter = new OdbcDataAdapter(sqlSt, conn);
- DataSet dsInvoices = new DataSet();
- dAdapter.Fill(dsInvoices, "inv");
- OdbcCommand cmd = new OdbcCommand();
- string myGuid = System.Guid.NewGuid().ToString();
- string sql = "INSERT INTO agaIMon ([guid], [date], [invoice], [revision]) VALUES ";
- sql += "('" + myGuid + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + invoiceNo + "','0')";
- cmd = new OdbcCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- #endregion //utilsGeneral
- #region ItemAliases
- static string AliasImageFromStyle(string style, bool isNotLooseStone, string cut, out string categoryId)
- {
- //default this to zero incase we don't catch the category correctly.
- categoryId = "0";
- if (!isNotLooseStone) //it IS a loose stone!
- {
- string folder = "1345/";
- categoryId = "85";
- switch (cut.ToLower())
- {
- case "asscher": return folder + "asscher.png";
- case "baguette": return folder + "baguette.png";
- case "cushion": return folder + "cushion.png";
- case "emerald": return folder + "emerald.png";
- case "flower round": return folder + "flower-round.png";
- case "heart": return folder + "heart.png";
- case "marquise": return folder + "marquise.png";
- case "oval": return folder + "oval.png";
- case "pear": return folder + "pear.png";
- case "princess": return folder + "princess.png";
- case "princess quad": return folder + "princess-quad.png";
- case "round": return folder + "round.png";
- case "square radiant": return folder + "square-radiant.png";
- case "trilliant": return folder + "trilliant.png";
- default: return "unknown";
- }
- }
- //it IS a finished good
- if (style.Length < 4) style += "JUNKSTYLE#"; //stops style#'s that are less than 4chars in length
- string pix = "";
- style = style.ToUpper();
- //-----EARRINGS----------------------------------------------------------------------------------
- if (style.Substring(0, 1) == "E")
- {
- if (Regex.Match(style, "E[?0-9]").Success) { pix = "EARRING-3"; categoryId = "110"; }
- if (Regex.Match(style, "EM[?0-9]").Success) { pix = "EARRING-2"; categoryId = "110"; }
- if (Regex.Match(style, "EB[?0-9]").Success) { pix = "EARRING-3"; categoryId = "110"; }
- if (Regex.Match(style, "EP[?0-9]").Success) { pix = "EARRING-1"; categoryId = "111"; }
- if (Regex.Match(style, "EPV[?0-9]").Success) { pix = "EARRING-1"; categoryId = "111"; }
- if (Regex.Match(style, "ERP71[?0-9]").Success) { pix = "ERP71"; categoryId = "151"; }
- if (Regex.Match(style, "ER71[?0-9]").Success) { pix = "ER71"; categoryId = "150"; }
- if (Regex.Match(style, "ERR[?0-9]").Success) { pix = "ERR050"; categoryId = "134"; }
- if (Regex.Match(style, "ER61[?0-9]").Success) { pix = "ER61"; categoryId = "145"; }
- if (Regex.Match(style, "ER81[?0-9]").Success) { pix = "ER81"; categoryId = "144"; }
- if (Regex.Match(style, "ER51[?0-9]").Success) { pix = "ER51"; categoryId = "146"; }
- if (style.Length >= 6)
- {
- if (style.Substring(0, 6) == "ER4003" || style.Substring(0, 6) == "ER4008") { pix = "ER4003"; categoryId = "147"; }
- if (style.Substring(0, 6) == "ER4004" || style.Substring(0, 6) == "ER4009") { pix = "ER4004"; categoryId = "148"; }
- if (style.Substring(0, 6) == "ER4001" || style.Substring(0, 6) == "ER4002") { pix = "ER4001"; categoryId = "149"; }
- if (style.Substring(0, 6) == "ER4005" || style.Substring(0, 6) == "ER4006") { pix = "ER4001"; categoryId = "149"; }
- }
- }
- //-----END OF EARRINGS---------------------------------------------------------------------------
- //-----RINGS-------------------------------------------------------------------------------------
- if (style.Substring(0, 1) == "R" || style.Substring(0, 1) == "Y")
- {
- if (Regex.Match(style, "R0[?0-9]").Success || Regex.Match(style, "R10[?0-9]").Success) { pix = "R01"; categoryId = "112"; }
- if (Regex.Match(style, "RP0[?0-9]").Success || Regex.Match(style, "RP10[?0-9]").Success) { pix = "RP01"; categoryId = "113"; }
- if (style.Length >= 5)
- {
- if (style.Substring(0, 5) == "R6067" || style.Substring(0, 5) == "R6085" || style.Substring(0, 5) == "R6088") { pix = "R6067"; categoryId = "114"; }
- if (style.Substring(0, 5) == "R6066" || style.Substring(0, 5) == "R6086" || style.Substring(0, 5) == "R6089") { pix = "R6066"; categoryId = "114"; }
- if (style.Substring(0, 5) == "R6068" || style.Substring(0, 5) == "R6087" || style.Substring(0, 5) == "R6090") { pix = "R6068"; categoryId = "114"; }
- if (Regex.Match(style, "YP0[?0-9]").Success || style.Substring(0, 5) == "YP100" || style.Substring(0, 5) == "YP150" || style.Substring(0, 5) == "YP200" || style.Substring(0, 5) == "YP300")
- { if (style.IndexOf("F2") > 0) { pix = "YP100F2"; categoryId = "130"; } else { pix = "YP100"; categoryId = "128"; } }
- if (style.Substring(0, 5) == "YE050" || style.Substring(0, 5) == "YE100" || style.Substring(0, 5) == "YE150" || style.Substring(0, 5) == "YE200") { pix = "YE100"; categoryId = "133"; }
- if (style.Substring(0, 5) == "YR050" || style.Substring(0, 5) == "YR075" || style.Substring(0, 5) == "YR100" || style.Substring(0, 5) == "YR150") { pix = "YR100"; categoryId = "135"; }
- }
- if (Regex.Match(style, "R171[?0-9]").Success) { pix = "R171"; categoryId = "115"; }
- if (Regex.Match(style, "RP171[?0-9]").Success) { pix = "RP171"; categoryId = "116"; }
- if (Regex.Match(style, "R161[?0-9]").Success) { pix = "R161"; categoryId = "117"; }
- if (Regex.Match(style, "R141[?0-9]").Success) { pix = "R141"; categoryId = "118"; }
- if (Regex.Match(style, "R151[?0-9]").Success) { pix = "R151"; categoryId = "119"; }
- if (Regex.Match(style, "R191[?0-9]").Success) { pix = "R191"; categoryId = "124"; }
- if (Regex.Match(style, "R181[?0-9]").Success) { pix = "R181"; categoryId = "115"; }
- if (Regex.Match(style, "RP181[?0-9]").Success) { pix = "RP181"; categoryId = "116"; }
- if (Regex.Match(style, "R101[?0-9]").Success) { pix = "R101"; categoryId = "125"; }
- if (Regex.Match(style, "R40[?0-9]").Success || Regex.Match(style, "R41[?0-9]").Success || Regex.Match(style, "R42[?0-9]").Success) { pix = "R4004"; categoryId = "126"; }
- if (style.Length >= 6)
- {
- if (style.Substring(0, 6) == "RET100" || style.Substring(0, 6) == "RET150" || style.Substring(0, 6) == "RET200" || style.Substring(0, 6) == "RET300")
- { if (style.IndexOf("CH") > 0) { pix = "RET100CH"; categoryId = "123"; } else { pix = "RET100"; categoryId = "123"; } }
- }
- if (style.Length >= 7)
- {
- if (style.Substring(0, 7) == "RET2002" || style.Substring(0, 7) == "RET2003" || style.Substring(0, 7) == "RET2004") { pix = "RET2000"; categoryId = "121"; }
- if (style.Substring(0, 7) == "RET3000" || style.Substring(0, 7) == "RET3001") { pix = "RET3000"; categoryId = "122"; }
- }
- if (style.Length >= 8)
- {
- if (style.Substring(0, 8) == "RETP100" || style.Substring(0, 8) == "RETP150" || style.Substring(0, 8) == "RETP200" || style.Substring(0, 8) == "RETP300") { pix = "RETP100"; categoryId = "123"; }
- }
- if (style.Length >= 4)
- {
- if (Regex.Match(style, "Y0[?0-9]").Success || style.Substring(0, 4) == "Y100" || style.Substring(0, 4) == "Y150" || style.Substring(0, 4) == "Y200" || style.Substring(0, 4) == "Y300")
- { if (style.IndexOf("F1") > 0) { pix = "Y100F1"; categoryId = "131"; } else if (style.IndexOf("F2") > 0) { pix = "Y100F2"; categoryId = "131"; } else { pix = "Y100"; categoryId = "127"; } }
- }
- if (Regex.Match(style, "RR400[?0-9]").Success) { pix = "RR400"; categoryId = "130"; }
- if (Regex.Match(style, "RE400[?0-9]").Success) { pix = "RE400"; categoryId = "132"; }
- }
- //-----END OF RINGS------------------------------------------------------------------------------
- //----- PENDANTS --------------------------------------------------------------------------------
- if (style.Substring(0, 1) == "P" || style.Substring(0, 2) == "JP")
- {
- if (Regex.Match(style, "JP30[?0-9]").Success) { pix = "JP30"; categoryId = "137"; }
- if (Regex.Match(style, "P0[?0-9]").Success || style.Substring(0, 4) == "P100") { pix = "P100"; categoryId = "138"; }
- if (Regex.Match(style, "PP[?0-9]").Success) { pix = "PP100"; categoryId = "139"; }
- }
- //----- END OF PENDANTS -------------------------------------------------------------------------
- //----- BRACELETS -------------------------------------------------------------------------------
- if (style.Length >= 4 && style.Substring(0, 1) == "B")
- {
- if (style.Substring(2, 2) == "02") { pix = "B02"; categoryId = "140"; }
- if (style.Substring(2, 2) == "24") { pix = "B24"; categoryId = "141"; }
- if (style.Substring(2, 2) == "04") { pix = "B04"; categoryId = "142"; }
- if (style.Substring(2, 2) == "28") { pix = "B28"; categoryId = "143"; }
- }
- //----- END OF BRACELETS ------------------------------------------------------------------------
- if (pix.Length > 0)
- {
- return "1345/" + pix + ".png";
- }
- else
- {
- return "unknown";
- }
- }
- static string aliasQualityQty(string catId)
- { //if marked with //, the item actually does have qty 1 :)
- switch (catId)
- {
- case "110": return "2";
- case "111": return "2";
- case "112": return "1"; //
- case "113": return "1"; //
- case "114": return "1"; //?
- case "115": return "9"; //?
- case "116": return "10";//?
- case "117": return "7";
- case "118": return "5";
- case "119": return "5";
- case "120": return "23"; //?
- case "121": return "1";
- case "122": return "58"; //?
- case "123": return "84"; //?
- case "124": return "31"; //?
- case "125": return "20"; //?
- case "126": return "11"; //?
- case "127": return "3";
- case "128": return "3";
- case "129": return "15"; //?
- case "130": return "11"; //?
- case "131": return "1";
- case "132": return "1";
- case "133": return "3";
- case "134": return "2";
- case "135": return "3";
- case "136": return "1";
- case "137": return "7";
- case "138": return "1";//
- case "139": return "1";//
- case "140": return "1";
- case "141": return "1";
- case "142": return "1";
- case "143": return "1";
- case "144": return "74"; //?
- case "145": return "68"; //?
- case "146": return "140"; //?
- case "148": return "124"; //?
- case "149": return "42"; //?
- case "150": return "7"; //?
- case "151": return "7"; //?
- default: return "1";
- }
- }
- static string aliasQualityCut(string cut)
- {
- cut = cut.ToLower();
- if (cut == "rd") { return "Round"; }
- if (cut == "prin") { return "Princess"; }
- if (cut == "emer") { return "Emerald"; }
- if (cut == "mq") { return "Marquise"; }
- if (cut == "hrt") { return "Heart"; }
- if (cut == "oval") { return "Oval"; }
- if (cut == "pear") { return "Pear"; }
- if (cut == "tril") { return "Trilliant"; }
- if (cut == "rfl") { return "Flower Round"; }
- if (cut == "pr+b") { return "Princess & Baguette"; }
- if (cut == "pqd") { return "Princess Quad"; }
- if (cut == "dfl") { return "Flower Pear"; }
- if (cut == "bag") { return "Baguette"; }
- if (cut == "rd+b") { return "Round & Baguette"; }
- if (cut == "srad") { return "Square Radiant"; }
- if (cut == "rd+p") { return "Round & Princess"; }
- if (cut == "hfl") { return "Flower Heart"; }
- if (cut == "sqfl") { return "Flower Square"; }
- if (cut == "asc") { return "Asscher"; }
- if (cut == "q") { return "Quad"; }
- if (cut == "cus") { return "Cushion"; }
- if (cut == "rad") { return "Radiant"; }
- return "";
- }
- public string aliasMetal(string met)
- {
- switch (met.ToLower())
- {
- case "14kw": return "14KW Gold";
- case "14ky": return "14KY Gold";
- case "10ky": return "10KY Gold";
- case "18kw": return "18KW Gold";
- case "14tt": return "14K TT";
- case "platinum": return "Platinum";
- case "18ky": return "18KY Gold";
- case "10kw": return "10KW Gold";
- case "palladium": return "Palladium";
- case "10tt": return "10K TT";
- }
- return met;
- }
- public string aliasProductCategory(string cat3)
- {
- //not used, put into supplier specific for no good reason currently
- switch (cat3.ToLower())
- {
- case "3st+": return "Three Stone";
- case "3stn": return "Three Stone";
- case "annv": return "Anniversary";
- case "br": return "Bracelet";
- case "brid": return "Bridal";
- case "cir": return "Circle";
- case "eter": return "Eternity Band";
- case "flw": return "Flower";
- case "fshb": return "Fashion Bangle";
- case "fshe": return "Fashion Earring";
- case "fshp": return "Fashion Pendant";
- case "fsr": return "Fashion Ring";
- case "hoop": return "Hoop Earring";
- case "jour": return "Journey";
- case "quad": return "Princess Quad";
- case "rdl": return "Rondel";
- case "semi": return "Semi-Mounting";
- case "sflw": return "Square";
- case "sol": return "Solitaire";
- case "sp": return "Special Order";
- }
- return cat3;
- }
- static string aliasQualityColor(string style)
- {
- if (style.IndexOf("K3") > 0 || style.IndexOf("N3") > 0) { return "G/H"; }
- if (style.IndexOf("K4") > 0 || style.IndexOf("N4") > 0) { return "G/H"; }
- if (style.IndexOf("K5") > 0 || style.IndexOf("N5") > 0) { return "G/H"; }
- if (style.IndexOf("K6") > 0 || style.IndexOf("N6") > 0) { return "G/H"; }
- if (style.IndexOf("K7") > 0 || style.IndexOf("N7") > 0) { return "G/H"; }
- if (style.IndexOf("K8") > 0 || style.IndexOf("N8") > 0) { return "G/H"; }
- if (style.IndexOf("K9") > 0 || style.IndexOf("N9") > 0) { return "G/H"; }
- if (style.IndexOf("K10") > 0 || style.IndexOf("N10") > 0) { return "G/H"; }
- if (style.IndexOf("S4") > 0) { return "I/J"; }
- if (style.IndexOf("S5") > 0) { return "I/J"; }
- if (style.IndexOf("S6") > 0) { return "I/J"; }
- if (style.IndexOf("S7") > 0) { return "I/J"; }
- if (style.IndexOf("S8") > 0) { return "I/J"; }
- if (style.IndexOf("S9") > 0) { return "I/J"; }
- if (style.IndexOf("S10") > 0) { return "I/J"; }
- return ""; //wasn't able to find
- }
- static string aliasQualityClarity(string style)
- {
- if (style.IndexOf("K3") > 0 || style.IndexOf("N3") > 0) { return "VS2"; }
- if (style.IndexOf("K4") > 0 || style.IndexOf("N4") > 0) { return "SI1"; }
- if (style.IndexOf("K5") > 0 || style.IndexOf("N5") > 0) { return "SI2"; }
- if (style.IndexOf("K6") > 0 || style.IndexOf("N6") > 0) { return "SI3"; }
- if (style.IndexOf("K7") > 0 || style.IndexOf("N7") > 0) { return "I1"; }
- if (style.IndexOf("K8") > 0 || style.IndexOf("N8") > 0) { return "I1/I2"; }
- if (style.IndexOf("K9") > 0 || style.IndexOf("N9") > 0) { return "I2"; }
- if (style.IndexOf("K10") > 0 || style.IndexOf("N10") > 0) { return "I2/I3"; }
- if (style.IndexOf("S4") > 0) { return "SI1"; }
- if (style.IndexOf("S5") > 0) { return "SI2"; }
- if (style.IndexOf("S6") > 0) { return "SI3"; }
- if (style.IndexOf("S7") > 0) { return "I1"; }
- if (style.IndexOf("S8") > 0) { return "I1/I2"; }
- if (style.IndexOf("S9") > 0) { return "I2"; }
- if (style.IndexOf("S10") > 0) { return "I2/I3"; }
- return ""; //wasn't able to find
- }
- #endregion //itemAliases
- #region fracsToDecimalUtils
- static string FractionToDecimal(string frac)
- {
- try
- {
- if (isDecimal(frac)) { return frac; } //no nothing, it's already a decimal value
- if (parseJunkCases(frac).Length > 0) { return parseJunkCases(frac); } //convert shit values like 2CT and 11/2
- string[] complexParts = frac.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- string fraction;
- if (complexParts.Length == 1)
- fraction = complexParts[0];
- else
- fraction = complexParts[1];
- string[] simpleParts = fraction.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
- double fractionValue = Convert.ToDouble(simpleParts[0]);
- if (simpleParts[0].Length == 2) { return frac; }
- if (simpleParts.Length > 1) fractionValue = fractionValue / Convert.ToDouble(simpleParts[1]);
- if (complexParts.Length > 1) fractionValue += Convert.ToDouble(complexParts[0]);
- fractionValue = Math.Round(fractionValue, 2);
- return fractionValue.ToString();
- }
- catch
- { return frac; }
- }
- static string parseJunkCases(string val)
- {
- if (val == "1CT") { return "1.00"; }
- if (val == "2CT") { return "2.00"; }
- if (val == "3CT") { return "3.00"; }
- if (val == "4CT") { return "4.00"; }
- if (val == "11/2") { return "1.50"; }
- if (val == "11/3") { return "1.33"; }
- if (val == "11/4") { return "1.25"; }
- if (val == "11/8") { return "1.13"; }
- if (val == "21/2") { return "2.50"; }
- if (val == "21/3") { return "2.33"; }
- if (val == "21/4") { return "2.25"; }
- if (val == "21/8") { return "2.13"; }
- if (val == "31/2") { return "3.50"; }
- if (val == "31/3") { return "3.33"; }
- if (val == "31/4") { return "3.25"; }
- if (val == "31/8") { return "3.13"; }
- if (val == "41/2") { return "4.50"; }
- if (val == "41/3") { return "4.33"; }
- if (val == "41/4") { return "4.25"; }
- if (val == "41/8") { return "4.13"; }
- if (val == "51/2") { return "5.50"; }
- if (val == "51/3") { return "5.33"; }
- if (val == "51/4") { return "5.25"; }
- if (val == "51/8") { return "5.13"; }
- if (val == "61/2") { return "6.50"; }
- if (val == "61/3") { return "6.33"; }
- if (val == "61/4") { return "6.25"; }
- if (val == "61/8") { return "6.13"; }
- return ""; //couldn't fix, so short circuit
- }
- static bool isDecimal(string val)
- {
- try
- {
- Convert.ToDouble(val);
- return true;
- }
- catch
- {
- return false;
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement