private void GetNotificationData(Int64 ID) { ENT.ResponseHeatReport objResponse = new ENT.ResponseHeatReport(); List <ENT.HeatStartStopReportApi> lstResult = new List <ENT.HeatStartStopReportApi>(); lstResult = new DAL.HeatStartStopReport().GetHeatStartStopReportByDate(DateTime.Now.ToString("dd-MMM-yyyy"), ID); if (lstResult.Count > 0) { // heat timming data objResponse.ReportName = "HeatReport"; objResponse.PowerOn = Convert.ToString(lstResult[0].StartDataTime); objResponse.SuperHeat = Convert.ToString(lstResult[0].StartDataTime); objResponse.HeatTapped = Convert.ToString(lstResult[0].EndDataTime); objResponse.TapToTapHrsMin = Convert.ToString(lstResult[0].HrsMin); // heat unit consumption data objResponse.KwhrAtStart = Convert.ToString(lstResult[0].DataValue); objResponse.KwhrAtEnd = Convert.ToString(lstResult[0].DataValue2); objResponse.TotalKwhr = Convert.ToString(lstResult[0].UnitDifference); objResponse.KwhrHeat = Convert.ToString(lstResult[0].UnitDifference * 10); // create json for send data to mobile app string jsonNotification = Newtonsoft.Json.JsonConvert.SerializeObject(objResponse); ENT.HeatStartStopReport objENT = new ENT.HeatStartStopReport(); // here, call the function for send data from local to live database string result = SendHeatStartStopReportData(objENT, jsonNotification); } }
public bool UpdateHeatStartStopReport(ENT.HeatStartStopReport objENT) { bool row = false; try { sqlCMD = new SqlCommand(); sqlCMD.CommandText = "InsertUpdateDeleteHeatStartStopReport"; sqlCMD.Parameters.AddWithValue("@ID", objENT.ID); sqlCMD.Parameters.AddWithValue("@fur_name", objENT.fur_name); sqlCMD.Parameters.AddWithValue("@fur_no", objENT.fur_no); sqlCMD.Parameters.AddWithValue("@fur_status_stop", objENT.fur_status_stop); sqlCMD.Parameters.AddWithValue("@fur_status_start", objENT.fur_status_start); sqlCMD.Parameters.AddWithValue("@fur_open_time", objENT.fur_open_time); sqlCMD.Parameters.AddWithValue("@fur_close_time", objENT.fur_close_time); sqlCMD.Parameters.AddWithValue("@LineCountEnd", objENT.LineCountEnd); sqlCMD.Parameters.AddWithValue("@EndDataTime", objENT.EndDataTime); sqlCMD.Parameters.AddWithValue("@DataValue", objENT.DataValue); sqlCMD.Parameters.AddWithValue("@isupdated", objENT.isupdated); sqlCMD.Parameters.AddWithValue("@Mode", objENT.Mode); row = objCRUD.InsertUpdateDelete(sqlCMD); } catch (Exception ex) { throw ex; } return(row); }
public bool InsertHeatStartStopReport(ENT.HeatStartStopReport objENT) { bool row = false; try { sqlCMD = new SqlCommand(); sqlCMD.CommandText = "InsertUpdateDeleteHeatStartStopReport"; sqlCMD.Parameters.AddWithValue("@ID", objENT.ID); sqlCMD.Parameters.AddWithValue("@LineCountStart", objENT.LineCountStart); sqlCMD.Parameters.AddWithValue("@LineCountEnd", objENT.LineCountEnd); sqlCMD.Parameters.AddWithValue("@StartDataTime", objENT.StartDataTime); sqlCMD.Parameters.AddWithValue("@EndDataTime", objENT.EndDataTime); sqlCMD.Parameters.AddWithValue("@DataValue", objENT.DataValue); sqlCMD.Parameters.AddWithValue("@DataValue2", objENT.DataValue2); sqlCMD.Parameters.AddWithValue("@FileName", objENT.FileName); sqlCMD.Parameters.AddWithValue("@EntryDate", objENT.EntryDate); sqlCMD.Parameters.AddWithValue("@isupdated", objENT.isupdated); sqlCMD.Parameters.AddWithValue("@Mode", objENT.Mode); row = objCRUD.InsertUpdateDelete(sqlCMD); } catch (Exception ex) { throw ex; } return(row); }
public List <ENT.HeatStartStopReport> GetHeatStartStopReport(ENT.HeatStartStopReport objENT) { List <ENT.HeatStartStopReport> lstENT = new List <ENT.HeatStartStopReport>(); try { sqlCMD = new SqlCommand(); sqlCMD.CommandText = "GetHeatStartStopReport"; sqlCMD.Parameters.AddWithValue("@ID", objENT.ID); sqlCMD.Parameters.AddWithValue("@Mode", objENT.Mode); lstENT = DBHelper.GetEntityList <ENT.HeatStartStopReport>(sqlCMD); } catch (Exception ex) { throw ex; } return(lstENT); }
private string SendHeatStartStopReportData(ENT.HeatStartStopReport obj, string json) { string message = string.Empty; try { // this is our live api url for send data to live database WebRequest tRequest = WebRequest.Create("http://gisrv.appsmith.co.in/api/HeatReport/InsertHeatStartStopReportAPI"); tRequest.Method = "POST"; tRequest.ContentType = "application/json"; obj.heat_json = json; string jsonNotificationFormat = Newtonsoft.Json.JsonConvert.SerializeObject(obj); Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat); tRequest.ContentLength = byteArray.Length; tRequest.ContentType = "application/json"; using (Stream dataStream = tRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse tResponse = tRequest.GetResponse()) { using (Stream dataStreamResponse = tResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String responseFromFirebaseServer = tReader.ReadToEnd(); message = "HeatStartStopReport : " + responseFromFirebaseServer; } } } } } catch (Exception ex) { message = ex.Message; return(message); } return(message); }
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { string fileName = "COMPortLog" + DateTime.Now.ToString("dd-MM-yyyy"); try { this.Invoke((Action) delegate { SerialPort sp = (SerialPort)sender; string indata = sp.ReadLine(); string[] words = indata.Split('|'); if (words.Length >= 3) { CURR_FUR_NAME = Convert.ToString(words[0]).Trim(); CURR_FUR_NO = Convert.ToInt32(words[1]); CURR_POUR_STATUS = Convert.ToString(words[2]).Trim() == "POURSTOP" ? Convert.ToInt32(DAL.MyEnum.PourStatus.POUR_STOP) : Convert.ToInt32(DAL.MyEnum.PourStatus.POUR_START); if (CURR_FUR_NAME.Equals("FURNACE2") && CURR_FUR_NO.Equals(1)) { SetText(CURR_FUR_NAME + "|" + CURR_FUR_NO + "|" + Convert.ToString(words[2]) + "|True"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> STRING >> " + indata + ""); } } objENTFur.Mode = "GetTopOne"; objENTFur.fur_name = CURR_FUR_NAME.Trim(); objENTFur.fur_no = CURR_FUR_NO; objENTFur.fur_status = CURR_POUR_STATUS; lstENTFur = objDALFur.GetFurnaceSwitch(objENTFur); if (lstENTFur.Count > 0) { if (lstENTFur[0].fur_status != CURR_POUR_STATUS) { // get last time from unit file. SetText(getDateFromCSVFile().ToString("dd/MMM/yyyy hh:mm:ss tt") + " Date From File."); objENTFur.fur_file_time = getDateFromCSVFile().ToString("dd/MMM/yyyy hh:mm:ss tt"); objENTFur.fur_id = Guid.NewGuid(); objENTFur.Mode = "ADD"; if (objDALFur.InsertUpdateDeleteFurnaceSwitch(objENTFur)) { SetText(indata + "|True|InsertSuccess"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> STRING >> " + indata + "|True|InsertSuccess"); } } else { SetText(indata + "|False|InsertFail"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> STRING >> " + indata + "|False|InsertFail"); } } if (CURR_POUR_STATUS == 1) { // get top one record by id for updated List <ENT.HeatStartStopReport> lstHSSR = new List <ENT.HeatStartStopReport>(); lstHSSR = new DAL.HeatStartStopReport().GetHeatStartStopReport(new ENT.HeatStartStopReport { Mode = "GetByTopOneUpdate" }); if (lstHSSR.Count > 0) { // when status is 0 then update record one time if (lstHSSR[0].isupdated == 0) { try { // get last record from MeterSlaveMaster for update into HeatStartStopReport table List <ENT.MeterSlaveMaster> lstMeter = new List <ENT.MeterSlaveMaster>(); lstMeter = new DAL.MeterSlaveMaster().GetTopOneRecord(new ENT.MeterSlaveMaster { Mode = "GetByTopOne" }); if (lstMeter.Count > 0) { ENT.HeatStartStopReport objHSSR = new ENT.HeatStartStopReport(); objHSSR = new ENT.HeatStartStopReport(); objHSSR.ID = lstHSSR[0].ID; objHSSR.fur_name = lstENTFur[0].fur_name; objHSSR.fur_no = lstENTFur[0].fur_no; objHSSR.fur_status_stop = lstENTFur[0].fur_status; objHSSR.fur_open_time = Convert.ToDateTime(lstENTFur[0].fur_open_time); objHSSR.fur_close_time = Convert.ToDateTime(lstENTFur[0].fur_close_time); objHSSR.LineCountEnd = lstMeter[0].LineCount; objHSSR.EndDataTime = lstMeter[0].DataTime; objHSSR.DataValue = lstMeter[0].DataValue; objHSSR.isupdated = 1; objHSSR.Mode = "UPDATE"; if (new DAL.HeatStartStopReport().UpdateHeatStartStopReport(objHSSR)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + lstMeter[0].FileName + " >> " + " >> LINE_NO >> " + objHSSR.LineCountEnd + " >> Updated For Report."); } } } } catch (Exception ex) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> ERROR >> " + ex.Message + ""); } } } } } else if (CURR_POUR_STATUS == 0) { // get record from database where isupdated=0 if not found any record then insert one record with isupdated=0 List <ENT.HeatStartStopReport> lstHSSR = new List <ENT.HeatStartStopReport>(); lstHSSR = new DAL.HeatStartStopReport().GetHeatStartStopReport(new ENT.HeatStartStopReport { Mode = "GetByTopOneInsert" }); if (lstHSSR.Count == 0) { // get last record from MeterSlaveMaster for insert into HeatStartStopReport table List <ENT.MeterSlaveMaster> lstMeter = new List <ENT.MeterSlaveMaster>(); lstMeter = new DAL.MeterSlaveMaster().GetTopOneRecord(new ENT.MeterSlaveMaster { Mode = "GetByTopOne" }); if (lstMeter.Count > 0) { ENT.HeatStartStopReport objHSSR = new ENT.HeatStartStopReport(); objHSSR.LineCountStart = lstMeter[0].LineCount; objHSSR.LineCountEnd = lstMeter[0].LineCount; objHSSR.StartDataTime = lstMeter[0].DataTime; objHSSR.EndDataTime = lstMeter[0].DataTime; objHSSR.DataValue = lstMeter[0].DataValue; objHSSR.DataValue2 = lstMeter[0].DataValue; objHSSR.FileName = lstMeter[0].FileName; objHSSR.EntryDate = DateTime.Now; objHSSR.isupdated = 0; objHSSR.Mode = "ADD"; if (new DAL.HeatStartStopReport().InsertHeatStartStopReport(objHSSR)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + objHSSR.FileName + " >> " + " LINE_NO >> " + objHSSR.LineCountStart + " >> Inserted For Report."); } } // Insert First record for dryrun heat report ENT.DryrunHeatReport objHDRH = new ENT.DryrunHeatReport(); try { objHDRH.LineCountStart = lstMeter[0].LineCount; objHDRH.LineCountEnd = lstMeter[0].LineCount; objHDRH.StartDataTime = lstMeter[0].DataTime; objHDRH.EndDataTime = lstMeter[0].DataTime; objHDRH.DataValueLast = lstMeter[0].DataValue; objHDRH.DataValueFirst = lstMeter[0].DataValue; objHDRH.FileName = lstMeter[0].FileName; objHDRH.EntryDate = DateTime.Now; objHDRH.IsUpdated = 0; objHDRH.Mode = "ADD"; if (new DAL.DryrunHeatReport().InsertUpdateDeleteDryrunHeatReport(objHDRH)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + objHDRH.FileName + " >> " + " LINE_NO >> " + objHDRH.LineCountStart + " >> Inserted For Dryrun Report."); } } } catch (Exception ex) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\ErrorLog.txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + objHDRH.FileName + " >> " + " >> LINE_NO >> " + objHDRH.LineCountStart + " >> " + ex.Message.ToString()); } } } } } } } else { // get last time from unit file. SetText(getDateFromCSVFile().ToString("dd/MMM/yyyy hh:mm:ss tt") + " Date From File."); objENTFur.fur_file_time = getDateFromCSVFile().ToString("dd/MMM/yyyy hh:mm:ss tt"); objENTFur.fur_id = Guid.NewGuid(); objENTFur.Mode = "ADD"; if (objDALFur.InsertUpdateDeleteFurnaceSwitch(objENTFur)) { SetText(indata + "|True|FirstInsertSuccess"); } else { SetText(indata + "|False|FirstInsertFail"); } } } else { SetText(indata + "|NA"); } }); } catch (Exception ex) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\" + fileName + ".txt", true)) { file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> ERROR >> " + ex.Message + ""); } this.SetText("Error => " + ex.Message.ToString()); } }