private static bool IsDBAlive() { Event clsEvent = new Event(); try { clsEvent.AddEvent("Checking connections to server."); if (IPAddress.IsOpen(AceSoft.RetailPlus.DBConnection.ServerIP(), DBConnection.DBPort()) == false) { clsEvent.AddEvent("Cannot connect to server please check."); return(false); } clsEvent.AddEvent("Checking connections to database."); Data.Database clsDatabase = new Data.Database(); bool boIsDBAlive = clsDatabase.IsAlive(); clsEvent.AddEventLn("Done! Connected to " + clsDatabase.Connection.ConnectionString, false); clsEvent.AddEventLn("Updating version to " + Application.ProductVersion, true); Data.Terminal clsTerminal = new Data.Terminal(clsDatabase.Connection, clsDatabase.Transaction); clsTerminal.UpdateFEVersion(Constants.TerminalBranchID, CompanyDetails.TerminalNo, Application.ProductVersion); clsDatabase.CommitAndDispose(); return(boIsDBAlive); } catch (Exception ex) { clsEvent.AddErrorEventLn(ex); return(false); } }
static void Main(string[] args) { WriteProcessToMonitor("Starting RetailPlus Credit Biller tool..."); // check if it's already running if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) { WriteProcessToMonitor(" already running. Press any key to continue..."); Console.ReadLine(); return; } WriteProcessToMonitor(" ok"); back: try { WriteProcessToMonitor("Checking process start time..."); DateTime _CreditBillerProcessStartTime = DateTime.TryParse(DateTime.Now.ToString("yyyy-MM-dd") + " " + System.Configuration.ConfigurationManager.AppSettings["ProcessStartTime"].ToString(), out _CreditBillerProcessStartTime) ? _CreditBillerProcessStartTime : DateTime.MinValue; if (DateTime.Now < _CreditBillerProcessStartTime) { WriteProcessToMonitor(" cannot process will process next day-starttime:" + _CreditBillerProcessStartTime.ToString("hh:mm tt")); Wait(); goto back; } WriteProcessToMonitor("Checking process end time..."); DateTime _CreditBillerProcessEndTime = DateTime.TryParse(DateTime.Now.ToString("yyyy-MM-dd") + " " + System.Configuration.ConfigurationManager.AppSettings["ProcessEndTime"].ToString(), out _CreditBillerProcessEndTime) ? _CreditBillerProcessEndTime : DateTime.MinValue; if (DateTime.Now > _CreditBillerProcessEndTime) { WriteProcessToMonitor(" cannot process will process next day-endtime:" + _CreditBillerProcessEndTime.ToString("hh:mm tt")); Wait(); goto back; } WriteProcessToMonitor("Checking connections to server."); if (IPAddress.IsOpen(AceSoft.RetailPlus.DBConnection.ServerIP(), DBConnection.DBPort()) == false) { WriteProcessToMonitor(" cannot connect to server please check."); Wait(); goto exit; } WriteProcessToMonitor(" ok"); WriteProcessToMonitor("Checking connections to database."); Data.Database clsDatabase = new Data.Database(); mConnection = clsDatabase.Connection; mTransaction = clsDatabase.Transaction; try { bool boIsDBAlive = clsDatabase.IsAlive(); WriteProcessToMonitor(" connected to '" + clsDatabase.Connection.ConnectionString.Split(';')[0].ToString().Replace("Data Source=", "") + "'"); } catch (Exception ex) { WriteProcessToMonitor(" ERROR connecting to database. Exception: " + ex.ToString()); clsDatabase.CommitAndDispose(); return; } WriteProcessToMonitor("Checking credit billings with guarantor to process..."); WriteProcessToMonitor(" done checking..."); Data.CardType clsCardType = new Data.CardType(mConnection, mTransaction); mConnection = clsCardType.Connection; mTransaction = clsCardType.Transaction; System.Data.DataTable dt = clsCardType.ListAsDataTable(new Data.CardTypeDetails() { CreditCardType = CreditCardTypes.Internal, CheckGuarantor = true, WithGuarantor = true }); clsCardType.CommitAndDispose(); clsDatabase.CommitAndDispose(); foreach (System.Data.DataRow dr in dt.Rows) { WriteProcessToMonitor("Processing " + dr["CardTypeName"].ToString() + "..."); ProcessCreditBillWG(dr["CardTypeName"].ToString()); } WriteProcessToMonitor("Checking credit billings to process..."); WriteProcessToMonitor(" done checking..."); // processing of Internal WithOutGuarantor clsCardType = new Data.CardType(mConnection, mTransaction); mConnection = clsCardType.Connection; mTransaction = clsCardType.Transaction; dt = clsCardType.ListAsDataTable(new Data.CardTypeDetails() { CreditCardType = CreditCardTypes.Internal, CheckGuarantor = true, WithGuarantor = false }); clsCardType.CommitAndDispose(); clsDatabase.CommitAndDispose(); foreach (System.Data.DataRow dr in dt.Rows) { WriteProcessToMonitor("Processing " + dr["CardTypeName"].ToString() + "..."); ProcessCreditBill(dr["CardTypeName"].ToString()); } // redo this checking before processing creditbill with Guarantor WriteProcessToMonitor("Checking process start time..."); if (DateTime.Now < _CreditBillerProcessStartTime) { WriteProcessToMonitor(" cannot process will process next day-starttime:" + _CreditBillerProcessStartTime.ToString("hh:mm tt")); goto exit; } WriteProcessToMonitor("Checking process end time..."); if (DateTime.Now > _CreditBillerProcessEndTime) { WriteProcessToMonitor(" cannot process will process next day-endtime:" + _CreditBillerProcessEndTime.ToString("hh:mm tt")); goto exit; } // end-redo this checking before processing creditbill with Guarantor Wait(); goto back; exit: WriteProcessToMonitor("Sytem terminated."); Console.ReadLine(); } catch (Exception ex) { WriteProcessToMonitor("PLEASE CALL RETAILPLUS IMMEDIATELY... error:" + ex.ToString()); goto back; } }
private static bool IsDBAlive() { Event clsEvent = new Event(); try { clsEvent.AddEvent("Checking connections to server."); if (IPAddress.IsOpen(AceSoft.RetailPlus.DBConnection.ServerIP(), DBConnection.DBPort()) == false) { clsEvent.AddEvent("Cannot connect to server please check."); return false; } clsEvent.AddEvent("Checking connections to database."); Data.Database clsDatabase = new Data.Database(); bool boIsDBAlive = clsDatabase.IsAlive(); clsEvent.AddEventLn("Done! Connected to " + clsDatabase.Connection.ConnectionString, false); clsEvent.AddEventLn("Updating version to " + Application.ProductVersion, true); Data.Terminal clsTerminal = new Data.Terminal(clsDatabase.Connection, clsDatabase.Transaction); clsTerminal.UpdateFEVersion(Constants.TerminalBranchID, CompanyDetails.TerminalNo, Application.ProductVersion); clsDatabase.CommitAndDispose(); return boIsDBAlive; } catch (Exception ex) { clsEvent.AddErrorEventLn(ex); return false; } }
static void Main(string[] args) { try { WriteProcessToMonitor("Starting RetailPlus monitoring tool..."); // check if it's already running if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) { WriteProcessToMonitor(" already running. not ok"); return; } WriteProcessToMonitor(" ok"); Data.Database clsDatabase = new Data.Database(); back: WriteProcessToMonitor("Checking connections to server."); if (IPAddress.IsOpen(AceSoft.RetailPlus.DBConnection.ServerIP(), DBConnection.DBPort()) == false) { WriteProcessToMonitor(" cannot connect to server please check."); goto exit; } WriteProcessToMonitor(" ok"); WriteProcessToMonitor("Checking connections to database."); clsDatabase.GetConnection(username: "******", password: "******"); try { bool boIsDBAlive = clsDatabase.IsAlive(); WriteProcessToMonitor(" connected to '" + clsDatabase.Connection.ConnectionString.Split(';')[0].ToString().Replace("Data Source=", "") + "'"); } catch (Exception ex) { WriteProcessToMonitor(" ERROR connecting to database. Exception: " + ex.ToString()); } #region Timed-Out Process WriteProcessToMonitor("Checking timed-out process."); System.Data.DataTable dtProcessList = clsDatabase.getProcessList(); foreach (DataRow dr in dtProcessList.Rows) { int iID = int.Parse(dr["ID"].ToString()); string strHost = dr["Host"].ToString(); string strDB = dr["db"].ToString(); int iTime = int.Parse(dr["Time"].ToString()); string strInfo = dr["Info"].ToString(); if (strInfo.ToUpper() != "SHOW PROCESSLIST" || strDB == "pos") { WriteProcessToMonitor(" id:" + iID.ToString() + " host:" + strHost + " Time:" + iTime.ToString() + " Info:" + strInfo); if (iTime > Constants.C_DEFAULT_MYSQL_PROCESS_TIMEOUT && strDB == "pos") { WriteProcessToMonitor(" status not ok... killing process id: " + iID.ToString()); clsDatabase.killProcess(iID); WriteProcessToMonitor(" done."); } else if (iTime > 16 && string.IsNullOrEmpty(strInfo)) { WriteProcessToMonitor(" status idle... killing process id: " + iID.ToString()); clsDatabase.killProcess(iID); WriteProcessToMonitor(" done."); } else if (strInfo.Contains("INSERT INTO tblTransactions") && iTime >= 8) { WriteProcessToMonitor(" status not ok... flushing table tblTransactions...process id: " + iID.ToString()); clsDatabase.FlushTable("tblTransactions"); WriteProcessToMonitor(" done."); } else if (strInfo.Contains("UPDATE tblTerminalReport") && iTime >= 8) { WriteProcessToMonitor(" status not ok... flushing table tblTerminalReport...process id: " + iID.ToString()); clsDatabase.FlushTable("tblTerminalReport"); WriteProcessToMonitor(" done."); } else { WriteProcessToMonitor(" status ok"); } } } clsDatabase.CommitAndDispose(); // audit //clsDatabase = new Data.Database(clsDatabase.Connection, clsDatabase.Transaction); clsDatabase.GetConnection(username: "******", password: "******"); try { bool boIsDBAlive = clsDatabase.IsAlive(); WriteProcessToMonitor(" connected to '" + clsDatabase.Connection.ConnectionString.Split(';')[0].ToString().Replace("Data Source=", "") + "'"); } catch (Exception ex) { WriteProcessToMonitor(" ERROR connecting to database. Exception: " + ex.ToString()); } WriteProcessToMonitor("Checking Audit timed-out process."); dtProcessList = clsDatabase.getProcessList(); foreach (DataRow dr in dtProcessList.Rows) { int iID = int.Parse(dr["ID"].ToString()); string strHost = dr["Host"].ToString(); string strDB = dr["db"].ToString(); int iTime = int.Parse(dr["Time"].ToString()); string strInfo = dr["Info"].ToString(); if (strInfo.ToUpper() != "SHOW PROCESSLIST" || strDB == "pos") { WriteProcessToMonitor(" audit id:" + iID.ToString() + " host:" + strHost + " Time:" + iTime.ToString() + " Info:" + strInfo); if (iTime > Constants.C_DEFAULT_MYSQL_PROCESS_TIMEOUT && strDB == "pos") { WriteProcessToMonitor(" status not ok... killing process id: " + iID.ToString()); clsDatabase.killProcess(iID); WriteProcessToMonitor(" done."); } else { WriteProcessToMonitor(" status ok"); } } } clsDatabase.CommitAndDispose(); WriteProcessToMonitor(" done checking..."); #endregion string strSyncFunction = ""; try { strSyncFunction = System.Configuration.ConfigurationManager.AppSettings["SyncFunction"].ToString(); } catch { } if (strSyncFunction.ToLower().Trim() == "export") { #region Export Products //clsDatabase = new Data.Database(clsDatabase.Connection, clsDatabase.Transaction); clsDatabase.GetConnection(username: "******", password: "******"); Data.SysConfig clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); DateTime dteLastSyncDateTime = clsSysConfig.get_ProdLastSyncDateTime(); DateTime dteLastSyncDateTimeTo = dteLastSyncDateTime.AddMinutes(clsSysConfig.get_ProdSyncInterval()); if (dteLastSyncDateTimeTo <= DateTime.Now) { Data.DBSync clsDBSync = new Data.DBSync(clsDatabase.Connection, clsDatabase.Transaction); System.Data.DataTable stSyncItems = clsDBSync.ListAsDataTable("tblProducts", dteLastSyncDateTime, dteLastSyncDateTimeTo); if (stSyncItems.Rows.Count > 0) { string xmlFileName = @"C:\RetailPlus\RetailPlus\RetailPlus\temp\uploaded\prodsync\prod_" + dteLastSyncDateTime.ToString("yyyyMMddHHmmss") + ".xml"; if (!System.IO.File.Exists(xmlFileName)) { XmlTextWriter writer = new XmlTextWriter(xmlFileName, System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteComment("This file represents the updated products."); writer.WriteStartElement("Header"); writer.WriteAttributeString("TableName", stSyncItems.TableName); writer.WriteAttributeString("LastSyncDateTime", dteLastSyncDateTime.ToString("yyyy-MM-dd HH:mm:ss")); writer.WriteAttributeString("LastSyncDateTimeTo", dteLastSyncDateTimeTo.ToString("yyyy-MM-dd HH:mm:ss")); foreach (DataRow dr in stSyncItems.Rows) { writer.WriteStartElement("Details"); foreach (DataColumn dc in dr.Table.Columns) { if (dc.DataType == System.Type.GetType("System.DateTime")) writer.WriteAttributeString(dc.ColumnName, DateTime.Parse(dr[dc.ColumnName].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); else writer.WriteAttributeString(dc.ColumnName, dr[dc.ColumnName].ToString()); } writer.WriteEndElement(); } writer.WriteEndElement(); //Write the XML to file and close the writer writer.Flush(); writer.Close(); } } clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); clsSysConfig.Save(new Data.SysConfigDetails() { ConfigName = "ProdLastSyncDateTime", ConfigValue = dteLastSyncDateTimeTo.ToString("yyyy-MM-dd HH:mm:ss"), Category = "Sync" }); } clsDatabase.CommitAndDispose(); #endregion } else if (strSyncFunction.ToLower().Trim() == "import") { #region Import Products XmlTextReader xmlReader = new XmlTextReader(@"C:\RetailPlus\RetailPlus\RetailPlus\temp\uploaded\prodsync\prod_20150629183000.xml"); xmlReader.WhitespaceHandling = WhitespaceHandling.None; ////clsDatabase = new Data.Database(clsDatabase.Connection, clsDatabase.Transaction); clsDatabase.GetConnection(DBName: "poseamirror", username: "******", password: "******"); clsDatabase.SetForeignKey(false); Data.SysConfig clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); DateTime dteLastSyncDateTime = clsSysConfig.get_ProdLastSyncDateTime(); DateTime dteLastSyncDateTimeTo = dteLastSyncDateTime.AddMinutes(clsSysConfig.get_ProdSyncInterval()); Data.Products clsProducts = new Data.Products(clsDatabase.Connection, clsDatabase.Transaction); Data.ProductDetails clsProductDetails = new Data.ProductDetails(); string strTableName = ""; DateTime dteXmlLastSyncDateTime = Constants.C_DATE_MIN_VALUE; DateTime dteXmlLastSyncDateTimeTo = Constants.C_DATE_MIN_VALUE; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (xmlReader.Name == "Header") { strTableName = xmlReader.GetAttribute("TableName").ToString(); dteXmlLastSyncDateTime = DateTime.TryParse(xmlReader.GetAttribute("LastSyncDateTime").ToString(), out dteXmlLastSyncDateTime) ? dteXmlLastSyncDateTime : Constants.C_DATE_MIN_VALUE; dteXmlLastSyncDateTimeTo = DateTime.TryParse(xmlReader.GetAttribute("LastSyncDateTimeTo").ToString(), out dteXmlLastSyncDateTimeTo) ? dteXmlLastSyncDateTimeTo : Constants.C_DATE_MIN_VALUE; if (dteLastSyncDateTime >= dteXmlLastSyncDateTime) break; } else if (strTableName == "tblProducts" && xmlReader.Name == "Details") { clsProductDetails = Data.DBSync.setSyncProductDetails(xmlReader); clsProducts.Save(clsProductDetails); } break; } } if (dteLastSyncDateTime < dteXmlLastSyncDateTime) { clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); clsSysConfig.Save(new Data.SysConfigDetails() { ConfigName = "ProdLastSyncDateTime", ConfigValue = dteXmlLastSyncDateTimeTo.ToString("yyyy-MM-dd HH:mm:ss"), Category = "Sync" }); } clsDatabase.SetForeignKey(true); clsDatabase.CommitAndDispose(); #endregion } WriteProcessToMonitor("Waiting for next process..."); System.Threading.Thread.Sleep(20000); goto back; exit: WriteProcessToMonitor("Sytem terminated."); } catch (Exception ex) { WriteProcessToMonitor("PLEASE CALL RETAILPLUS IMMEDIATELY... error:" + ex.ToString()); } }
static void Main(string[] args) { try { WriteProcessToMonitor("Starting RetailPlus monitoring tool..."); // check if it's already running if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) { WriteProcessToMonitor(" already running. not ok"); return; } WriteProcessToMonitor(" ok"); Data.Database clsDatabase = new Data.Database(); back: WriteProcessToMonitor("Checking connections to server."); if (IPAddress.IsOpen(AceSoft.RetailPlus.DBConnection.ServerIP(), DBConnection.DBPort()) == false) { WriteProcessToMonitor(" cannot connect to server please check."); goto exit; } WriteProcessToMonitor(" ok"); WriteProcessToMonitor("Checking connections to database."); clsDatabase.GetConnection(username: "******", password: "******"); try { bool boIsDBAlive = clsDatabase.IsAlive(); WriteProcessToMonitor(" connected to '" + clsDatabase.Connection.ConnectionString.Split(';')[0].ToString().Replace("Data Source=", "") + "'"); } catch (Exception ex) { WriteProcessToMonitor(" ERROR connecting to database. Exception: " + ex.ToString()); } #region Timed-Out Process WriteProcessToMonitor("Checking timed-out process."); System.Data.DataTable dtProcessList = clsDatabase.getProcessList(); foreach (DataRow dr in dtProcessList.Rows) { int iID = int.Parse(dr["ID"].ToString()); string strHost = dr["Host"].ToString(); string strDB = dr["db"].ToString(); int iTime = int.Parse(dr["Time"].ToString()); string strInfo = dr["Info"].ToString(); if (strInfo.ToUpper() != "SHOW PROCESSLIST" || strDB == "pos") { WriteProcessToMonitor(" id:" + iID.ToString() + " host:" + strHost + " Time:" + iTime.ToString() + " Info:" + strInfo); if (iTime > Constants.C_DEFAULT_MYSQL_PROCESS_TIMEOUT && strDB == "pos") { WriteProcessToMonitor(" status not ok... killing process id: " + iID.ToString()); clsDatabase.killProcess(iID); WriteProcessToMonitor(" done."); } else if (iTime > 16 && string.IsNullOrEmpty(strInfo)) { WriteProcessToMonitor(" status idle... killing process id: " + iID.ToString()); clsDatabase.killProcess(iID); WriteProcessToMonitor(" done."); } else if (strInfo.Contains("INSERT INTO tblTransactions") && iTime >= 8) { WriteProcessToMonitor(" status not ok... flushing table tblTransactions...process id: " + iID.ToString()); clsDatabase.FlushTable("tblTransactions"); WriteProcessToMonitor(" done."); } else if (strInfo.Contains("UPDATE tblTerminalReport") && iTime >= 8) { WriteProcessToMonitor(" status not ok... flushing table tblTerminalReport...process id: " + iID.ToString()); clsDatabase.FlushTable("tblTerminalReport"); WriteProcessToMonitor(" done."); } else { WriteProcessToMonitor(" status ok"); } } } clsDatabase.CommitAndDispose(); // audit //clsDatabase = new Data.Database(clsDatabase.Connection, clsDatabase.Transaction); clsDatabase.GetConnection(username: "******", password: "******"); try { bool boIsDBAlive = clsDatabase.IsAlive(); WriteProcessToMonitor(" connected to '" + clsDatabase.Connection.ConnectionString.Split(';')[0].ToString().Replace("Data Source=", "") + "'"); } catch (Exception ex) { WriteProcessToMonitor(" ERROR connecting to database. Exception: " + ex.ToString()); } WriteProcessToMonitor("Checking Audit timed-out process."); dtProcessList = clsDatabase.getProcessList(); foreach (DataRow dr in dtProcessList.Rows) { int iID = int.Parse(dr["ID"].ToString()); string strHost = dr["Host"].ToString(); string strDB = dr["db"].ToString(); int iTime = int.Parse(dr["Time"].ToString()); string strInfo = dr["Info"].ToString(); if (strInfo.ToUpper() != "SHOW PROCESSLIST" || strDB == "pos") { WriteProcessToMonitor(" audit id:" + iID.ToString() + " host:" + strHost + " Time:" + iTime.ToString() + " Info:" + strInfo); if (iTime > Constants.C_DEFAULT_MYSQL_PROCESS_TIMEOUT && strDB == "pos") { WriteProcessToMonitor(" status not ok... killing process id: " + iID.ToString()); clsDatabase.killProcess(iID); WriteProcessToMonitor(" done."); } else { WriteProcessToMonitor(" status ok"); } } } clsDatabase.CommitAndDispose(); WriteProcessToMonitor(" done checking..."); #endregion string strSyncFunction = ""; try { strSyncFunction = System.Configuration.ConfigurationManager.AppSettings["SyncFunction"].ToString(); } catch { } if (strSyncFunction.ToLower().Trim() == "export") { #region Export Products //clsDatabase = new Data.Database(clsDatabase.Connection, clsDatabase.Transaction); clsDatabase.GetConnection(username: "******", password: "******"); Data.SysConfig clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); DateTime dteLastSyncDateTime = clsSysConfig.get_ProdLastSyncDateTime(); DateTime dteLastSyncDateTimeTo = dteLastSyncDateTime.AddMinutes(clsSysConfig.get_ProdSyncInterval()); if (dteLastSyncDateTimeTo <= DateTime.Now) { Data.DBSync clsDBSync = new Data.DBSync(clsDatabase.Connection, clsDatabase.Transaction); System.Data.DataTable stSyncItems = clsDBSync.ListAsDataTable("tblProducts", dteLastSyncDateTime, dteLastSyncDateTimeTo); if (stSyncItems.Rows.Count > 0) { string xmlFileName = @"C:\RetailPlus\RetailPlus\RetailPlus\temp\uploaded\prodsync\prod_" + dteLastSyncDateTime.ToString("yyyyMMddHHmmss") + ".xml"; if (!System.IO.File.Exists(xmlFileName)) { XmlTextWriter writer = new XmlTextWriter(xmlFileName, System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteComment("This file represents the updated products."); writer.WriteStartElement("Header"); writer.WriteAttributeString("TableName", stSyncItems.TableName); writer.WriteAttributeString("LastSyncDateTime", dteLastSyncDateTime.ToString("yyyy-MM-dd HH:mm:ss")); writer.WriteAttributeString("LastSyncDateTimeTo", dteLastSyncDateTimeTo.ToString("yyyy-MM-dd HH:mm:ss")); foreach (DataRow dr in stSyncItems.Rows) { writer.WriteStartElement("Details"); foreach (DataColumn dc in dr.Table.Columns) { if (dc.DataType == System.Type.GetType("System.DateTime")) { writer.WriteAttributeString(dc.ColumnName, DateTime.Parse(dr[dc.ColumnName].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); } else { writer.WriteAttributeString(dc.ColumnName, dr[dc.ColumnName].ToString()); } } writer.WriteEndElement(); } writer.WriteEndElement(); //Write the XML to file and close the writer writer.Flush(); writer.Close(); } } clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); clsSysConfig.Save(new Data.SysConfigDetails() { ConfigName = "ProdLastSyncDateTime", ConfigValue = dteLastSyncDateTimeTo.ToString("yyyy-MM-dd HH:mm:ss"), Category = "Sync" }); } clsDatabase.CommitAndDispose(); #endregion } else if (strSyncFunction.ToLower().Trim() == "import") { #region Import Products XmlTextReader xmlReader = new XmlTextReader(@"C:\RetailPlus\RetailPlus\RetailPlus\temp\uploaded\prodsync\prod_20150629183000.xml"); xmlReader.WhitespaceHandling = WhitespaceHandling.None; ////clsDatabase = new Data.Database(clsDatabase.Connection, clsDatabase.Transaction); clsDatabase.GetConnection(DBName: "poseamirror", username: "******", password: "******"); clsDatabase.SetForeignKey(false); Data.SysConfig clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); DateTime dteLastSyncDateTime = clsSysConfig.get_ProdLastSyncDateTime(); DateTime dteLastSyncDateTimeTo = dteLastSyncDateTime.AddMinutes(clsSysConfig.get_ProdSyncInterval()); Data.Products clsProducts = new Data.Products(clsDatabase.Connection, clsDatabase.Transaction); Data.ProductDetails clsProductDetails = new Data.ProductDetails(); string strTableName = ""; DateTime dteXmlLastSyncDateTime = Constants.C_DATE_MIN_VALUE; DateTime dteXmlLastSyncDateTimeTo = Constants.C_DATE_MIN_VALUE; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (xmlReader.Name == "Header") { strTableName = xmlReader.GetAttribute("TableName").ToString(); dteXmlLastSyncDateTime = DateTime.TryParse(xmlReader.GetAttribute("LastSyncDateTime").ToString(), out dteXmlLastSyncDateTime) ? dteXmlLastSyncDateTime : Constants.C_DATE_MIN_VALUE; dteXmlLastSyncDateTimeTo = DateTime.TryParse(xmlReader.GetAttribute("LastSyncDateTimeTo").ToString(), out dteXmlLastSyncDateTimeTo) ? dteXmlLastSyncDateTimeTo : Constants.C_DATE_MIN_VALUE; if (dteLastSyncDateTime >= dteXmlLastSyncDateTime) { break; } } else if (strTableName == "tblProducts" && xmlReader.Name == "Details") { clsProductDetails = Data.DBSync.setSyncProductDetails(xmlReader); clsProducts.Save(clsProductDetails); } break; } } if (dteLastSyncDateTime < dteXmlLastSyncDateTime) { clsSysConfig = new Data.SysConfig(clsDatabase.Connection, clsDatabase.Transaction); clsSysConfig.Save(new Data.SysConfigDetails() { ConfigName = "ProdLastSyncDateTime", ConfigValue = dteXmlLastSyncDateTimeTo.ToString("yyyy-MM-dd HH:mm:ss"), Category = "Sync" }); } clsDatabase.SetForeignKey(true); clsDatabase.CommitAndDispose(); #endregion } WriteProcessToMonitor("Waiting for next process..."); System.Threading.Thread.Sleep(20000); goto back; exit: WriteProcessToMonitor("Sytem terminated."); } catch (Exception ex) { WriteProcessToMonitor("PLEASE CALL RETAILPLUS IMMEDIATELY... error:" + ex.ToString()); } }