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); } }