public void InitThongTin(Thuoc304 oThuoc) { //btnAddFromDmByt.Enabled = oThuoc != null; InitControl(); this.Entity = oThuoc; if (Entity == null) { Entity = new Thuoc304() { ID = Guid.NewGuid() }; _giaThuoc = new GiaThuoc() { ID = Guid.NewGuid(), ThuocID = Entity.ID }; return; } _giaThuoc = KhoUtil.GetGiaThuoc(Entity.ID); if (_giaThuoc == null) { _giaThuoc = new GiaThuoc() { ID = Guid.NewGuid(), ThuocID = Entity.ID }; } _lstDonVis = KhoUtil.GetChuyenDoiDonViThuoc(Entity.ID); txtTenThuoc.Text = Entity.TEN_THUOC; txtSoDangKy.Text = Entity.SO_DANG_KY; txtHoatChat.Text = Entity.HOAT_CHAT; txtHamLuong.Text = Entity.HAM_LUONG; cboDuongDung.Text = Entity.DUONG_DUNG; txtDongGoi.Text = Entity.DONG_GOI; cboHoTriLieu.Text = Entity.HO_TRI_LIEU; //Đơn vị tính giá cboDonVi.Value = _giaThuoc.DonViID; txtGiaDichVu.Text = _giaThuoc.GiaDichVu.ToString(); txtGiaBH.Text = _giaThuoc.GiaBaoHiem.ToString(); txtGiaCB.Text = _giaThuoc.GiaChinhSach.ToString(); var lstChuyenDoiDonViThuoc = KhoUtil.GetChuyenDoiDonViThuoc(Entity.ID).OrderBy(d => d.TiLeChuyenDoi).ToList(); int i = 0; foreach (var item in lstChuyenDoiDonViThuoc) { i++; object[] arr = new object[] { i.ToString(), item.DonViID, item.TiLeChuyenDoi, item.PhuongThucChuyenDoi == 0? "Chia" : "Nhân", item.MoTa }; int index = dataGridView1.Rows.Add(arr); dataGridView1.Rows[index].Tag = item; } }
private GiaThuoc GetFormGiaThuoc() { GiaThuoc g = new GiaThuoc(); g.MaGiaThuoc = int.Parse(txtMagiathuoc.Text); g.MaThuoc = int.Parse(txtMathuoc.Text); g.GiaNhap = float.Parse(txtGianhap.Text); g.GiaXuat = float.Parse(txtGiaxuat.Text); g.NgayCapNhat = DateTime.Parse(dtNgaycapnhat.Text); return(g); }
private void gridView2_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if (gridView2.SelectedRowsCount > 0) { GiaThuoc g = (GiaThuoc)gridView2.GetRow(gridView2.GetSelectedRows()[0]); txtMagiathuoc.Text = g.MaGiaThuoc.ToString(); txtGianhap.Text = g.GiaNhap.ToString(); txtGiaxuat.Text = g.GiaXuat.ToString(); dtNgaycapnhat.Text = g.NgayCapNhat.ToShortDateString(); } }
internal static void SaveThuoc304(Thuoc304 oThuoc, GiaThuoc oGiaThuoc, List <ChuyenDoiDonViThuoc> lstDonVi) { try { KhoConnector.SaveThuoc304(oThuoc, oGiaThuoc, lstDonVi); } catch (Exception ex) { throw; } }
private void txtMathuoc_TextChanged(object sender, EventArgs e) { try { GiaThuoc g = gt.GetLast(int.Parse(txtMathuoc.Text), "GiaThuocMaThuoc"); txtGia.Text = g.GiaXuat.ToString(); } catch (Exception) { XtraMessageBox.Show("Chưa có thông tin giá thuốc"); } }
private void txtMathuoc_EditValueChanged(object sender, EventArgs e) { GiaThuoc g = new GiaThuoc(); if (txtMathuoc.Text != "") { g = gt.GetLast(txtMathuoc.Text, "GiaThuocMaThuoc"); } if (g != null) { Thuoc t = th.SelectByID(int.Parse(txtMathuoc.Text))[0]; txtMagiathuoc.Text = g.MaGiaThuoc.ToString(); txtMathuoc.Text = g.MaThuoc.ToString(); txtGianhap.Text = g.GiaNhap.ToString(); txtGiaxuat.Text = g.GiaXuat.ToString(); dtNgaycapnhat.Text = g.NgayCapNhat.ToShortDateString(); txtTenthuoc.Text = t.TenThuoc; } LoadGiaThuoc(); }
public static Result InsertGiaThuoc(GiaThuoc giaThuoc) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); string desc = string.Empty; using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew)) { //Insert if (giaThuoc.GiaThuocGUID == null || giaThuoc.GiaThuocGUID == Guid.Empty) { giaThuoc.GiaThuocGUID = Guid.NewGuid(); db.GiaThuocs.InsertOnSubmit(giaThuoc); db.SubmitChanges(); //Tracking desc += string.Format("- GUID: '{0}', Thuốc: '{1}', Giá bán: '{2}', Ngày áp dụng: '{3}'", giaThuoc.GiaThuocGUID.ToString(), giaThuoc.Thuoc.TenThuoc, giaThuoc.GiaBan, giaThuoc.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss")); 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 thông tin giá thuốc"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.Price; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } else //Update { GiaThuoc gt = db.GiaThuocs.SingleOrDefault <GiaThuoc>(g => g.GiaThuocGUID.ToString() == giaThuoc.GiaThuocGUID.ToString()); if (gt != null) { double giaCu = gt.GiaBan; gt.ThuocGUID = giaThuoc.ThuocGUID; gt.GiaBan = giaThuoc.GiaBan; gt.NgayApDung = giaThuoc.NgayApDung; gt.Note = giaThuoc.Note; gt.CreatedDate = giaThuoc.CreatedDate; gt.CreatedBy = giaThuoc.CreatedBy; gt.UpdatedDate = giaThuoc.UpdatedDate; gt.UpdatedBy = giaThuoc.UpdatedBy; gt.DeletedDate = giaThuoc.DeletedDate; gt.DeletedBy = giaThuoc.DeletedBy; gt.Status = giaThuoc.Status; db.SubmitChanges(); //Tracking desc += string.Format("- GUID: '{0}', Thuốc: '{1}', Giá bán: cũ: '{2}' - mới: '{3}', Ngày áp dụng: '{4}'", gt.GiaThuocGUID.ToString(), gt.Thuoc.TenThuoc, giaCu, gt.GiaBan, gt.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss")); 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 thông tin giá thuốc"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.Price; tk.ComputerName = Utility.GetDNSHostName(); db.Trackings.InsertOnSubmit(tk); db.SubmitChanges(); } } tnx.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 DeleteGiaThuoc(List <string> giaThuocKeys) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew)) { string desc = string.Empty; foreach (string key in giaThuocKeys) { GiaThuoc giaThuoc = db.GiaThuocs.SingleOrDefault <GiaThuoc>(g => g.GiaThuocGUID.ToString() == key); if (giaThuoc != null) { giaThuoc.DeletedDate = DateTime.Now; giaThuoc.DeletedBy = Guid.Parse(Global.UserGUID); giaThuoc.Status = (byte)Status.Deactived; desc += string.Format("- GUID: '{0}', Thuốc: '{1}', Giá bán: '{2}', Ngày áp dụng: '{3}'\n", giaThuoc.GiaThuocGUID.ToString(), giaThuoc.Thuoc.TenThuoc, giaThuoc.GiaBan, giaThuoc.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss")); } } //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 thông tin giá thuốc"; tk.Description = desc; tk.TrackingType = (byte)TrackingType.Price; 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 void SaveThuoc304(Thuoc304 oThuoc, GiaThuoc oGiaThuoc, List <ChuyenDoiDonViThuoc> lstDonVi) { try { var thuoc = KhoTongProvider.KhoTong.Thuoc304.FirstOrDefault(t => t.ID == oThuoc.ID); if (thuoc == null) { KhoTongProvider.KhoTong.Thuoc304.Add(oThuoc); } else { thuoc.TEN_THUOC = oThuoc.TEN_THUOC; thuoc.SO_DANG_KY = oThuoc.SO_DANG_KY; thuoc.HOAT_CHAT = oThuoc.HOAT_CHAT; thuoc.HAM_LUONG = oThuoc.HAM_LUONG; thuoc.DUONG_DUNG = oThuoc.DUONG_DUNG; thuoc.DONG_GOI = oThuoc.DONG_GOI; thuoc.HO_TRI_LIEU = oThuoc.HO_TRI_LIEU; } KhoTongProvider.KhoTong.SaveChanges(); var giaThuoc = KhoTongProvider.KhoTong.GiaThuoc.FirstOrDefault(t => t.ThuocID == oGiaThuoc.ThuocID); if (giaThuoc == null) { KhoTongProvider.KhoTong.GiaThuoc.Add(oGiaThuoc); } else { giaThuoc.DonViID = oGiaThuoc.DonViID; giaThuoc.GiaBaoHiem = oGiaThuoc.GiaBaoHiem; giaThuoc.GiaChinhSach = oGiaThuoc.GiaChinhSach; giaThuoc.GiaDichVu = oGiaThuoc.GiaDichVu; giaThuoc.ThuocID = oGiaThuoc.ThuocID; } //Save don vi chuyen doi var removeDonvi = KhoTongProvider.KhoTong.ChuyenDoiDonViThuoc.Where(d => d.ThuocID == oThuoc.ID).ToList(); foreach (var dv in lstDonVi) { var donvi = KhoTongProvider.KhoTong.ChuyenDoiDonViThuoc.FirstOrDefault(d => d.ID == dv.ID); if (donvi == null) { removeDonvi.RemoveAll(d => d.ID == dv.ID); KhoTongProvider.KhoTong.ChuyenDoiDonViThuoc.Add(dv); } else { donvi.DonViID = dv.DonViID; donvi.TiLeChuyenDoi = dv.TiLeChuyenDoi; donvi.PhuongThucChuyenDoi = dv.PhuongThucChuyenDoi; donvi.MoTa = dv.MoTa; } } foreach (var item in removeDonvi) { KhoTongProvider.KhoTong.ChuyenDoiDonViThuoc.RemoveRange(removeDonvi); } KhoTongProvider.KhoTong.SaveChanges(); } catch (Exception ex) { throw; } }
private void SaveEntity() { Thuoc304 oThuoc = new Thuoc304(); oThuoc.ID = Entity.ID; oThuoc.TEN_THUOC = txtTenThuoc.Text; oThuoc.SO_DANG_KY = txtSoDangKy.Text; oThuoc.HOAT_CHAT = txtHoatChat.Text; oThuoc.HAM_LUONG = txtHamLuong.Text; oThuoc.DUONG_DUNG = cboDuongDung.Text; oThuoc.DONG_GOI = txtDongGoi.Text; oThuoc.HO_TRI_LIEU = cboHoTriLieu.Text; oThuoc.DonViID = (Guid)cboDonVi.Value; GiaThuoc oGiaThuoc = new GiaThuoc(); if (_giaThuoc.ID == Guid.Empty) { _giaThuoc.ID = Guid.NewGuid(); _giaThuoc.ThuocID = oThuoc.ID; } oGiaThuoc.ID = _giaThuoc.ID; oGiaThuoc.ThuocID = oThuoc.ID; oGiaThuoc.DonViID = (Guid)cboDonVi.Value; oGiaThuoc.GiaDichVu = decimal.Parse(txtGiaDichVu.Text); oGiaThuoc.GiaBaoHiem = decimal.Parse(txtGiaBH.Text); oGiaThuoc.GiaChinhSach = decimal.Parse(txtGiaCB.Text); //Don vi chuyen doi List <ChuyenDoiDonViThuoc> lstDonVi = new List <ChuyenDoiDonViThuoc>(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { ChuyenDoiDonViThuoc oDonVi = null; var row = dataGridView1.Rows[i]; if (row.Tag == null) { oDonVi = new ChuyenDoiDonViThuoc(); oDonVi.ID = Guid.NewGuid(); } else { oDonVi = row.Tag as ChuyenDoiDonViThuoc; } oDonVi.ThuocID = oThuoc.ID; oDonVi.DonViID = (Guid)row.Cells[1].Value; oDonVi.TiLeChuyenDoi = int.Parse(row.Cells[2].Value.ToString()); oDonVi.PhuongThucChuyenDoi = row.Cells[3].Value.ToString() == "Chia" ? (byte)0 : (byte)1; oDonVi.MoTa = row.Cells[4].Value.ToString(); lstDonVi.Add(oDonVi); } //Save data KhoUtil.SaveThuoc304(oThuoc, oGiaThuoc, lstDonVi); //Update cached var item = KhoUtil.GetDanhMuc <Thuoc304>().FirstOrDefault(t => t.ID == oThuoc.ID); if (item == null) { KhoUtil.GetDanhMuc <Thuoc304>().Add(item); } else { item = oThuoc; } }