private T GetData <T>(string costCenterCode, string cardid, string sqltype) { if (string.IsNullOrWhiteSpace(cardid)) { return(default(T)); } CCMastFactory ccmf = new CCMastFactory(); // Table CCMast CCMast ccm = ccmf.GetCCMastInfo(costCenterCode); // Table SqlMast SingleField ccObj = new SingleField(); ccObj.code = costCenterCode; List <SingleField> lstCcObj = new List <SingleField>(); lstCcObj.Add(ccObj); SqlMast sm = ccmf.GetSqlMastInfo(lstCcObj, sqltype)[0]; // Sql文 string strSql = string.Format(sm.sqlCommand, cardid); #region TCP if (string.IsNullOrWhiteSpace(ccm.posDBUserName)) { return(NetTcpHelper.GetEntity <T>(ccm.posIp, ccm.posDBName, strSql)); } #endregion #region 连数据 string strConn = string.Format(string.Format(SqlServerHelper.customerAllConn(), ccm.posIp, ccm.posDBName, ccm.posDBUserName, ccm.posDBPassword)); //strConn = "Data Source=192.168.0.97,1433;Initial Catalog=DWPOS;User ID=sa;Password=gladis0083;Persist Security Info=True;Connection Timeout=10"; // 取得卡信息 return(SqlServerHelper.GetEntity <T>(strConn, strSql)); #endregion }
/// <summary> /// 入口 /// </summary> /// <returns></returns> public static string DoTransfer(string transferGuid) { string sresult = ""; try { // 取得需要导入的基本数据 List <WxOrder> lstOrder = GetTransferData(transferGuid); if (lstOrder == null || !lstOrder.Any()) { throw new Exception("没有需要导入的记录"); } /***按成本中心分组***/ var lqOrder = (from order in lstOrder group order by new { costCenterCode = order.costCenterCode }).ToList(); #region 取得导入Sql文集合 & 成本中心主数据集合 List <SingleField> lstCC = lqOrder.Select(q => new SingleField { code = q.Key.costCenterCode }).ToList(); CCMastFactory ccm = new CCMastFactory(); // Sql文集合 List <SqlMast> lstSqlTransfer = ccm.GetSqlMastInfo(lstCC, "InsertPOSRecharge"); // 成本中心主数据集合 List <CCMast> lstCCMast = ccm.GetCCMastInfo(lstCC); #endregion foreach (var gOrder in lqOrder) { sresult += string.Format("成本中心:{0}\r\n", gOrder.Key.costCenterCode); // Sql文 SqlMast sqlObj = lstSqlTransfer.FirstOrDefault(r => string.Format(",{0},", r.costCenterCodes) .Contains(string.Format(",{0},", gOrder.Key.costCenterCode))); // Sql连接相关信息 CCMast ccObj = lstCCMast.FirstOrDefault(r => gOrder.Key.costCenterCode.Equals(r.costCenterCode)); // Data Source={0};Initial Catalog={1};User ID={2};Password={3};Persist Security Info=True;Connection Timeout=10" providerName="System.Data.SqlClient" /> string strConn = string.Format(SqlServerHelper.customerAllConn(), ccObj.posIp, ccObj.posDBName, ccObj.posDBUserName, ccObj.posDBPassword); // 初始化最终Sql文 StringBuilder sbSqlFinal = new StringBuilder(); /***参数设置***/ string[] sArray = sqlObj.sqlParams.Split(','); //int x = 0; foreach (WxOrder wxo in gOrder.ToList()) { sbSqlFinal.AppendFormat(sqlObj.sqlCommand, wxo.GetProperties(sArray)); sbSqlFinal.AppendLine(";"); } if (string.IsNullOrWhiteSpace(sbSqlFinal.ToString())) { continue; } //new System.Threading.Thread(() => //{ int rst = 0; if (string.IsNullOrWhiteSpace(ccObj.posDBUserName)) { rst = NetTcpHelper.Execute(ccObj.posIp, ccObj.posDBName, sbSqlFinal.ToString()); } else { rst = SqlServerHelper.Execute(strConn, sbSqlFinal.ToString()); } //if (rst == 0) return ; Console.WriteLine("成本中心:" + gOrder.Key.costCenterCode + " 记录数:" + rst.ToString() + "条导入成功"); sresult += " 记录数:" + rst.ToString() + "条导入成功\r\n"; rst = SqlServerHelper.Execute(SqlServerHelper.salesorderConn(), GetUpdateSql(transferGuid, gOrder.Key.costCenterCode)); Console.WriteLine("成本中心:" + gOrder.Key.costCenterCode + " 记录数:" + rst.ToString() + "条回写成功"); Console.WriteLine(""); sresult += " 记录数:" + rst.ToString() + "条回写成功\r\n\r\n"; //}).Start(); } return(sresult); } catch (Exception e) { //throw e; sresult += e.Message; } finally { /***删除数据导入标志位***/ SetUpdateGuid(transferGuid, false); } return(sresult); //return result; }