private void ExecuteAction() { //Kiểm tra tính hợp lệ của dữ liệu trước khi thêm mới if (!IsValidData()) { return; } //Gán ServerEntity vào DataEntity SetValueforEntity(); //Khởi tạo BusinessRule để xử lý nghiệp vụ ServerInfor Infor = new ServerInfor(); Utility.MapValueFromEntityIntoObjectInfor(Infor, ServerEntity); ServerController _BusRule = new ServerController(Infor); switch (Act) { case action.Insert: //Gọi nghiệp vụ Insert dữ liệu ActionResult InsertResult = _BusRule.Insert(); if (InsertResult == ActionResult.Success)//Nếu thành công { //Thêm mới một dòng vào Datasource để cập nhật lại dữ liệu trên DataGridView //phải đảm bảo Datasource và ServerEntity có cấu trúc giống nhau mới dùng hàm này DataRow dr = Utility.CopyData(ServerEntity.Rows[0], DataSource); dr["ID"] = Infor.ID; if (dr != null)//99.99% là sẽ !=null { DataSource.Rows.Add(dr); DataSource.AcceptChanges(); } //Return to the InitialStatus Act = action.FirstOrFinished; //Nhảy đến bản ghi vừa thêm mới trên lưới. Do txtID chưa bị reset nên dùng luôn Utility.GotoNewRow(grdList, "colIpAddress", txtIpAddress.Text.Trim()); mdlStatic.SetMsg(lblMsg, "Thêm mới dữ liệu thành công!", false); SetControlStatus(); CurrentCellChanged(); } else//Có lỗi xảy ra { switch (InsertResult) { case ActionResult.ExistedRecord: mdlStatic.SetMsg(lblMsg, "Đã tồn tại Server có địa chỉ: " + txtIpAddress.Text.Trim() + " và Called AETitle:"+txtCalledAETitle.Text.Trim() +" và cổng :"+txtport.Text.Trim()+"\n Đề nghị bạn xem lại",true); break; default: mdlStatic.SetMsg(lblMsg,"Lỗi trong quá trình thêm mới Server. Liên hệ với VBIT",true); break; } } break; case action.Update: //Gọi Business cập nhật dữ liệu ActionResult UpdateResult = _BusRule.Update(); if (UpdateResult == ActionResult.Success)//Nếu thành công { //Cập nhật số thứ tự cho bản ghi tráo số thứ tự với bản ghi đang được cập nhật(nếu có)? foreach (DataRow drUpdatePort in DataSource.Rows) { if (Utility.Int16Dbnull(drUpdatePort["Port"]) == Convert.ToInt16(txtport.Text)) { drUpdatePort["Port"] = OldPort; break; // TODO: might not be correct. Was : Exit For } } DataSource.AcceptChanges(); //Cập nhật dòng hiện thời trong Datasource để cập nhật lại dữ liệu trên DataGridView DataRow dr = Utility.GetDataRow(DataSource, "ID", Utility.GetValueFromGridColumn(grdList, "colID", grdList.CurrentRow.Index)); if (dr != null) { Utility.CopyData(ServerEntity.Rows[0], ref dr); DataSource.AcceptChanges(); } //Return to the InitialStatus Act = action.FirstOrFinished; //Nhảy đến bản ghi vừa cập nhật trên lưới. Do txtID chưa bị reset nên dùng luôn Utility.GotoNewRow(grdList, "colIpAddress", txtIpAddress.Text.Trim()); mdlStatic.SetMsg(lblMsg, "Cập nhật dữ liệu thành công.", false); SetControlStatus(); CurrentCellChanged(); } else//Có lỗi xảy ra { switch (UpdateResult) { case ActionResult.Error: mdlStatic.SetMsg(lblMsg, "Lỗi khi cập nhật Server. Liên hệ với VBIT", true); break; default: mdlStatic.SetMsg(lblMsg, "Lỗi khi cập nhật Server. Liên hệ với VBIT", true); break; } } break; case action.Delete: if (Utility.AcceptQuestion("Bạn có muốn xóa Server đang chọn hay không?", "Xác nhận xóa", true)) { string IpAddress = txtIpAddress.Text.Trim(); //Gọi nghiệp vụ xóa dữ liệu ActionResult DeleteResult = _BusRule.Delete(); if (DeleteResult == ActionResult.Success)//Nếu xóa thành công trong CSDL { //Xóa dòng dữ liệu vừa chọn trong Datasource để cập nhật lại dữ liệu trên DataGridView DataRow dr = Utility.GetDataRow(DataSource, "IpAddress", IpAddress); if (dr != null) { DataSource.Rows.Remove(dr); DataSource.AcceptChanges(); } //Return to the InitialStatus Act = action.FirstOrFinished; mdlStatic.SetMsg(lblMsg,"Đã xóa Server có mã: " + IpAddress + " ra khỏi hệ thống.",false); SetControlStatus(); CurrentCellChanged(); } else//Có lỗi xảy ra { switch (DeleteResult) { case ActionResult.DataHasUsedinAnotherTable: mdlStatic.SetMsg(lblMsg,"Server có mã: " + IpAddress + " đã được sử dụng trong bảng khác nên bạn không thể xóa!",true); break; default: mdlStatic.SetMsg(lblMsg,"Lỗi khi xóa Server. Liên hệ với VBIT",true); break; } } } break; default: break; } }
void Send2DicomPrinter_cfprint() { try { DataTable DataSource = new ServerController().GetDcmPrinterList().Tables[0]; if (DataSource == null || DataSource.Rows.Count <= 0) return; DataRow dr = DataSource.Rows[0]; AppLogger.LogAction.AddLog2List(lstFPD560, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": Print Img using ClearCanvas"); LocalAETitle = dr["CallingAETitle"].ToString(); printerName = dr["ServerName"].ToString(); RemoteAETitle = dr["CalledAETitle"].ToString(); RemoteHost = dr["IPAddress"].ToString(); Port = Convert.ToInt32(dr["Port"]); TimeOut = Convert.ToInt32(dr["TimeOut"]); FilmSizeID = Utility.sDbnull(dr["FilmSize"], "10INX12IN"); NumberOfCopies = 1; string ErrorMsg = ""; string SuccessConnect = ""; if (htbFiles.Count <= 0) { new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "THÔNG BÁO", "INFORMATION"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Chưa có ảnh in Film. Đề nghị xem lại", "No images to print. Pls check again..."), "ĐÃ HIỂU", "THOÁT").ShowDialog(); return; } try { VietBaIT.DICOM.Print newPrinter = new VietBaIT.DICOM.Print(RemoteHost, Port, RemoteAETitle, LocalAETitle); //Thử kết nối string ErrMsg = ""; if (_AppMode == AppType.AppEnum.AppMode.Demo) { new RegDetailController().InsertPrintLog(htbDetail, FilmSizeID, printerName, RemoteHost, DateTime.Now.ToString("dd/MM/yyyy"), globalVariables.UserName, rePrint); } else { //if (!newPrinter.isActive(60, ref ErrMsg)) //{ // ErrorMsg = "Không thể kết nối tới Server " + RemoteHost + "(Port=" + Port.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Nội dung lỗi:" + ErrMsg + "\n"; // string En_ErrorMsg = "Could not connect to Server " + RemoteHost + "(Port=" + Port.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Error content:" + ErrMsg + "\n"; // new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "THÔNG BÁO", "INFORMATION"), MultiLanguage.GetText(globalVariables.DisplayLanguage, ErrorMsg, En_ErrorMsg), "ĐÃ HIỂU", "THOÁT").ShowDialog(); //} //else //{ string newErrMsg = ""; new RegDetailController().InsertPrintLog(htbDetail, FilmSizeID, printerName, RemoteHost, DateTime.Now.ToString("dd/MM/yyyy"), globalVariables.UserName, rePrint); SuccessConnect += RemoteHost + ","; newPrinter.SendtoDicomPrinter(htbFiles, 1, 1, NumberOfCopies, FilmSizeID, FilmOrientation, TimeOut, ref newErrMsg); //if (newErrMsg.Trim() != "" && !newErrMsg.ToUpper().Contains("SUCCESS")) //{ // ErrorMsg = "Không thể kết nối tới Server " + RemoteHost + "(Port=" + Port.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Nội dung lỗi:" + newErrMsg + "\n"; // string En_ErrorMsg = "Could not connect to Server " + RemoteHost + "(Port=" + Port.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Error content:" + newErrMsg + "\n"; // new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "THÔNG BÁO", "INFORMATION"), MultiLanguage.GetText(globalVariables.DisplayLanguage, ErrorMsg, En_ErrorMsg), "ĐÃ HIỂU", "THOÁT").ShowDialog(); //} //else //{ // SuccessConnect += RemoteHost + ","; //} //} } } catch (Exception ex1) { //throw ex1; } } catch (Exception ex) { // throw ex; } finally { } }
/// <summary> /// Trả về đối tượng Infor dựa vào Primary key của nó /// </summary> /// <param name="ID"></param> /// <returns></returns> public static ServerInfor GetInfor(int ID) { DataSet ds = new ServerController().GetData("ID=" + ID); ServerInfor Infor = new ServerInfor(); if (ds != null) { if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { Infor.ID = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["ID"]); Infor.IpAddress = Utility.sDbnull(ds.Tables[0].Rows[0]["IpAddress"]); Infor.CalledAETitle = Utility.sDbnull(ds.Tables[0].Rows[0]["CalledAETitle"]); Infor.LocalAddress = Utility.sDbnull(ds.Tables[0].Rows[0]["LocalAddress"]); Infor.LocalPort = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["LocalPort"]); Infor.Port = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Port"]); Infor.TimeOut = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["TimeOut"]); Infor.IsActive = Convert.ToByte(ds.Tables[0].Rows[0]["IsActive"]); Infor.ServerType = Convert.ToByte(ds.Tables[0].Rows[0]["ServerType"]); Infor.CallingAETitle = Utility.sDbnull(ds.Tables[0].Rows[0]["CallingAETitle"]); return Infor; } else { return null; } } else { return null; } }
void Send2DicomPrinter() { try { DataTable DataSource = new ServerController().GetDcmPrinterList().Tables[0]; if (DataSource == null || DataSource.Rows.Count <= 0) return; DataRow dr = DataSource.Rows[0]; AppLogger.LogAction.AddLog2List(lstFPD560, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": Print Img using Leadtools"); LocalAETitle = dr["CallingAETitle"].ToString(); printerName = dr["ServerName"].ToString(); RemoteAETitle = dr["CalledAETitle"].ToString(); RemoteHost = dr["IPAddress"].ToString(); PrinterPort = Convert.ToInt32(dr["Port"]); TimeOut = Convert.ToInt32(dr["TimeOut"]); FilmSizeID = Utility.sDbnull(dr["FilmSize"], "10INX12IN"); NumberOfCopies = 1; string ErrorMsg = ""; string SuccessConnect = ""; if (htbFiles.Count <= 0) { new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "THÔNG BÁO", "INFORMATION"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Chưa có ảnh in Film. Đề nghị xem lại", "No images to print. Pls check again..."), "ĐÃ HIỂU", "THOÁT").ShowDialog(); return; } try { Printer.Dicom newPrinter = new Printer.Dicom(this, printerName, RemoteHost, PrinterPort, RemoteAETitle, LocalAETitle); //Thử kết nối string ErrMsg = ""; if (_AppMode == AppType.AppEnum.AppMode.Demo) { new RegDetailController().InsertPrintLog(htbDetail, FilmSizeID, printerName, RemoteHost, DateTime.Now.ToString("dd/MM/yyyy"), globalVariables.UserName, rePrint); } if (!newPrinter.isActive(60, ref ErrMsg)) { ErrorMsg = "Không thể kết nối tới Server " + RemoteHost + "(Port=" + PrinterPort.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Nội dung lỗi:" + ErrMsg + "\n"; string En_ErrorMsg = "Could not connect to Server " + RemoteHost + "(Port=" + PrinterPort.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Error content:" + ErrMsg + "\n"; new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "THÔNG BÁO", "INFORMATION"), MultiLanguage.GetText(globalVariables.DisplayLanguage, ErrorMsg, En_ErrorMsg), "ĐÃ HIỂU", "THOÁT").ShowDialog(); } else { string newErrMsg = ""; //Cập nhật PrintLog if (_AppMode ==AppType.AppEnum.AppMode.License) new RegDetailController().InsertPrintLog(htbDetail, FilmSizeID, printerName, RemoteHost, DateTime.Now.ToString("dd/MM/yyyy"), globalVariables.UserName, rePrint); SuccessConnect += RemoteHost + ","; newPrinter.SendtoDicomPrinter((Hashtable)htbFiles.Clone(), 1, 1, "", "", "", DepartmentName, DateTime.Now.ToString("dd/MM/yyyy hh24:mm:ss"), NumberOfCopies, FilmSizeID, FilmOrientation.ToUpper(), TimeOut, ref newErrMsg); if (newErrMsg.Trim() != "") { ErrorMsg = "Không thể kết nối tới Server " + RemoteHost + "(Port=" + PrinterPort.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Nội dung lỗi:" + newErrMsg + "\n"; string En_ErrorMsg = "Could not connect to Server " + RemoteHost + "(Port=" + PrinterPort.ToString() + ",RemoteAETitle=" + RemoteAETitle + ",LocalAETitle=" + LocalAETitle + ").Error content:" + newErrMsg + "\n"; new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "THÔNG BÁO", "INFORMATION"), MultiLanguage.GetText(globalVariables.DisplayLanguage, ErrorMsg, En_ErrorMsg), "ĐÃ HIỂU", "THOÁT").ShowDialog(); } else { } } } catch (Exception ex1) { } } catch (Exception ex) { new frm_LargeMsgBoxOK("Thông báo", "Lỗi khi in film \n" + ex.ToString(), "ĐÃ HIỂU", "THOÁT").ShowDialog(); } finally { rePrint = false; } }