private void btnSave_Click(object sender, EventArgs e) { if (Validation()) { if (MessageBox.Show("Do you want to save?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string machineId = grdDataSync[0, grdDataSync.CurrentCell.RowIndex].FormattedValue.ToString(); string status = grdDataSync[3, grdDataSync.CurrentCell.RowIndex].FormattedValue.ToString(); string ipAddress = grdDataSync[1, grdDataSync.CurrentCell.RowIndex].FormattedValue.ToString(); int port = int.Parse(grdDataSync[2, grdDataSync.CurrentCell.RowIndex].FormattedValue.ToString()); string Error = machineData.StartService(machineId, ipAddress, port, dtFrom.Value, dtTo.Value, "Device Is Online"); if (Error == "Successfull") { MessageBox.Show("Data Saved Successfully!!", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { using (TextWriter tw = new StreamWriter("Error" + DateTime.Now.ToString("yyyyMMddhh") + ".txt", true)) { tw.WriteLine(Error); } MessageBox.Show("Error Occured , Please check the log file!!", "Save", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } } }
private void StartAttandanceService() { IList <DeviceEntity> deviceEntities = deviceBLL.GetDynamic(" Where isActive=1", ""); IList <DeviceEntity> deviceOnline = new List <DeviceEntity>(); string Error = string.Empty; #region Variables string machineId = string.Empty; string status = string.Empty; string ipAddress = string.Empty; int port = 0; DateTime dtFrom = DateTime.Now; DateTime dtTo = DateTime.Now; #endregion foreach (DeviceEntity deviceEntity in deviceEntities) { machineId = deviceEntity.MachineId.ToString(); ipAddress = deviceEntity.IpAddress.ToString(); port = int.Parse(deviceEntity.Port.ToString()); dtFrom = DateTime.Now; dtTo = DateTime.Now; status = machineData.CheckingConnectionStatus(ipAddress, port.ToString()); if (status != "Device Is Online") { using (TextWriter tw = new StreamWriter("Error_" + DateTime.Now.ToString("yyyyMMddhh") + ".dat", true)) { tw.WriteLine(status); } } else { deviceOnline.Add(deviceEntity); } } foreach (DeviceEntity deviceEntity in deviceOnline) { machineId = deviceEntity.MachineId.ToString(); ipAddress = deviceEntity.IpAddress.ToString(); port = int.Parse(deviceEntity.Port.ToString()); dtFrom = DateTime.Now; dtTo = DateTime.Now; Error = machineData.StartService(machineId, ipAddress, port, dtFrom, dtTo, "Device Is Online"); if (Error == "Successfull") { //Text File write } else { using (TextWriter tw = new StreamWriter("Error" + DateTime.Now.ToString("yyyyMMddhh") + ".txt", true)) { tw.WriteLine(Error); } } } }
private void StartAttandanceService(string _Zid) { try { IList <DeviceEntity> deviceEntities = deviceBLL.GetDynamic(" Where isActive=1 and Zid='" + _Zid + "'", ""); IList <DeviceEntity> deviceOnline = new List <DeviceEntity>(); string FileLocation = ConfigurationManager.AppSettings["FileLocation"].ToString(); string Error = string.Empty; #region Variables string machineId = string.Empty; string status = string.Empty; string ipAddress = string.Empty; int port = 0; DateTime dtFrom = DateTime.Now; DateTime dtTo = DateTime.Now; #endregion foreach (DeviceEntity deviceEntity in deviceEntities) { machineId = deviceEntity.MachineId.ToString(); ipAddress = deviceEntity.IpAddress.ToString(); port = int.Parse(deviceEntity.Port.ToString()); dtFrom = DateTime.Now; dtTo = DateTime.Now; status = machineData.CheckingConnectionStatus(ipAddress, port.ToString()); if (status != "Device Is Online") { using (TextWriter tw = new StreamWriter(FileLocation + "Error_" + DateTime.Now.ToString("yyyyMMdd") + ".dat", true)) { tw.WriteLine(status); } } else { deviceOnline.Add(deviceEntity); } } foreach (DeviceEntity deviceEntity in deviceOnline) { machineId = deviceEntity.MachineId.ToString(); ipAddress = deviceEntity.IpAddress.ToString(); port = int.Parse(deviceEntity.Port.ToString()); dtFrom = DateTime.Now; dtTo = DateTime.Now; Error = machineData.StartService(machineId, ipAddress, port, dtFrom, dtTo, "Device Is Online"); if (Error == "Successfull") { //Text File write } else { using (TextWriter tw = new StreamWriter(FileLocation + "Error_" + DateTime.Now.ToString("yyyyMMdd") + ".dat", true)) { tw.WriteLine(Error); } } } } catch (Exception ex) { string _FileLocation = ConfigurationManager.AppSettings["FileLocation"].ToString(); string _Error = string.Empty; using (TextWriter tw = new StreamWriter(_FileLocation + "TaskSceduleError_" + DateTime.Now.ToString("yyyyMMdd") + ".dat", true)) { tw.WriteLine(_Error); } } finally { Application.Exit(); } }