static void Main(string[] args) { try { WriteToLog("Start adding registr."); string startDate = ""; string endDate = ""; int per = int.Parse(args[0].Substring(1)); if (args[0].Substring(0, 1) == "z") { startDate = DateTime.Today.AddDays(-per).ToString("yyyy-MM-dd"); endDate = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"); } else if (args[0].Substring(0, 1) == "l") { DateTime today = DateTime.Today.AddMonths(-per); startDate = new DateTime(today.Year, today.Month, 1).ToString("yyyy-MM-dd"); endDate = new DateTime(DateTime.Today.Year, DateTime.Today.AddMonths(-per + 1).Month, 1).AddDays(-1).ToString("yyyy-MM-dd"); } else { throw new ArgumentException("Invalid parameter format."); } string[] orgs = ConfigurationManager.AppSettings["Moldtelecom"].Split(','); int[] moldtelecom = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["MaxDsl"].Split(','); int[] maxdsl = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["Unite"].Split(','); int[] unite = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["UnitePrePay"].Split(','); int[] unitePrePay = (from s in orgs select int.Parse(s)).ToArray(); long[] stornate = (from s in StornateNeexportate select long.Parse(s)).ToArray(); List<int[]> organizations = new List<int[]> {moldtelecom, maxdsl, unite, unitePrePay}; QsRetailDataContext qsRetail = new QsRetailDataContext(); paymentsWSClient clientService = new paymentsWSClient(); XmlDocument doc = new XmlDocument(); for (int i = 1; i <= organizations.Count; i++) { int count = 0; decimal sum = 0; try { var qsMovements = from p in qsRetail.Movements where organizations[i - 1].Contains(p.OrganizationIDTo) && ((p.Document.StatusID == 2 && p.IsReceivedTo) || (p.Document.StatusID == 3 && p.IsReceivedTo == false)) && p.Direction && p.OperationDate >= DateTime.Parse(startDate) && p.OperationDate < DateTime.Parse(endDate).AddDays(1) && p.Document.TransactionAmount > 0 && !stornate.Contains(p.Document.ID) select p; foreach (var qsMovement in qsMovements) { if (qsMovement.Document.StatusID == 3) { count = count + 2; } else { count++; sum += qsMovement.Document.TransactionAmount; } } string result = clientService.addPaymentsRegistr( user, password, i, DateTime.Parse(startDate).ToString("yyyyMMdd"), DateTime.Parse(endDate).ToString("yyyyMMdd"), "VICBMD2X", sum.ToString("0.00"), count.ToString()); if (result.Trim().Substring(0, 1) == "<") { doc.LoadXml(result); throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText + " (" + i + ") Count: " + count.ToString() + " Suma: " + sum.ToString("0.00") + " lei."); } WriteToLog(string.Format("Registru : {0} - {1} : Response : {2} OK ({3}) Count: {4} Suma: {5} lei.", new object[] { startDate, endDate, result, i, count.ToString(), sum.ToString("0.00") })); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(e.Message); } } WriteToLog("End adding registr."); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(e.Message); } }
static void Main() { try { QsRetailDataContext qsRetail = new QsRetailDataContext(); WriteToLog("Start export MOLDTELECOM payments"); string[] parts = ConfigurationManager.AppSettings["organizations"].Split(','); int[] organizationList = (from s in parts select int.Parse(s)).ToArray(); string[] orgs = ConfigurationManager.AppSettings["Moldtelecom"].Split(','); int[] moldtelecom = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["MaxDsl"].Split(','); int[] maxdsl = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["Unite"].Split(','); int[] unite = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["UnitePrePay"].Split(','); int[] unitePrePay = (from s in orgs select int.Parse(s)).ToArray(); var qsMovements = from p in qsRetail.Movements where organizationList.Contains(p.OrganizationIDTo) && p.Document.StatusID == 2 && p.IsReceivedTo == false && p.Direction && p.OperationDate >= DateTime.Parse("2012-03-01") && p.Document.TransactionAmount > 0 select p; foreach (var qsMovement in qsMovements) { try { string resp = ""; paymentsWSClient clientService = new paymentsWSClient(); XmlDocument doc = new XmlDocument(); string name = ""; string contract = ""; string tipCont = ""; string searchParam = ""; searchParam = qsMovement.Document.OwnerKey.Length == 8 ? "phone" : "cont"; if (moldtelecom.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "1"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT").InnerText; } else if (maxdsl.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "2"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT").InnerText; } else if (unite.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "3"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT").InnerText; } else if (unitePrePay.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "4"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT").InnerText; } string result = clientService.addPayment( user, password, contract, qsMovement.RealOperationDate.ToString("yyyyMMdd"), double.Parse(qsMovement.Document.TransactionAmount.ToString("0.00")), "1", int.Parse(tipCont), "VICBMD2X"); if (result.Trim().Substring(0,1) == "<") { doc.LoadXml(result); throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } qsMovement.IsReceivedTo = true; qsRetail.SubmitChanges(); WriteToLog(string.Format("MovementID : {0} order_id : {1} : Response : {2} OK ", new object[] { qsMovement.ID.ToString(), qsMovement.Document.OwnerKey, result })); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(string.Format("{0} : {1} : {2}", new object[] { qsMovement.ID.ToString(), qsMovement.Document.OwnerKey, e.Message })); } } WriteToLog("End export MOLDTELECOM payments"); WriteToLog("Start export MOLDTELECOM unpayments"); var qsUnMovements = from p in qsRetail.Movements where organizationList.Contains(p.OrganizationIDTo) && p.Document.StatusID == 3 && p.IsReceivedTo && p.Direction && p.OperationDate >= DateTime.Parse("2012-03-01") && p.Document.TransactionAmount > 0 select p; foreach (var qsUnMovement in qsUnMovements) { try { string resp = ""; paymentsWSClient clientService = new paymentsWSClient(); XmlDocument doc = new XmlDocument(); string name = ""; string contract = ""; string tipCont = ""; string searchParam = ""; searchParam = qsUnMovement.Document.OwnerKey.Length == 8 ? "phone" : "cont"; if (moldtelecom.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "1"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT").InnerText; } else if (maxdsl.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "2"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT").InnerText; } else if (unite.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "3"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT").InnerText; } else if (unitePrePay.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "4"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT").InnerText; } string result = clientService.addPayment( user, password, contract, qsUnMovement.RealOperationDate.ToString("yyyyMMdd"), -double.Parse(qsUnMovement.Document.TransactionAmount.ToString("0.00")), "1", int.Parse(tipCont), "VICBMD2X"); if (result.Trim().Substring(0, 1) == "<") { doc.LoadXml(result); throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } qsUnMovement.IsReceivedTo = false; qsRetail.SubmitChanges(); WriteToLog(string.Format("MovementID : {0} order_id : {1} : Response : {2} OK ", new object[] { qsUnMovement.ID.ToString(), qsUnMovement.Document.OwnerKey, result })); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(string.Format("{0} : {1} : {2}", new object[] { qsUnMovement.ID.ToString(), qsUnMovement.Document.OwnerKey, e.Message })); } } WriteToLog("End export MOLDTELECOM unpayments"); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(e.Message); } }