private void UpdateDBLog(List <ShortEmps> mylist) { // Update DB for Success Export foreach (ShortEmps employeeList in mylist) { var employeeid = employeeList.Id; DateTime localdate = DateTime.Now; //var defaultDateTimeValue = default(DateTime); var marked = false; var document = Path.GetFileName(employeeList.DocSelected); SignEvents myevent = new SignEvents(employeeid, localdate, marked, document); DBUtility.AddEvent(myevent); } }
public void ExportDataToCSV() { var csv = new System.Text.StringBuilder(); for (var i = 0; i < dataGridView.Rows.Count; i++) { string employeeNum = Convert.ToString(dataGridView.Rows[i].Cells[0].Value); string id = Convert.ToString(dataGridView.Rows[i].Cells[1].Value.ToString()); string fullName = Convert.ToString(dataGridView.Rows[i].Cells[2].Value); string mobile = Convert.ToString(dataGridView.Rows[i].Cells[3].Value); string email = Convert.ToString(dataGridView.Rows[i].Cells[4].Value); string department = Convert.ToString(dataGridView.Rows[i].Cells[5].Value); var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6}", employeeNum, id, fullName, mobile, email, department, _DocSelectedAbsulutePath); csv.AppendLine(newLine); // Create List of Event to save to DB var myDate = GetDateWithoutMilliseconds(DateTime.Now); var defaultDateTimeValue = default(DateTime); List <SignEvents> Event = new List <SignEvents>(); SignEvents data = new SignEvents(int.Parse(id), employeeNum, myDate, true, _DocSelectedAbsulutePath, defaultDateTimeValue); DBUtility.AddEvent(data); // id, string employeeid, DateTime date, bool marked, string document, DateTime signdate } string CurDateTime = DateTime.Now.ToString(@"MM\_dd\_yyyy hh\:mm T"); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Export Employee Data"; saveFileDialog.Filter = "CSV file(*.csv)|*.csv"; saveFileDialog.Filter = "HealthList_" + CurDateTime; if (saveFileDialog.ShowDialog() == DialogResult.OK) { File.WriteAllText(saveFileDialog.FileName, csv.ToString(), Encoding.Unicode); } }