/// <summary> /// 获取表数据 /// </summary> /// <param name="strSql"></param> /// <returns></returns> public static DataTable GetSelectTable(string strSql) { //数据库连接 ClsDBConnection Conn = GetConn(); DataTable dtResult = Conn.GetSqlResultToDt(strSql); Conn.Dispose(); return(dtResult); }
public bool MailConnect(string p_User, string p_Pass) { //判断系统是否注册此用户 ClsDBConnection m_oDb = new ClsDBConnection(); m_oDb.Open(); string strUserCountSql = "SELECT COUNT(*) FROM TBREGUSERINFO WHERE USER_CODE = '" + p_User + "'"; string strCount = m_oDb.GetSqlResultToStr(strUserCountSql); if (strCount == "0" || strCount == "") { return(false); } //注册验证邮件 bool Result = true; //中油信箱 string strMailSql = "SELECT SYS_VALUE FROM SAP_SYSCONFIG WHERE SYS_CODE = 'MailAddress'"; string strPopServer = m_oDb.GetSqlResultToStr(strMailSql); string strUser = p_User; string strPass = p_Pass; try { //用110端口新建POP3服务器连接 Server = new TcpClient(strPopServer, 110); //初始化 NetStrm = Server.GetStream(); RdStrm = new StreamReader(Server.GetStream()); string strMegage = RdStrm.ReadLine(); Result = CheckMailResult(strMegage); //登录服务器过程 Data = "USER " + strUser + CRLF; szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray()); NetStrm.Write(szData, 0, szData.Length); strMegage = RdStrm.ReadLine(); Result = CheckMailResult(strMegage); Data = "PASS " + strPass + CRLF; szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray()); NetStrm.Write(szData, 0, szData.Length); strMegage = RdStrm.ReadLine(); Result = CheckMailResult(strMegage); } catch (InvalidOperationException err) { Result = false; } m_oDb.Dispose(); return(Result); }
/// <summary> /// 执行语句 /// </summary> /// <param name="p_Sql">SQL语句</param> /// <returns>是否执行成功true执行成功,false失败</returns> public static bool ExecuteSqlToDb(string p_Sql) { bool Result = true; try { //执行更新SQL ClsDBConnection Conn = GetConn(); Conn.ExecuteSql(p_Sql); Conn.Dispose(); } catch (Exception exception) { ClsErrorLogInfo.WriteSqlLog("2", "执行sql发生异常:" + exception, p_Sql); Result = false; } return(Result); }
bool ISAPLoadInterface.SAPLoadData(ClsSAPDataParameter p_para) { bool Result = true; m_Conn = ClsUtility.GetConn(); //暂时注销,正式时根据时间查出数据 //DataTable dtEkkoDate = new DataTable(); //try //{ // string strSqlEkko = "SELECT AEDAT,EBELN FROM EKKO WHERE DLDATE='"+p_para.Sap_AEDAT+"'AND AEDAT like '" ; // dtEkkoDate = m_Conn.GetSqlResultToDt(strSqlEkko); //} //catch (Exception exception) //{ // Result = false; // ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询EKKO表发生异常:\t\n" + exception); // return Result; //} EKKO structEKKO = new EKKO(); DataTable dtEkko = new DataTable(); try { //杜杨ERP2.0 string stedate = p_para.Sap_AEDAT.Substring(0, 6); //查询EKKO数据 //string strSqlEkko = "SELECT * FROM EKKO WHERE BSART='Z012'AND AEDAT like '" + stedate + "%' and EBELN='7000231271' order by AEDAT asc"//单条测试 string strSqlEkko = "SELECT * FROM EKKO WHERE BSART='X009'AND AEDAT like '" + stedate + "%' order by AEDAT asc"; dtEkko = m_Conn.GetSqlResultToDt(strSqlEkko); } catch (Exception exception) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询EKKO表发生异常:\t\n" + exception); return Result; } strBuilder.Length = 0; strBuilder.Append(" Begin "); //开始执行SQL //开始执行SQL foreach (DataRow subRowEkko in dtEkko.Rows) { //赋值EKKO表值 structEKKO.strLOEKZ = subRowEkko["LOEKZ"].ToString(); structEKKO.strAEDAT = subRowEkko["AEDAT"].ToString(); structEKKO.strEBELN = subRowEkko["EBELN"].ToString(); structEKKO.strFRGKE = subRowEkko["FRGKE"].ToString(); structEKKO.strFRGKE = string.IsNullOrEmpty(structEKKO.strFRGKE) ? "0" : structEKKO.strFRGKE; structEKKO.strBUKRS = subRowEkko["BUKRS"].ToString(); structEKKO.strLIFNR = subRowEkko["LIFNR"].ToString(); structEKKO.strERNAM = subRowEkko["ERNAM"].ToString(); //服务商名称 try { structEKKO.strLIFNRMC = m_Conn.GetSqlResultToStr("SELECT NAME1 FROM LFA1 WHERE LIFNR='" + structEKKO.strLIFNR + "'"); } catch (Exception exception1) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询LFA1表发生异常:\t\n" + exception1); return Result; } //甲方单位名称 try { structEKKO.strBUKRSMC = m_Conn.GetSqlResultToStr("SELECT T.BUTXT FROM T001 T WHERE T.BUKRS='" + structEKKO.strBUKRS + "'"); } catch (Exception exception1) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询T001表发生异常:\t\n" + exception1); return Result; } if (string.IsNullOrEmpty(structEKKO.strBUKRSMC)) { continue; } //采购订单创建人员名称 try { structEKKO.strERNAMMC = m_Conn.GetSqlResultToStr("SELECT NAME_LAST FROM USR02 WHERE BNAME='" + structEKKO.strERNAM + "'"); } catch (Exception exception1) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询USR02表发生异常:\t\n" + exception1); return Result; } //采购订单创建人员账号 //EKKO字段FRGKE值为1,获取审批人,为0不获取 if (structEKKO.strFRGKE == "1") { //当查询结果存在多行时,取最近日期的USERNAME //当查询结果存在多行时,取最近时间的USERNAME string strSqlCDHDR = "SELECT T.USERNAME,MAX(T.UDATE) AS UDATE,T.UTIME FROM CDHDR T WHERE T.TCODE='ME29N' AND T.OBJECTID='" + structEKKO.strEBELN + "' GROUP BY T.USERNAME,T.UTIME"; DataTable dtCDHDR = m_Conn.GetSqlResultToDt(strSqlCDHDR); if (dtCDHDR != null && dtCDHDR.Rows.Count > 0) { string str_MaxTime = string.Empty; for (int i = 0; i < dtCDHDR.Rows.Count; i++) { if (i == 0) { structEKKO.strUSERNAME = dtCDHDR.Rows[i]["USERNAME"].ToString(); str_MaxTime = dtCDHDR.Rows[i]["UTIME"].ToString(); continue; } string str_time = dtCDHDR.Rows[i]["UTIME"].ToString(); string[] str_times = str_time.Split(':'); if (str_times.Length < 2) { str_time = "0" + str_time; } if (String.Compare(str_MaxTime, str_time) < 0) { str_MaxTime = str_time; structEKKO.strUSERNAME = dtCDHDR.Rows[i]["USERNAME"].ToString(); } } } //采购订单创建人员名称 if (!string.IsNullOrEmpty(structEKKO.strUSERNAME)) { try { structEKKO.strUSERNAMEMC = m_Conn.GetSqlResultToStr("SELECT NAME_LAST FROM USR02 WHERE BNAME='" + structEKKO.strUSERNAME + "'"); } catch (Exception exception1) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询USR02表发生异常:\t\n" + exception1); return Result; } } } EKPO structEKPO = new EKPO(); DataTable dtEKPO = new DataTable(); try { //查询EKPO未删除的数据 string strSqlEKPO = " SELECT * FROM EKPO WHERE EBELN = '" + structEKKO.strEBELN + "' AND (LOEKZ <>'X' OR LOEKZ IS NULL)"; dtEKPO = m_Conn.GetSqlResultToDt(strSqlEKPO); } catch (Exception exception1) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询EKPO或LFA1表发生异常:\t\n" + exception1); return Result; } foreach (DataRow subRowEKPO in dtEKPO.Rows) { //赋值EKPO表值 structEKPO.strEBELP = subRowEKPO["EBELP"].ToString(); structEKPO.strTXZ01 = subRowEKPO["TXZ01"].ToString().Replace("'", "‘"); structEKPO.strEBELN = subRowEKPO["EBELN"].ToString(); structEKPO.strBRTWR = subRowEKPO["BRTWR"].ToString(); structEKPO.strBRTWR = string.IsNullOrEmpty(structEKPO.strBRTWR) ? "0" : structEKPO.strBRTWR; structEKPO.strBRTWR = (Convert.ToDecimal(structEKPO.strBRTWR) / 10000).ToString("0.00"); structEKPO.strBUKRS = subRowEKPO["BUKRS"].ToString(); structEKPO.strPACKNO = subRowEKPO["PACKNO"].ToString(); //变量 string strSUB_PACKNO; try { //取出 ESLL-SUB_PACKNO strSUB_PACKNO = m_Conn.GetSqlResultToStr("SELECT SUB_PACKNO FROM ESLL WHERE PACKNO='" + structEKPO.strPACKNO + "' AND DEL IS NULL "); } catch (Exception exception2) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询ESLL表发生异常:\t\n" + exception2); return Result; } OTHER structOther = new OTHER(); ESLL structESll = new ESLL(); if (!string.IsNullOrEmpty(strSUB_PACKNO)) { //ESLL structESll = new ESLL(); DataTable dtESLL = new DataTable(); //变量 try { dtESLL = m_Conn.GetSqlResultToDt("SELECT * FROM ESLL WHERE PACKNO='" + strSUB_PACKNO + "' AND DEL IS NULL "); } catch (Exception exception2) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询ESLL表发生异常:\t\n" + exception2); return Result; } if (dtESLL != null && dtESLL.Rows.Count > 0) { foreach (DataRow drESLL in dtESLL.Rows) { structESll.strPACKNO = drESLL["PACKNO"].ToString(); structESll.strINTROW = drESLL["INTROW"].ToString(); structESll.strASNUM = drESLL["SRVPOS"].ToString(); structESll.strKTEXT1 = drESLL["KTEXT1"].ToString(); structESll.strPACKNO = drESLL["PACKNO"].ToString(); structESll.strBRTWR = drESLL["BRTWR"].ToString(); //OTHER structOther = new OTHER(); try { structOther.strZEKKN = m_Conn.GetSqlResultToStr("select t.ZEKKN from ESKL t where t.PACKNO='" + structESll.strPACKNO + "' and t.introw='" + structESll.strINTROW + "'"); } catch (Exception exception2) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询ESKL表发生异常:\t\n" + exception2); return Result; } if (!string.IsNullOrEmpty(structOther.strZEKKN)) { try { structOther.strPSPSPPNR = m_Conn.GetSqlResultToStr("select t.ps_psp_pnr from EKKN t where t.ebeln='" + structEKPO.strEBELN + "' and t.ebelp='" + structEKPO.strEBELP + "' and t.ZEKKN='" + structOther.strZEKKN + "'"); } catch (Exception exception2) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询EKKN表发生异常:\t\n" + exception2); return Result; } if (!string.IsNullOrEmpty(structOther.strPSPSPPNR)) { try { //structOther.strPOSID = m_Conn.GetSqlResultToStr("select t.POSID from PRPS t,EKKN a where trim(t.poski) =trim(a.'" + structOther.strPSPSPPNR + "')"); //structOther.strPOST1 = m_Conn.GetSqlResultToStr("select t.POST1 from PRPS t,EKKN a where trim(t.poski) =trim(a.'" + structOther.strPSPSPPNR + "')"); structOther.strPOSID = m_Conn.GetSqlResultToStr("select t.POSID from PRPS t where POSID ='" + structOther.strPSPSPPNR.Replace("-", "").Replace(".", "").Trim() + "'"); structOther.strPOST1 = m_Conn.GetSqlResultToStr("select t.POST1 from PRPS t where POSID ='" + structOther.strPSPSPPNR.Replace("-", "").Replace(".", "").Trim() + "'"); } catch (Exception exception2) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表过程中查询PRPS表发生异常:\t\n" + exception2); return Result; } } } strBuilder.Append(" DELETE FROM HB_XMFW WHERE XMFW_DDH='" + subRowEkko["EBELN"].ToString() + "' AND XMFW_XMH='" + subRowEKPO["EBELP"].ToString() + "' AND XMFW_MXBH='" + structOther.strZEKKN + "';"); //添加数据 strBuilder.Append(" INSERT INTO HB_XMFW"); strBuilder.Append("(XMFW_ID,XMFW_DATE,XMFW_DDH,XMFW_CJRYBM,XMFW_CJRYMC,XMFW_SPRYBM,XMFW_SPRYMC,XMFW_SP,"); strBuilder.Append("XMFW_DDSC,XMFW_JFDWBM,XMFW_JFDWMC,XMFW_XMH,XMFW_CGFUMC,XMFW_FUSBM,XMFW_FUSMC,XMFW_JE,"); strBuilder.Append("XMFW_MXBH,XMFW_GZBH,XMFW_GZNR,XMFW_WBSBM,XMFW_WBSMC,XMFW_DJ,XMFW_DJJE,XMFW_HT)"); strBuilder.Append(" VALUES("); strBuilder.Append("SQ_XMFW.NEXTVAL,"); strBuilder.Append("'" + p_para.Sap_AEDAT.Substring(0, 6) + "',"); strBuilder.Append("'" + structEKKO.strEBELN + "',"); strBuilder.Append("'" + structEKKO.strERNAM + "',"); strBuilder.Append("'" + structEKKO.strERNAMMC + "',"); strBuilder.Append("'" + structEKKO.strUSERNAME + "',"); strBuilder.Append("'" + structEKKO.strUSERNAMEMC + "',"); strBuilder.Append("'" + structEKKO.strFRGKE + "',"); strBuilder.Append("'" + structEKKO.strLOEKZ + "',"); strBuilder.Append("'" + structEKKO.strBUKRS + "',"); strBuilder.Append("'" + structEKKO.strBUKRSMC + "',"); strBuilder.Append("'" + structEKPO.strEBELP + "',"); strBuilder.Append("'" + structEKPO.strTXZ01 + "',"); strBuilder.Append("'" + structEKKO.strLIFNR + "',"); strBuilder.Append("'" + structEKKO.strLIFNRMC + "',"); strBuilder.Append("'" + structEKPO.strBRTWR + "',"); strBuilder.Append("'" + structOther.strZEKKN + "',"); strBuilder.Append("'" + structESll.strASNUM + "',"); strBuilder.Append("'" + structESll.strKTEXT1 + "',"); strBuilder.Append("'" + structOther.strPOSID + "',"); strBuilder.Append("'" + structOther.strPOST1 + "',"); strBuilder.Append("'" + (string.IsNullOrEmpty(structESll.strBRTWR) ? "0" : (Convert.ToDecimal(structESll.strBRTWR) / 10000).ToString("F2")) + "',"); strBuilder.Append("'" + structESll.strBRTWR + "',"); strBuilder.Append("'" + structEKPO.strBRTWR + "'"); strBuilder.Append(");"); } } } } } strBuilder.Append(" End;"); //SQL完成 try { if (strBuilder.ToString().Length < 14) { return true; } //数据提交 Result = ClsUtility.ExecuteSqlToDb(strBuilder.ToString()); m_Conn.Dispose(); } catch (Exception exception5) { Result = false; ClsErrorLogInfo.WriteSapLog("1", "xmfw", "ALL", p_para.Sap_AEDAT, "插入hb_xmfw表发生异常:" + exception5); } return Result; }