/// <summary> /// 根据供应商编号获取数据源配置信息 /// </summary> /// <param name="SourceCode"></param> /// <returns></returns> public static productsourceConfigModel GetConfigu(string SourceCode) { try { using (SqlConnection conn = new SqlConnection(ClientConnStr)) { conn.Open(); string sqlstr = "select * from productsourceConfig where SourceCode='" + SourceCode + "'"; SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn); DataTable dt = new DataTable(); da.Fill(dt); productsourceConfigModel prosc = new productsourceConfigModel(); if (dt.Rows.Count > 0) { prosc.Id = int.Parse(dt.Rows[0]["Id"].ToString()); prosc.SourceCode = dt.Rows[0]["SourceCode"] == null ? "" : dt.Rows[0]["SourceCode"].ToString(); prosc.SourcesAddress = dt.Rows[0]["SourcesAddress"] == null ? "" : dt.Rows[0]["SourcesAddress"].ToString(); prosc.UserId = dt.Rows[0]["UserId"] == null ? "" : dt.Rows[0]["UserId"].ToString(); prosc.UserPwd = dt.Rows[0]["UserPwd"] == null ? "" : dt.Rows[0]["UserPwd"].ToString(); prosc.DataSources = dt.Rows[0]["DataSources"] == null ? "" : dt.Rows[0]["DataSources"].ToString(); prosc.DataSourcesLevel = dt.Rows[0]["DataSourcesLevel"] == null ? "" : dt.Rows[0]["DataSourcesLevel"].ToString(); prosc.TimeStart = dt.Rows[0]["TimeStart"] == null ? 0 : int.Parse(dt.Rows[0]["TimeStart"].ToString()) * 1000 * 60; prosc.Def1 = dt.Rows[0]["Def1"] == null ? "" : dt.Rows[0]["Def1"].ToString(); prosc.Def2 = dt.Rows[0]["Def2"] == null ? "" : dt.Rows[0]["Def2"].ToString(); prosc.Def3 = dt.Rows[0]["Def3"] == null ? "" : dt.Rows[0]["Def3"].ToString(); prosc.Def4 = dt.Rows[0]["Def4"] == null ? "" : dt.Rows[0]["Def4"].ToString(); prosc.Def5 = dt.Rows[0]["Def5"] == null ? "" : dt.Rows[0]["Def5"].ToString(); return(prosc); } return(prosc); } } catch (Exception ex) { return(null); } }
static void Main(string[] args)// { //string[] args = new string[2]; //args[0] = "1"; //args[1] = "true"; Console.WriteLine("本地数据库:" + ClientConnStr); #region 1.当用户第一次请求查询,连接数据库,获取远程服务器配置信息 if (IsFirstStart) { IsFirstStart = false; if (args.Length > 0 && args[0] != null) { //1.1获取源数据数据库配置信息 prosc = productsourcestockDal.GetConfigu(args[0]); if (prosc != null) { Console.WriteLine("获取数据数据源信息成功!" + (bool.Parse(args[1]) ? "更新一次" : "更新多次")); } else { Console.WriteLine("获取数据数据源信息失败!"); return; } productsourcestockDal prodal = new productsourcestockDal(); Exception es; //1.2判断远程连接是否成功 bool IsCon = prodal.IsRemoteCon(prosc.SourcesAddress, prosc.DataSources, prosc.UserId, prosc.UserPwd, out es); if (IsCon) { Console.WriteLine("数据库连接测试成功!"); SleepTime = prosc.TimeStart;//3600000毫秒,一小时自动更新一次 Console.WriteLine("数据源:server=" + prosc.SourcesAddress + ";database=" + prosc.DataSources + ";uid=" + prosc.UserId + ";pwd=" + prosc.UserPwd); } else { Console.WriteLine("数据库连接测试失败!失败原因:" + es.Message); } } else { Console.WriteLine("获取数据源信息失败!"); return; } } #endregion //2.是否为单次更新 IsRepetitionUpdate = bool.Parse(args[1]); //3.修改控制台标题 Console.Title = "更新数据库原始数据信息表" + prosc.SourcesAddress + ((args[1] == "true") ? " Once" : " 多次更新"); //4.获取当前供应商下为第几次更新数据 GetSourceRenewIndex(); Console.WriteLine("当前数据源操作下第" + SourceRenewIndex + "次更新数据中...请勿关闭!"); //5.开始更新本地数据库 Run(); //6.当第5步更新完毕之后,到错误日志表查询更新错误的记录 #region MyRegion while (true) { if (threadCount == 0 && !IsDelete) { Thread thread = new Thread(NewRun); thread.IsBackground = false; // thread.Start(); thread.Join(); //等待上面线程执行完毕 Console.WriteLine("结束时间:" + DateTime.Now); productsourcestockDal prostds; if (prosc != null) { prostds = new productsourcestockDal(prosc.SourcesAddress, prosc.DataSources, prosc.UserId, prosc.UserPwd, SourceRenewIndex, SourceCode); } else { prostds = new productsourcestockDal(SourceCode, SourceRenewIndex); } prostds.AddErrorlog("第" + SourceRenewIndex + "次更结束", SourceCode, SourceRenewIndex, true);//本次更新添加结束时间 count = 0; if (!IsRepetitionUpdate) { Thread.Sleep(1000); // Thread.Sleep(SleepTime);暂停一秒 Main(args); //args } return; } } #endregion }