public static Result DeleteNhatKyLienHeCongTy(List <string> keys) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { string desc = string.Empty; int index = 0; foreach (string key in keys) { NhatKyLienHeCongTy s = db.NhatKyLienHeCongTies.SingleOrDefault <NhatKyLienHeCongTy>(ss => ss.NhatKyLienHeCongTyGUID.ToString() == key); if (s != null) { s.DeletedDate = DateTime.Now; s.DeletedBy = Guid.Parse(Global.UserGUID); s.Status = (byte)Status.Deactived; string docStaffGUID = string.Empty; string fullName = "Admin"; if (s.DocStaffGUID != null) { docStaffGUID = s.DocStaffGUID.ToString(); fullName = s.DocStaff.Contact.FullName; } desc += string.Format("- GUID: '{0}', Mã nhân viên: '{1}', Tên nhân viên: '{2}', Tên công ty liên hệ: '{3}', Tên người liên hệ: '{4}', Đia chỉ (Quận): '{5}', Số ĐT liên hệ: '{6}', Email liên hệ: '{7}', Số người khám: '{8}', Tháng khám: '{9}', Nội dung liên hệ: '{10}', Ghi chú: '{11}', Highlight: '{12}', Số ngày: '{13}'\n", s.NhatKyLienHeCongTyGUID.ToString(), docStaffGUID, fullName, s.CongTyLienHe, s.TenNguoiLienHe, s.DiaChi, s.SoDienThoaiLienHe, s.Email, s.SoNguoiKham, s.ThangKham, s.NoiDungLienHe, s.Note, s.Highlight, s.SoNgay); } index++; } //Tracking desc = desc.Substring(0, desc.Length - 1); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Delete; tk.Action = "Xóa nhật ký liên hệ công ty"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public static Result InsertNhatKyLienHeCongTy(NhatKyLienHeCongTy nhatKyLienHeCongTy) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { //Insert if (nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID == null || nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID == Guid.Empty) { nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID = Guid.NewGuid(); db.NhatKyLienHeCongTies.InsertOnSubmit(nhatKyLienHeCongTy); db.SubmitChanges(); //Tracking string docStaffGUID = string.Empty; string fullName = "Admin"; if (nhatKyLienHeCongTy.DocStaffGUID != null) { docStaffGUID = nhatKyLienHeCongTy.DocStaffGUID.ToString(); fullName = nhatKyLienHeCongTy.DocStaff.Contact.FullName; } desc += string.Format("- GUID: '{0}', Mã nhân viên: '{1}', Tên nhân viên: '{2}', Tên công ty liên hệ: '{3}', Tên người liên hệ: '{4}', Đia chỉ (Quận): '{5}', Số ĐT liên hệ: '{6}', Email liên hệ: '{7}', Số người khám: '{8}', Tháng khám: '{9}', Nội dung liên hệ: '{10}', Ghi chú: '{11}', Highlight: '{12}'", nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID.ToString(), docStaffGUID, fullName, nhatKyLienHeCongTy.CongTyLienHe, nhatKyLienHeCongTy.TenNguoiLienHe, nhatKyLienHeCongTy.DiaChi, nhatKyLienHeCongTy.SoDienThoaiLienHe, nhatKyLienHeCongTy.Email, nhatKyLienHeCongTy.SoNguoiKham, nhatKyLienHeCongTy.ThangKham, nhatKyLienHeCongTy.NoiDungLienHe, nhatKyLienHeCongTy.Note, nhatKyLienHeCongTy.Highlight); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Add; tk.Action = "Thêm nhật ký liên hệ công ty"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } else //Update { NhatKyLienHeCongTy nklhct = db.NhatKyLienHeCongTies.SingleOrDefault <NhatKyLienHeCongTy>(s => s.NhatKyLienHeCongTyGUID == nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID); if (nklhct != null) { nklhct.DocStaffGUID = nhatKyLienHeCongTy.DocStaffGUID; nklhct.NgayGioLienHe = nhatKyLienHeCongTy.NgayGioLienHe; nklhct.CongTyLienHe = nhatKyLienHeCongTy.CongTyLienHe; nklhct.NoiDungLienHe = nhatKyLienHeCongTy.NoiDungLienHe; nklhct.Note = nhatKyLienHeCongTy.Note; nklhct.CreatedDate = nhatKyLienHeCongTy.CreatedDate; nklhct.CreatedBy = nhatKyLienHeCongTy.CreatedBy; nklhct.UpdatedDate = nhatKyLienHeCongTy.UpdatedDate; nklhct.UpdatedBy = nhatKyLienHeCongTy.UpdatedBy; nklhct.DeletedDate = nhatKyLienHeCongTy.DeletedDate; nklhct.DeletedBy = nhatKyLienHeCongTy.DeletedBy; nklhct.Status = nhatKyLienHeCongTy.Status; nklhct.TenNguoiLienHe = nhatKyLienHeCongTy.TenNguoiLienHe; nklhct.SoDienThoaiLienHe = nhatKyLienHeCongTy.SoDienThoaiLienHe; nklhct.SoNguoiKham = nhatKyLienHeCongTy.SoNguoiKham; nklhct.ThangKham = nhatKyLienHeCongTy.ThangKham; nklhct.DiaChi = nhatKyLienHeCongTy.DiaChi; nklhct.Email = nhatKyLienHeCongTy.Email; nklhct.Highlight = nhatKyLienHeCongTy.Highlight; nklhct.SoNgay = nhatKyLienHeCongTy.SoNgay; //Tracking string docStaffGUID = string.Empty; string fullName = "Admin"; if (nklhct.DocStaffGUID != null) { docStaffGUID = nklhct.DocStaffGUID.ToString(); fullName = nklhct.DocStaff.Contact.FullName; } desc += string.Format("- GUID: '{0}', Mã nhân viên: '{1}', Tên nhân viên: '{2}', Tên công ty liên hệ: '{3}', Tên người liên hệ: '{4}', Đia chỉ (Quận): '{5}', Số ĐT liên hệ: '{6}', Email liên hệ: '{7}', Số người khám: '{8}', Tháng khám: '{9}', Nội dung liên hệ: '{10}', Ghi chú: '{11}', Highlight: '{12}', Số ngày: '{13}'", nklhct.NhatKyLienHeCongTyGUID.ToString(), docStaffGUID, fullName, nklhct.CongTyLienHe, nklhct.TenNguoiLienHe, nklhct.DiaChi, nklhct.SoDienThoaiLienHe, nklhct.Email, nklhct.SoNguoiKham, nklhct.ThangKham, nklhct.NoiDungLienHe, nklhct.Note, nklhct.Highlight, nklhct.SoNgay); Tracking tk = new Tracking(); tk.TrackingGUID = Guid.NewGuid(); tk.TrackingDate = DateTime.Now; tk.DocStaffGUID = Guid.Parse(Global.UserGUID); tk.ActionType = (byte)ActionType.Edit; tk.Action = "Sửa nhật ký liên hệ công ty"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.None; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } } t.Complete(); } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
private void ImportNhatKyFromExcel(string filename) { string LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log"); LogFile = Path.Combine(LogFile, "Import_" + DateTime.Now.ToString("dd-MM-yyyy-") + System.Environment.MachineName + ".txt"); if (File.Exists(LogFile)) { File.Delete(LogFile); } string message = "Nhập dữ liệu từ Excel hoàn tất." + System.Environment.NewLine; Cursor.Current = Cursors.WaitCursor; try { if (File.Exists(filename)) { IWorkbook book = SpreadsheetGear.Factory.GetWorkbook(filename); foreach (IWorksheet sheet in book.Worksheets) { if (CheckNhatKyTemplate(sheet, ref message)) { int RowCount = sheet.UsedRange.RowCount + 1; int ColumnCount = sheet.UsedRange.ColumnCount + 1; for (int i = 1; i < RowCount; i++) { NhatKyLienHeCongTy diary = new NhatKyLienHeCongTy(); for (int j = 0; j < ColumnCount; j++) { string curCellValue = string.Empty; if (sheet.Cells[i, j] != null && sheet.Cells[i, j].Value != null && sheet.Cells[i, j].Text != null) { curCellValue = sheet.Cells[i, j].Text.Trim(); } //process NULL text in excel if (curCellValue.ToUpper() == "NULL") { curCellValue = ""; } string sType = sheet.Cells[i, j].NumberFormat.Trim(); if (sType.Contains("yy")) { curCellValue = ReFormatDate(sType, curCellValue); } //process "'" character curCellValue = curCellValue.Replace("'", "''"); if (sheet.Cells[i, j].Font.Name.ToLower().IndexOf("vni") == 0) { curCellValue = Utility.ConvertVNI2Unicode(curCellValue); } if (sheet.Cells[0, j].Value != null && sheet.Cells[0, j].Value.ToString().Trim() != null) { switch (sheet.Cells[0, j].Value.ToString().Trim().ToLower()) { case "district": diary.DiaChi = curCellValue; break; case "company name": diary.CongTyLienHe = curCellValue; break; case "person contact": diary.TenNguoiLienHe = curCellValue; break; case "tel": diary.SoDienThoaiLienHe = curCellValue; break; case "quantity": diary.SoNguoiKham = curCellValue; break; case "check-up month": diary.ThangKham = curCellValue; break; // case "feedback": diary.NoiDungLienHe = curCellValue; break; case "email": diary.Email = curCellValue; break; case "contact date": DateTime dt = new DateTime(); if (DateTime.TryParse(curCellValue, out dt)) { diary.CreatedDate = dt; diary.NgayGioLienHe = dt; } else { diary.CreatedDate = DateTime.Now; diary.NgayGioLienHe = DateTime.Now; } break; default: break; } } } //add to db //if (diary.CongTyLienHe != null && diary.CongTyLienHe != "" && diary.TenNguoiLienHe != null && diary.TenNguoiLienHe != "") if (diary.CongTyLienHe != null && diary.CongTyLienHe != "") { Result rs = NhatKyLienHeCongTyBus.CheckCongTyLienHeExist(diary.CongTyLienHe, string.Empty); if (rs.Error.Code == ErrorCode.EXIST) { string sLog = string.Format("Line {0}: Company:{1}", (i + 1).ToString(), diary.CongTyLienHe); WriteToLogFile(LogFile, sLog); continue; } else { if (Global.StaffType != StaffType.Admin) { diary.DocStaffGUID = Guid.Parse(Global.UserGUID); } else { diary.DocStaffGUID = null; } diary.CreatedBy = Guid.Parse(Global.UserGUID); diary.Note = "Import from Excel on " + DateTime.Now.ToString("dd/MM/yyyy"); Result result = NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy(diary); if (!result.IsOK) { MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy")); } } } else { string sLog = string.Format("Line {0}: Company:{1}", (i + 1).ToString(), diary.CongTyLienHe); WriteToLogFile(LogFile, sLog); } } } } } MsgBox.Show(Application.ProductName, message, IconType.Information); DisplayAsThread(); } catch (Exception ex) { MsgBox.Show(Application.ProductName, ex.Message, IconType.Error); Utility.WriteToTraceLog(ex.Message); } }