private void ImportData() { TAssignDetail objAssignDetail = null; TAssignInfo objAsignInfo = null; TPatientExam objPatientExam = null; TPatientInfo objPatientInfo = null; string SoCMND = ""; string sNgaySinh = ""; string sGioiTinh = ""; string sCoQuan = ""; string sChucVu = ""; byte btGioitinh = 0; string sDiaChi = ""; string sSDT = ""; string sMaNV = ""; var dtNgaySinh = new DateTime(); _lstAssignDetail.Clear(); if (!chkGhepLo.Checked) LaySoLoImportExcel(); int iSTT = 1; _Value = 0; try { DateTime sysdate = BusinessHelper.GetSysDateTime(); #region Get AssignInfo objAsignInfo = new TAssignInfo(); objAsignInfo.ExamId = -1; objAsignInfo.TreatId = -1; objAsignInfo.PatientDeptId = -1; objAsignInfo.PatientCode = SoCMND; objAsignInfo.ServiceId = -1; objAsignInfo.ServiceTypeId = -1; objAsignInfo.RegDate = dtNgayNhap.Value; objAsignInfo.PaymentStatus = 0; objAsignInfo.CreatedBy = globalVariables.UserName; objAsignInfo.CreateDate = sysdate; objAsignInfo.ObjectTypeId = -1; objAsignInfo.MaKhoaThien = "KSK"; objAsignInfo.Actived = 0; objAsignInfo.NoiTru = 0; objAsignInfo.IsPHIDvuKtheo = 0; #endregion #region Get AssignDetail foreach (DataRow dr in m_dtAssignDetail.Rows) { objAssignDetail = new TAssignDetail(); objAssignDetail.ExamId = -1; objAssignDetail.ServiceId = Convert.ToInt16(dr["Service_Id"]); objAssignDetail.ServiceDetailId = Convert.ToInt16(dr["ServiceDetail_Id"]); objAssignDetail.DiagPerson = Convert.ToInt16(dr["Diag_Person"]); objAssignDetail.DiscountRate = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Discount_Rate"], 0)); objAssignDetail.DiscountType = Convert.ToByte(Utility.ByteDbnull(dr["Discount_Type"], 0)); objAssignDetail.OriginPrice = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Origin_Price"], 0)); objAssignDetail.DiscountPrice = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Discount_Price"], 0)); objAssignDetail.SurchargePrice = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Surcharge_Price"], 0)); objAssignDetail.UserId = globalVariables.UserName; if (!string.IsNullOrEmpty(dr["Assign_Type_Id"].ToString())) objAssignDetail.AssignTypeId = Convert.ToByte(Utility.ByteDbnull(dr["Assign_Type_Id"], 0)); else objAssignDetail.AssignTypeId = 0; objAssignDetail.InputDate = dtNgayNhap.Value; objAssignDetail.PaymentStatus = 0; objAssignDetail.IsCancel = 0; objAssignDetail.IsPayment = 0; objAssignDetail.ObjectTypeId = 1; objAssignDetail.Quantity = Convert.ToInt32(dr["Quantity"]); objAssignDetail.AssignDetailStatus = 0; objAssignDetail.BhytStatus = 0; objAssignDetail.DisplayOnReport = 0; objAssignDetail.GiaBhytCt = 0; objAssignDetail.PaymentId = 0; objAssignDetail.ChoPhepIn = 0; _lstAssignDetail.Add(objAssignDetail); } foreach (GridEXRow row in grdData.GetCheckedRows()) { string patient_code = Utility.sDbnull(row.Cells["patient_code"].Value, ""); if (patient_code == "") { _BussinessImportExcel = new BussinessImportExcel(); #region Get PatientInfo SoCMND = ChuanHoaChuoi(row.Cells["CMT"].Value.ToString()); sNgaySinh = ChuanHoaChuoi(row.Cells["NGAY_SINH"].Value.ToString()); sGioiTinh = ChuanHoaChuoi(row.Cells["GIOI_TINH"].Value.ToString()); sCoQuan = ChuanHoaChuoi(row.Cells["CO_QUAN"].Value.ToString()); sChucVu = ChuanHoaChuoi(row.Cells["CHUC_VU"].Value.ToString()); sSDT = ChuanHoaChuoi(row.Cells["SDT"].Value.ToString()); sMaNV = ChuanHoaChuoi(row.Cells["Ma_NV"].Value.ToString()); // sDiaChi = ChuanHoaChuoi(row.Cells["DIA_CHI"].Value.ToString()); sDiaChi = ChuanHoaChuoi(row.Cells["DIACHI"].Value.ToString()); if (sGioiTinh.ToLower().Equals("m")) btGioitinh = 0; else if (sGioiTinh.ToLower().Equals("f")) btGioitinh = 1; else if (sGioiTinh.ToLower().Equals("nam")) btGioitinh = 0; else if (sGioiTinh.ToLower().Equals("nữ")) btGioitinh = 1; else btGioitinh = 2; if (string.IsNullOrEmpty(SoCMND)) SoCMND = dtNgayNhap.Value.ToString("yyyyMMdd") + "@" + iSTT; objPatientInfo = new TPatientInfo(); objPatientInfo.CountryId = 1; objPatientInfo.DanToc = 1; objPatientInfo.IdentifyNum = SoCMND; objPatientInfo.InputDate = dtNgayNhap.Value; objPatientInfo.Locked = 0; objPatientInfo.PatientJob = sChucVu; objPatientInfo.PatientName = ChuanHoaChuoi(row.Cells["HO_TEN"].Value.ToString()); objPatientInfo.PatientEmail = sMaNV; objPatientInfo.PatientPhone = sSDT; objPatientInfo.PatientAddr = sDiaChi; objPatientInfo.PatientSex = btGioitinh; objPatientInfo.Offices = sCoQuan; objPatientInfo.UserId = globalVariables.UserName; objPatientInfo.NgayTao = sysdate; int namsinh = DateTime.Now.Year; DateTime ngay_sinh = DateTime.Now; if (!string.IsNullOrEmpty(sNgaySinh)) { try { if (sNgaySinh.TrimStart().TrimEnd() == "") { namsinh = BusinessHelper.GetSysDateTime().Year; ngay_sinh = new DateTime(namsinh, 1, 1); } if (sNgaySinh.TrimStart().TrimEnd().Length == 4) { namsinh = Utility.Int32Dbnull(sNgaySinh, BusinessHelper.GetSysDateTime().Year); ngay_sinh = new DateTime(namsinh, 1, 1); } else { ngay_sinh = Convert.ToDateTime(sNgaySinh); namsinh = ngay_sinh.Year; } } catch { } objPatientInfo.PatientBirth = ngay_sinh; objPatientInfo.YearOfBirth = (Int16) namsinh; } objPatientInfo.SoLo = Convert.ToInt32(txtLo.Text); #endregion #region Get PatientExam objPatientExam = new TPatientExam(); objPatientExam.PatientCode = SoCMND; objPatientExam.ObjectTypeId = 1; objPatientExam.HosTrans = 0; objPatientExam.InputDate = objPatientInfo.InputDate; objPatientExam.UserId = objPatientInfo.UserId; objPatientExam.HosStatus = 0; objPatientExam.DiscountRate = 0; objPatientExam.Locked = 0; objPatientExam.IndentityNo = 1; objPatientExam.DisplayOnReport = 0; objPatientExam.NgayTao = objPatientInfo.NgayTao; objPatientExam.NguoiTao = objPatientInfo.UserId; objPatientExam.MaKhoaThien = "KSK"; objPatientExam.MaDoiTuong = "DV"; objPatientExam.EmergencyHos = 0; #endregion objAsignInfo.Barcode = ChuanHoaChuoi(Utility.sDbnull(row.Cells[TAssignInfo.Columns.Barcode].Value, "")); iSTT = iSTT + 1; row.BeginEdit(); string sMaDonVi = ""; string errMsg = ""; if ( !_BussinessImportExcel.Save(objPatientInfo, objPatientExam, objAsignInfo, _lstAssignDetail, dtNgayNhap.Value, sMaDonVi, ref errMsg)) { row.Cells["_Error"].Value = 1; _decFailed = _decFailed + 1; Utility.ShowMsg( "Import dữ liệu không thành công. Bạn hãy nhấn vào nút tìm kiếm theo lô và thực hiện xóa trước khi import lại.\n" + errMsg); return; } _Value = _Value + 1; row.Cells["_Error"].Value = 0; row.Cells["patient_code"].Value = objPatientExam.PatientCode; row.Cells["patient_id"].Value = objPatientExam.PatientId; row.Cells["assign_code"].Value = objAsignInfo.MaChidinh; row.Cells["assign_id"].Value = objAsignInfo.AssignId; row.EndEdit(); SetValue4Prg(progressImport, 1); Application.DoEvents(); //if (iSTT % 10 == 0) System.Threading.Thread.Sleep(1000); //Application.DoEvents(); #endregion } else { SetValue4Prg(progressImport, 1); Application.DoEvents(); } } } catch (Exception ex) { Utility.ShowMsg("Import dữ liệu không thành công" + ex.Message); } }
private void cmdXoalo_Click(object sender, EventArgs e) { if (Utility.AcceptQuestion("Bạn có chắc chắn muốn xóa dữ liệu lô vừa chọn", "Cảnh báo", true)) { _BussinessImportExcel = new BussinessImportExcel(); _BussinessImportExcel._OnDoing += _BussinessImportExcel__OnDoing; _Value = 0; var lstID = new List<int>(); progressImport.Maximum = grdData.GetCheckedRows().Length; progressImport.Value = 0; foreach (GridEXRow row in grdData.GetCheckedRows()) { int patient_id = Utility.Int32Dbnull(row.Cells["patient_id"].Value, -1); lstID.Add(patient_id); } _BussinessImportExcel.DeleteData(lstID, wait4Tu); Utility.ShowMsg("Đã xóa xong dữ liệu. Nhấn OK để kết thúc"); } }