private bool CheckFileUpload(string fileName, string serverIP) { bool status = false; bool result = false; string checkFolderName = @"\\" + serverIP; //Connecting share folder. try { status = ShareFolderConnect.connectState(checkFolderName, "sunpark", "Tdxh638*"); } catch (Exception e) { LogClass.WriteLog($"Can Not Connect To Server {serverIP}" + e.ToString()); AlarmTxt($"Can Not Connect To Server {serverIP}"); return(result); } LogClass.WriteLog(checkFolderName + " connected Ok"); string FileName = checkFolderName + @"\log\M" + DateTime.Now.ToString("yyyyMMdd") + ".log"; LogClass.WriteLog(FileName); if (status) { try { bool IsUpload = false; // 读取文件的源路径及其读取流 StreamReader srReadFile = new StreamReader(FileName); // 读取流直至文件末尾结束 while (!srReadFile.EndOfStream) { string strReadLine = srReadFile.ReadLine(); //读取每行数据 if (strReadLine.Contains(fileName)) { if (strReadLine.Contains("successfully")) { IsUpload = true; break; } } } if (IsUpload) { result = true; } // 关闭读取流文件 srReadFile.Close(); return(result); } catch (Exception e) { LogClass.WriteLog("Fail To Read FileName " + e.ToString()); return(result); } } try { throw new NotImplementedException(); } catch (NotImplementedException exece) { LogClass.WriteLog("NotImplementedException: " + exece.ToString()); return(result); } }
private void ReadDataFromPMS() { SettleFileBatch.Clear(); string constr_server = "Data Source=172.16.1.89;uid=secure;pwd=weishenme;database=NetsSettlementAudit"; DateTime dt = DateTime.Now; string start_time = dt.ToString("yyyy-MM-dd 00:00:00"); string end_time = dt.AddDays(1).ToString("yyyy-MM-dd 00:00:00"); string collection_date = dt.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"); string P_date = DateTime.Now.AddDays(-1).ToString("yyyyMMdd"); foreach (KeyValuePair <string, string> kv in carparklist) { LogClass.WriteLog($"=========={kv.Key}=========="); if (!((StoredProcedureSpProcessConsolidated(kv.Key, kv.Value, P_date, P_date)) && (StoredProcedureSjAddCashCardCollection(kv.Key, kv.Value, P_date, P_date)) && (StoredProcedureSjAddLTACollection(kv.Key, kv.Value, P_date, P_date)))) { continue; } string constr = $"Data Source={kv.Value};uid=sa;pwd=yzhh2007;database={kv.Key}"; string cmd = @"SELECT * FROM [dbo].[settle_file_history] where settle_date BETWEEN @start_time and @end_time and station_id='ALL'; SELECT * FROM [dbo].[daily_cashcard_collection] where trans_date=@collection_date; SELECT value FROM [dbo].[parameter_mst] where name='CHUIP'; SELECT * FROM [dbo].[daily_lta_collection] where trans_date=@collection_date;"; DataSet ds = null; string[] str = kv.Value.Split('.'); string ipgroup = $"{str[0]}.{str[1]}.{str[2]}"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@start_time", start_time), new SqlParameter("@end_time", end_time), new SqlParameter("@collection_date", collection_date) }; try { ds = SqlHelper.ExecuteDataset(constr, CommandType.Text, cmd, para); LogClass.WriteLog($"{kv.Key} Collected Nets Data."); } catch (SqlException e) { LogClass.WriteLog($"{kv.Key} read db fail,{e.ToString()}"); AlarmTxt($"{kv.Key} Fail To Collect Nets File Details,Please Check PMS Connection."); continue; } if (ds == null) { LogClass.WriteLog($"{kv.Key} dataset is null"); AlarmTxt($"{kv.Key} Dataset Is Null"); continue; } try { //Update LTA settlement amount. if ((ds != null) && (ds.Tables[3].Rows.Count > 0)) { try { double conso_amt = Convert.ToDouble(ds.Tables[3].Rows[0]["conso_amt"].ToString()); double settle_amt = Convert.ToDouble(ds.Tables[3].Rows[0]["settle_amt"].ToString()); //Update CPT amt; string cmd_update_cpt = @"IF EXISTS (SELECT * FROM [dbo].[DailyRevenueSummary] where Trans_date=@Trans_date and carparkID=@carparkID) BEGIN --update Update DailyRevenueSummary set LTA_conso=@LTA_conso,LTA_settle=@LTA_settle,update_date=getdate(),ipgroup=@ipgroup where Trans_date=@Trans_date and carparkID=@carparkID END ELSE BEGIN -- insert Insert INTO DailyRevenueSummary(carparkID,batch,LTA_conso,LTA_settle,Trans_date,update_date,ipgroup)VALUES(@carparkID,@batch,@LTA_conso,@LTA_settle,@Trans_date,getdate(),@ipgroup) END"; SqlParameter[] para_LTA = new SqlParameter[] { new SqlParameter("@carparkID", kv.Key), new SqlParameter("@batch", batchlist[kv.Key]), new SqlParameter("@LTA_conso", conso_amt), new SqlParameter("@LTA_settle", settle_amt), new SqlParameter("@ipgroup", ipgroup), new SqlParameter("@Trans_date", collection_date) }; try { SqlHelper.ExecuteNonQuery(constr_server, CommandType.Text, cmd_update_cpt, para_LTA); LogClass.WriteLog("Insert Data to Server Ok."); } catch (SqlException sqle) { LogClass.WriteLog($"Found Error When Insert To Server. {sqle.ToString()}"); //AlarmTxt($"{kv.Key} Have No CPT File Amount={conso_amt.ToString()} Generated,Please Check."); } } catch (SqlException sqle) { } } else { LogClass.WriteLog($"No Lta data can collect."); } //Collect Settlement File Name. if ((ds != null) && (ds.Tables[0].Rows.Count > 0)) { foreach (DataRow dr_3 in ds.Tables[0].Rows) { string settle_file_path = dr_3["settle_file"].ToString(); //C:\Carpark\Settle\Pack\NETS\2018\T4P080100 string settle_sys = dr_3["settle_sys"].ToString(); // 0 CPT 1 CHU string[] array = settle_file_path.Split('\\'); string file_name = array[6]; switch (settle_sys) { case "0": SettleFileName.Add(file_name, kv.Key + "_CPT"); break; case "1": SettleFileName.Add(file_name, kv.Key + "_CHU"); break; } SettleFileBatch.Add(file_name, batchlist[kv.Key]); } } //Check by daily_cashcard_collection. if ((ds != null) && (ds.Tables[1].Rows.Count > 0)) { string value = ds.Tables[2].Rows[0]["value"].ToString(); LogClass.WriteLog($"CHUIP:{value}"); bool isCHUIPSame = false; if (value.Equals(kv.Key)) { isCHUIPSame = true; } foreach (DataRow dr in ds.Tables[1].Rows) { string trans_type = dr["trans_type"].ToString(); double conso_amt = Convert.ToDouble(dr["conso_amt"].ToString()); double settle_amt = Convert.ToDouble(dr["settle_amt"].ToString()); string trans_date = dr["trans_date"].ToString(); bool flag_cpt = false; bool flag_chu = false; if (trans_type.Equals("1") && (conso_amt > 0)) //1 CPT Consolidated. { //Update CPT amt; string cmd_update_cpt = @"IF EXISTS (SELECT * FROM [dbo].[DailyRevenueSummary] where Trans_date=@Trans_date and carparkID=@carparkID) BEGIN --update Update DailyRevenueSummary set cpt_conso=@cpt_conso,CPT_settle=@CPT_settle,update_date=getdate(),ipgroup=@ipgroup where Trans_date=@Trans_date and carparkID=@carparkID END ELSE BEGIN -- insert Insert INTO DailyRevenueSummary(carparkID,batch,CPT_conso,CPT_settle,Trans_date,update_date,ipgroup)VALUES(@carparkID,@batch,@CPT_conso,@CPT_settle,@Trans_date,getdate(),@ipgroup) END"; SqlParameter[] para_cpt = new SqlParameter[] { new SqlParameter("@carparkID", kv.Key), new SqlParameter("@batch", batchlist[kv.Key]), new SqlParameter("@cpt_conso", conso_amt), new SqlParameter("@CPT_settle", settle_amt), new SqlParameter("@ipgroup", ipgroup), new SqlParameter("@Trans_date", trans_date) }; try { SqlHelper.ExecuteNonQuery(constr_server, CommandType.Text, cmd_update_cpt, para_cpt); LogClass.WriteLog("Insert Data to Server Ok."); } catch (SqlException sqle) { LogClass.WriteLog($"Found Error When Insert To Server. {sqle.ToString()}"); //AlarmTxt($"{kv.Key} Have No CPT File Amount={conso_amt.ToString()} Generated,Please Check."); } if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr_2 in ds.Tables[0].Rows) { string settle_sys = dr_2["settle_sys"].ToString(); string settle_file = dr_2["settle_file"].ToString(); string send_flag = dr_2["send_flag"].ToString(); double total_amt = Convert.ToDouble(dr_2["total_amt"].ToString()); if (settle_sys.Equals("0")) //0 CPT 1 CHU Settled. { flag_cpt = true; if (send_flag.Equals("1")) { //CPT Upload ok. LogClass.WriteLog($"{kv.Key} CPT Upload OK."); } else { //CPT never upload. LogClass.WriteLog($"{kv.Key} CPT {settle_file} Never Upload,Please Check."); AlarmTxt($"{kv.Key} CPT {settle_file} Never Upload,Please Check."); } if (conso_amt == total_amt) { //CPT same amt LogClass.WriteLog($"{kv.Key} CPT Settle Same Amount {conso_amt} As Consolidated."); } else { //CPT diff amt. LogClass.WriteLog($"{kv.Key} CPT Has Different Amount with Consolidated.conso_amt={conso_amt},settle={total_amt}"); //AlarmTxt($"{kv.Key} CPT Has Different Amount with Consolidated.conso_amt={conso_amt},settle={total_amt}"); } } } if (!flag_cpt) { //No CPT file generated. LogClass.WriteLog($"{kv.Key} Have No CPT File Generated,Please Check."); AlarmTxt($"{kv.Key} Have No CPT File Amount={conso_amt.ToString()} Generated,Please Check."); } } } else if (trans_type.Equals("2") && (conso_amt > 0)) //2 CHU Consolidated. { //Update CHU amt; string cmd_update_cpt = @"IF EXISTS (SELECT * FROM [dbo].[DailyRevenueSummary] where Trans_date=@Trans_date and carparkID=@carparkID) BEGIN --update update DailyRevenueSummary set CHU_conso=@CHU_conso,CHU_settle=@CHU_settle,update_date=getdate(),ipgroup=@ipgroup where Trans_date=@Trans_date and carparkID=@carparkID END ELSE BEGIN -- insert Insert INTO DailyRevenueSummary(carparkID,batch,CHU_conso,CHU_settle,Trans_date,update_date,ipgroup)VALUES(@carparkID,@batch,@CHU_conso,@CHU_settle,@Trans_date,getdate(),@ipgroup) END"; SqlParameter[] para_cpt = new SqlParameter[] { new SqlParameter("@carparkID", kv.Key), new SqlParameter("@batch", batchlist[kv.Key]), new SqlParameter("@CHU_conso", conso_amt), new SqlParameter("@CHU_settle", settle_amt), new SqlParameter("@ipgroup", ipgroup), new SqlParameter("@Trans_date", trans_date) }; try { SqlHelper.ExecuteNonQuery(constr_server, CommandType.Text, cmd_update_cpt, para_cpt); LogClass.WriteLog("Insert Data to Server Ok."); } catch (SqlException sqle) { LogClass.WriteLog($"Found Error When Insert To Server. {sqle.ToString()}"); //AlarmTxt($"{kv.Key} Have No CPT File Amount={conso_amt.ToString()} Generated,Please Check."); } if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr_2 in ds.Tables[0].Rows) { string settle_sys = dr_2["settle_sys"].ToString(); string settle_file = dr_2["settle_file"].ToString(); string send_flag = dr_2["send_flag"].ToString(); double total_amt = Convert.ToDouble(dr_2["total_amt"].ToString()); if (settle_sys.Equals("1")) //1 CHU Settled. { flag_chu = true; if (send_flag.Equals("1")) { //CHU upload ok. LogClass.WriteLog($"{kv.Key} CHU Upload OK."); } else { //CHU never upload. LogClass.WriteLog($"{kv.Key} CHU {settle_file} Never Upload,Please Check."); AlarmTxt($"{kv.Key} CHU {settle_file} Never Upload,Please Check."); } if (conso_amt == total_amt) { //CHU same amt LogClass.WriteLog($"{kv.Key} CHU Settle Same Amount {conso_amt} As Consolidated."); } else { //CHU diff amt. LogClass.WriteLog($"{kv.Key} CHU Has Different Amount with Consolidated.conso_amt={conso_amt},settle={total_amt}"); //AlarmTxt($"{kv.Key} CHU Has Different Amount with Consolidated.conso_amt={conso_amt},settle={total_amt}"); } } } } //Update CHU amt; if (!flag_chu) { if (isCHUIPSame) { //No CHU file generated. LogClass.WriteLog($"{kv.Key} Have No CHU File Generated,Please Check."); AlarmTxt($"{kv.Key} Have No CHU File Amount={conso_amt.ToString()} Generated,Please Check."); } else { //CHUIP and PMS not same IP. LogClass.WriteLog($"{kv.Key} CHU File Generated From Other PMS {value}."); } } } } } else { LogClass.WriteLog($"No Nets data can collect."); } } catch (Exception e) { } } }