public static Result GetNhapKhoCapCuu(string nhapKhoCapCuuGUID) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); NhapKhoCapCuuView nkcc = db.NhapKhoCapCuuViews.SingleOrDefault(n => n.NhapKhoCapCuuGUID.ToString() == nhapKhoCapCuuGUID); result.QueryResult = nkcc; } 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 OnDelete() { if (_dictNhapKhoCapCuu == null) { return; } List <string> deletedList = new List <string>(); List <DataRow> deletedRows = _dictNhapKhoCapCuu.Values.ToList(); foreach (DataRow row in deletedRows) { deletedList.Add(row["NhapKhoCapCuuGUID"].ToString()); } if (deletedList.Count > 0) { foreach (string key in deletedList) { Result rs = NhapKhoCapCuuBus.GetNhapKhoCapCuu(key); if (!rs.IsOK) { MsgBox.Show(Application.ProductName, rs.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuu"), IconType.Error); Utility.WriteToTraceLog(rs.GetErrorAsString("NhapKhoCapCuuBus.GetNhapKhoCapCuu")); return; } NhapKhoCapCuuView nkcc = rs.QueryResult as NhapKhoCapCuuView; if (nkcc.SoLuongXuat > 0) { MsgBox.Show(Application.ProductName, string.Format("Cấp cứu: '{0}' này đã xuất rồi không thể xóa.", nkcc.TenCapCuu), IconType.Information); return; } } if (MsgBox.Question(Application.ProductName, "Bạn có muốn xóa những thông tin nhập kho cấp cứu mà bạn đã đánh dấu ?") == DialogResult.Yes) { Result result = NhapKhoCapCuuBus.DeleteNhapKhoCappCuu(deletedList); if (result.IsOK) { DataTable dt = dgNhapKhoCapCuu.DataSource as DataTable; if (dt == null || dt.Rows.Count <= 0) { return; } foreach (string key in deletedList) { DataRow[] rows = dt.Select(string.Format("NhapKhoCapCuuGUID='{0}'", key)); if (rows == null || rows.Length <= 0) { continue; } dt.Rows.Remove(rows[0]); } _dictNhapKhoCapCuu.Clear(); _dtTemp.Rows.Clear(); } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("NhapKhoCapCuuBus.DeleteNhapKhoCappCuu"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("NhapKhoCapCuuBus.DeleteNhapKhoCappCuu")); } } } else { MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những thông tin nhập kho cấp cứu cần xóa.", IconType.Information); } }