private void OnDisplayNhatKyLienHeCongTyList() { Result result = NhatKyLienHeCongTyBus.GetNhatKyLienHeCongTyList(_type, _fromDate, _toDate, _tenBenhNhan, _tenNguoiTao, _thang, _soDienThoai, _type2); if (result.IsOK) { MethodInvoker method = delegate { ClearData(); dgNhatKyLienHeCongTy.DataSource = result.QueryResult; lbKetQuaTimDuoc.Text = string.Format("Kết quả tìm được: {0}", dgNhatKyLienHeCongTy.RowCount); RefreshHighlight(); }; if (InvokeRequired) { BeginInvoke(method); } else { method.Invoke(); } } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("NhatKyLienHeCongTyBus.GetNhatKyLienHeCongTyList"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.GetNhatKyLienHeCongTyList")); } }
private void OnDelete() { List <string> deletedSpecList = new List <string>(); List <DataRow> deletedRows = new List <DataRow>(); DataTable dt = dgNhatKyLienHeCongTy.DataSource as DataTable; foreach (DataRow row in dt.Rows) { if (Boolean.Parse(row["Checked"].ToString())) { string userGUID = row["CreatedBy"].ToString(); string nguoiTao = row["NguoiTao"] as string; if (nguoiTao != null && nguoiTao.Trim() != string.Empty && userGUID != Global.UserGUID) { MsgBox.Show(Application.ProductName, "Bạn không thể xóa nhật ký liên hệ của người khác. Vui lòng kiểm tra lại.", IconType.Information); return; } deletedSpecList.Add(row["NhatKyLienHeCongTyGUID"].ToString()); deletedRows.Add(row); } } if (deletedSpecList.Count > 0) { if (MsgBox.Question(Application.ProductName, "Bạn có muốn xóa những nhật ký liên hệ mà bạn đã đánh dấu ?") == DialogResult.Yes) { Result result = NhatKyLienHeCongTyBus.DeleteNhatKyLienHeCongTy(deletedSpecList); if (result.IsOK) { foreach (DataRow row in deletedRows) { dt.Rows.Remove(row); } } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("NhatKyLienHeCongTyBus.DeleteNhatKyLienHeCongTy"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.DeleteNhatKyLienHeCongTy")); } } } else { MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những nhật ký liên hệ cần xóa.", IconType.Information); } }
private void DisplayCongTyLienHeList() { dtpkNgayGioLienHe.Value = DateTime.Now; Result result = NhatKyLienHeCongTyBus.GetCongTyLienHeList(); if (result.IsOK) { DataTable dt = result.QueryResult as DataTable; foreach (DataRow row in dt.Rows) { cboCongTyLienHe.Items.Add(row["CongTyLienHe"].ToString()); } } else { MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.GetCongTyLienHeList"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.GetCongTyLienHeList")); } }
private void OnSaveInfo() { try { _nhatKyLienHeCongTy.Status = (byte)Status.Actived; if (_isNew) { _nhatKyLienHeCongTy.CreatedDate = DateTime.Now; _nhatKyLienHeCongTy.CreatedBy = Guid.Parse(Global.UserGUID); } else { _nhatKyLienHeCongTy.UpdatedDate = DateTime.Now; _nhatKyLienHeCongTy.UpdatedBy = Guid.Parse(Global.UserGUID); } MethodInvoker method = delegate { _nhatKyLienHeCongTy.NgayGioLienHe = dtpkNgayGioLienHe.Value; if (!_isNew) { int soNgay = DateTime.Now.Subtract(dtpkNgayGioLienHe.Value).Days; int thang = soNgay / 30; int ngay = soNgay % 30; if (thang > 0) { _nhatKyLienHeCongTy.SoNgay = string.Format("{0} tháng {1} ngày", thang, ngay); } else { _nhatKyLienHeCongTy.SoNgay = string.Format("{0} ngày", ngay); } } if (Global.StaffType != StaffType.Admin) { _nhatKyLienHeCongTy.DocStaffGUID = Guid.Parse(Global.UserGUID); } else { _nhatKyLienHeCongTy.DocStaffGUID = null; } _nhatKyLienHeCongTy.CongTyLienHe = cboCongTyLienHe.Text; _nhatKyLienHeCongTy.NoiDungLienHe = txtNoiDungLienHe.Text; _nhatKyLienHeCongTy.Note = string.Empty; _nhatKyLienHeCongTy.TenNguoiLienHe = txtNguoiLienHe.Text; _nhatKyLienHeCongTy.SoDienThoaiLienHe = txtSoDienThoaiLienHe.Text; _nhatKyLienHeCongTy.SoNguoiKham = txtSoNguoiKham.Text; _nhatKyLienHeCongTy.DiaChi = txtDiaChi.Text; _nhatKyLienHeCongTy.Email = txtEmail.Text; _nhatKyLienHeCongTy.ThangKham = txtThangKham.Text; _nhatKyLienHeCongTy.Highlight = chkHighlight.Checked; Result result = NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy(_nhatKyLienHeCongTy); if (!result.IsOK) { MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("NhatKyLienHeCongTyBus.InsertNhatKyLienHeCongTy")); this.DialogResult = System.Windows.Forms.DialogResult.Cancel; } }; if (InvokeRequired) { BeginInvoke(method); } else { method.Invoke(); } } catch (Exception e) { MsgBox.Show(this.Text, e.Message, IconType.Error); Utility.WriteToTraceLog(e.Message); } }
private bool CheckInfo() { if (cboCongTyLienHe.Text.Trim() == string.Empty) { MsgBox.Show(this.Text, "Vui lòng nhập công ty liên hệ.", IconType.Information); cboCongTyLienHe.Focus(); return(false); } //if (txtNguoiLienHe.Text.Trim() == string.Empty) //{ // MsgBox.Show(this.Text, "Vui lòng nhập tên người liên hệ.", IconType.Information); // txtNguoiLienHe.Focus(); // return false; //} if (txtSoDienThoaiLienHe.Text.Trim() == string.Empty && txtEmail.Text.Trim() == string.Empty) { MsgBox.Show(this.Text, "Vui lòng nhập số điện thoại hoặc email liên hệ.", IconType.Information); txtSoDienThoaiLienHe.Focus(); return(false); } //if (txtThangKham.Text.Trim() == string.Empty) //{ // MsgBox.Show(this.Text, "Vui lòng nhập tháng khám.", IconType.Information); // txtThangKham.Focus(); // return false; //} string nhatKyLienHeCongTyGUID = string.Empty; if (!_isNew) { nhatKyLienHeCongTyGUID = _nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID.ToString(); } Result result = NhatKyLienHeCongTyBus.CheckCongTyLienHeExist(cboCongTyLienHe.Text, nhatKyLienHeCongTyGUID); if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST) { if (result.Error.Code == ErrorCode.EXIST) { MsgBox.Show(this.Text, string.Format("Công ty: '{0}' đã liên hệ rồi. Vui lòng xem lại thông tin.", cboCongTyLienHe.Text), IconType.Information); _isView = true; return(false); } } else { MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.CheckCongTyLienHeExist"), IconType.Error); return(false); } nhatKyLienHeCongTyGUID = string.Empty; if (!_isNew) { nhatKyLienHeCongTyGUID = _nhatKyLienHeCongTy.NhatKyLienHeCongTyGUID.ToString(); } result = NhatKyLienHeCongTyBus.CheckCongTyLienHeExist2(cboCongTyLienHe.Text, nhatKyLienHeCongTyGUID); if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST) { if (result.Error.Code == ErrorCode.EXIST) { string sChoice = string.Format("Công ty: '{0}' đã liên hệ rồi. Bạn có muốn tạo liên hệ với công ty này nữa không?", cboCongTyLienHe.Text); if (MsgBox.Question(this.Text, sChoice) == DialogResult.Yes) { return(true); } _isView = true; return(false); } } else { MsgBox.Show(this.Text, result.GetErrorAsString("NhatKyLienHeCongTyBus.CheckCongTyLienHeExist2"), IconType.Error); return(false); } return(true); }
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); } }