Beispiel #1
0
        /// <summary>
        /// Insert Update Dryrun report data
        /// </summary>
        /// <param name="objENT"></param>
        /// <returns></returns>
        public bool InsertUpdateDeleteDryrunHeatReport(ENT.DryrunHeatReport objENT)
        {
            bool row = false;

            try
            {
                sqlCMD             = new SqlCommand();
                sqlCMD.CommandText = "InsertUpdateDeleteDryrunHeatReport";
                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("@DataValueLast", objENT.DataValueLast);
                sqlCMD.Parameters.AddWithValue("@DataValueFirst", objENT.DataValueFirst);
                sqlCMD.Parameters.AddWithValue("@FileName", objENT.FileName);
                sqlCMD.Parameters.AddWithValue("@EntryDate", objENT.EntryDate);
                sqlCMD.Parameters.AddWithValue("@Mode", objENT.Mode);
                row = objCRUD.InsertUpdateDelete(sqlCMD);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(row);
        }
        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());
            }
        }
Beispiel #3
0
        private void ReadData()
        {
            string strFilename = "01SELEC" + DateTime.Now.ToString("yyMMdd") + ".csv";

            try
            {
                objTime.Stop();
                objTime.Enabled = false;
                int      cntInsert        = 0;
                string   copyToFilePath   = Path.Combine(Application.StartupPath, strFilename);
                string[] copyFromFilePath = File.ReadAllLines(Path.Combine(Application.StartupPath, "DownloadFilePath.txt"));
                tmInerval        = Convert.ToInt32(copyFromFilePath[1]);
                objTime.Interval = ((1000 * 60) * tmInerval);

                #region Copy File From FTP Folder
                if (File.Exists(copyToFilePath))
                {
                    if (File.Exists(Path.Combine(copyFromFilePath[0], strFilename)))
                    {
                        File.Delete(copyToFilePath);
                        File.Copy(Path.Combine(copyFromFilePath[0], strFilename), copyToFilePath);
                    }
                    else
                    {
                        notifyIcon1.BalloonTipText = "File not generated by machine, Please check machine status.";
                        notifyIcon1.ShowBalloonTip(2000);
                        objTime.Start();
                    }
                }
                else
                {
                    if (File.Exists(Path.Combine(copyFromFilePath[0], strFilename)))
                    {
                        File.Copy(Path.Combine(copyFromFilePath[0], strFilename), copyToFilePath);
                    }
                    else
                    {
                        notifyIcon1.BalloonTipText = "File not generated by machine, Please check machine status.";
                        notifyIcon1.ShowBalloonTip(2000);
                        objTime.Start();
                    }
                }
                #endregion

                #region Line Count Of File
                DataTable dtNew = new DataTable();
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                string     strqry = "SELECT COUNT(*) AS Cnt FROM MeterSlaveMaster WHERE FileName='" + strFilename.Trim() + "'";
                SqlCommand cmd    = new SqlCommand();
                cmd.CommandText = strqry;
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = conn;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dtNew);

                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                int lines_count = Convert.ToInt32(dtNew.Rows[0][0]);
                #endregion

                DataTable dtCSV = DAL.MeterSlaveMaster.GetDataTableFromCSVFile((Path.Combine(Application.StartupPath, strFilename)));
                for (int m = lines_count; m < dtCSV.Rows.Count; m++)
                {
                    try
                    {
                        ENT.MeterSlaveMaster    objENT  = new ENT.MeterSlaveMaster();
                        ENT.HeatStartStopReport objHSSR = new ENT.HeatStartStopReport();
                        ENT.DryrunHeatReport    objHDRH = new ENT.DryrunHeatReport();

                        objENT.ID = Guid.NewGuid();

                        string   date    = dtCSV.Rows[m][0].ToString().Substring(0, 8);
                        string[] arrDate = date.Split('-');
                        DateTime dtDate  = new DateTime(2000 + Convert.ToInt32(arrDate[0]), Convert.ToInt32(arrDate[1]), Convert.ToInt32(arrDate[2]), 0, 0, 0);
                        objENT.DataDate = dtDate;


                        string   time    = dtCSV.Rows[m][0].ToString().Substring(9, 8);
                        string[] arrTime = time.Split(':');
                        DateTime dtTime  = new DateTime(2000 + Convert.ToInt32(arrDate[0]), Convert.ToInt32(arrDate[1]), Convert.ToInt32(arrDate[2]), Convert.ToInt32(arrTime[0]), Convert.ToInt32(arrTime[1]), Convert.ToInt32(arrTime[2]));
                        objENT.DataTime = dtTime;


                        objENT.MeterID   = 0;
                        objENT.SlaveID   = 0;
                        objENT.Address   = 0;
                        objENT.Quantity  = 0;
                        objENT.DataValue = Convert.ToDecimal(Convert.ToString(dtCSV.Rows[m][1]));

                        string strValues = Convert.ToString(dtCSV.Rows[m][2]);
                        strValues = strValues.Replace("[", "").Replace("]", "");
                        string[] Values = strValues.Split(',');
                        objENT.Value1 = Convert.ToDecimal(Values[0]);
                        objENT.Value2 = Convert.ToDecimal(Values[1]);

                        #region Get Last Unit
                        DataTable dtTop = new DataTable();
                        if (conn.State == ConnectionState.Closed)
                        {
                            conn.Open();
                        }
                        string     strTopOne = "SELECT TOP 1 ISNULL(DataValue,0) as DataValue,Value2,FinalUnit FROM MeterSlaveMaster ORDER BY EntryDate DESC, LineCount DESC";
                        SqlCommand cmdtop    = new SqlCommand();
                        cmdtop.CommandText = strTopOne;
                        cmdtop.CommandType = CommandType.Text;
                        cmdtop.Connection  = conn;
                        SqlDataAdapter daTop = new SqlDataAdapter(cmdtop);
                        daTop.Fill(dtTop);
                        decimal dcmPrvValue2 = 0;
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                        if (dtTop.Rows.Count > 0)
                        {
                            objENT.DataValue2 = Convert.ToDecimal(dtTop.Rows[0]["DataValue"]);
                            objENT.FinalUnit  = Convert.ToDecimal(dtTop.Rows[0]["FinalUnit"]);
                            dcmPrvValue2      = Convert.ToDecimal(dtTop.Rows[0]["Value2"]);
                            using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\LastUnitLog-" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt", true))
                            {
                                file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> DataValue Found >> " + objENT.DataValue2 + " >> " + " LINE_NO >> " + m);
                            }
                        }
                        else
                        {
                            objENT.DataValue2 = 0; objENT.FinalUnit = 0;
                            using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\LastUnitLog-" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt", true))
                            {
                                file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> DataValue Not Found>> " + objENT.DataValue2 + " >> " + " LINE_NO >> " + m);
                            }
                        }


                        decimal dcmDiff = objENT.Value2 - dcmPrvValue2;

                        dcmDiff = dcmDiff / 64;

                        if (dcmDiff < 0)
                        {
                            dcmDiff = dcmDiff + 1024;
                        }

                        objENT.Difference = dcmDiff;
                        objENT.FinalUnit  = objENT.FinalUnit + dcmDiff;

                        #endregion

                        string QueryString = "INSERT INTO MeterSlaveMaster (ID,DataDate,DataTime,MeterID,SlaveID,Address,Quantity,DataValue,DataValue2,Difference,FinalUnit,Value1,Value2,FileName,LineCount,EntryDate) values ('" + objENT.ID.ToString() + "','" + objENT.DataDate.ToString("dd/MMM/yyyy") + "','" + objENT.DataTime.ToString("dd/MMM/yyyy hh:mm:ss tt") + "'," + objENT.MeterID + "," + objENT.SlaveID + "," + objENT.Address + "," + objENT.Quantity + "," + objENT.DataValue + "," + objENT.DataValue2 + "," + objENT.Difference + "," + objENT.FinalUnit + "," + objENT.Value1 + "," + objENT.Value2 + ",'" + strFilename.Trim() + "'," + (m + 1).ToString() + ",getdate())";
                        if (conn.State == ConnectionState.Closed)
                        {
                            conn.Open();
                        }

                        SqlCommand cmdInsert = new SqlCommand();
                        cmdInsert.CommandText = QueryString;
                        cmdInsert.CommandType = CommandType.Text;
                        cmdInsert.Connection  = conn;

                        if (cmdInsert.ExecuteNonQuery() > 0)
                        {
                            cntInsert = cntInsert + 1;
                            if (m == 0)
                            {
                                // Insert First record for heat report
                                try
                                {
                                    objHSSR.LineCountStart = lines_count + 1;
                                    objHSSR.LineCountEnd   = lines_count + 1;
                                    objHSSR.StartDataTime  = objENT.DataTime;
                                    objHSSR.EndDataTime    = objENT.DataTime;
                                    objHSSR.DataValue      = objENT.DataValue;
                                    objHSSR.DataValue2     = objENT.DataValue;
                                    objHSSR.FileName       = strFilename.Trim();
                                    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\\LastUnitLog-" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt", true))
                                        {
                                            file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + strFilename + " >> LINE_NO >> " + cntInsert + " >> Inserted For Report.");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\ErrorLog.txt", true))
                                    {
                                        file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + strFilename + " >> LINE_NO >> " + cntInsert + " >> HeatReport >> " + ex.Message.ToString());
                                    }
                                }

                                // Insert First record for dryrun heat report
                                try
                                {
                                    objHDRH.LineCountStart = lines_count + 1;
                                    objHDRH.LineCountEnd   = lines_count + 1;
                                    objHDRH.StartDataTime  = objENT.DataTime;
                                    objHDRH.EndDataTime    = objENT.DataTime;
                                    objHDRH.DataValueLast  = objENT.DataValue;
                                    objHDRH.DataValueFirst = objENT.DataValue;
                                    objHDRH.FileName       = strFilename.Trim();
                                    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\\LastUnitLog-" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt", true))
                                        {
                                            file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + strFilename + " >> " + " >> LINE_NO >> " + cntInsert + " >>  Inserted For Dryrun Report.");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\ErrorLog.txt", true))
                                    {
                                        file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + strFilename + " >> " + " >> LINE_NO >> " + cntInsert + " >> DryrunReport >> " + ex.Message.ToString());
                                    }
                                }
                            }
                        }

                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\ErrorLog.txt", true))
                        {
                            file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + strFilename + " >> " + " >> LINE_NO >> " + cntInsert + " >> " + ex.Message.ToString());
                        }

                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                }
                objTime.Start();
                objTime.Enabled = true;
            }
            catch (Exception ex)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\Log\\ErrorLog.txt", true))
                {
                    file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> FILE_NAME >> " + strFilename + " >> " + ex.Message.ToString());
                }

                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                notifyIcon1.BalloonTipText = "Error : " + ex.Message.ToString();
                notifyIcon1.ShowBalloonTip(2000);
                objTime.Start();
            }
        }