Beispiel #1
0
        private void InitializeData()
        {
            // Init data
            if (this._mode == ViewModes.Add)
            {
                // Medicine plan
                this._medicinePlan          = new Data.Entities.MedicinePlan();
                this._medicinePlan.Date     = DateTime.Today;
                this._medicinePlan.ClinicId = AppContext.CurrentClinic.Id;

                var date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1, 0, 0, 0);
                date = date.AddMonths(1);
                this._medicinePlan.Month  = date.Month;
                this._medicinePlan.Year   = date.Year;
                this._medicinePlan.Status = 0;

                ReloadPlannedInfo();
            }
            else
            {
                this._medicinePlan = this._planingRepo.Get(this._planningId);
                if (this._medicinePlan == null)
                {
                    throw new Exception("Dự trù thuốc không tồn tại");
                }
                bdsPlanning.DataSource = this._medicinePlan;

                this._medicinePlanDetails = this._planingDetailRepo.GetByPlanId(this._planningId);
                var medicines = this._medicineRepo.GetAll();

                foreach (var planDetail in _medicinePlanDetails)
                {
                    foreach (var medicine in medicines)
                    {
                        if (medicine.Id != planDetail.MedicineId)
                        {
                            continue;
                        }
                        planDetail.TradeName    = medicine.TradeName;
                        planDetail.MedicineName = medicine.Define.Name;

                        var medicinePlanDetail = new MedicinePlanDetail
                        {
                            MedicineId   = medicine.Id,
                            Version      = 0,
                            MedicineName = medicine.Name,
                            UnitName     = medicine.Define.Name,
                            TradeName    = medicine.TradeName
                        };
                    }
                }

                bdsPlanningDetail.DataSource = this._medicinePlanDetails;

                this.txtYear.Enabled  = false;
                this.txtMonth.Enabled = false;
            }
        }
 public void Insert(MedicinePlan MedicinePlan)
 {
     MedicinePlan.CreatedDate = DateTime.Now;
     MedicinePlan.CreatedUser = AppContext.LoggedInUser.Id;
     MedicinePlan.LastUpdatedDate = DateTime.Now;
     MedicinePlan.LastUpdatedUser = AppContext.LoggedInUser.Id;
     MedicinePlan.Version = 0;
     this.Context.MedicinePlans.Add(MedicinePlan);
     this.Context.SaveChanges();
 }
        private void InitializeData()
        {
            // Init data
            if (this._mode == ViewModes.Add)
            {
                // Medicine plan
                this._medicinePlan = new Data.Entities.MedicinePlan();
                this._medicinePlan.Date = DateTime.Today;
                this._medicinePlan.ClinicId = AppContext.CurrentClinic.Id;

                var date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1, 0, 0, 0);
                date = date.AddMonths(1);
                this._medicinePlan.Month = date.Month;
                this._medicinePlan.Year = date.Year;
                this._medicinePlan.Status = 0;

                ReloadPlannedInfo();
            }
            else
            {
                this._medicinePlan = this._planingRepo.Get(this._planningId);
                if (this._medicinePlan == null) throw new Exception("Dự trù thuốc không tồn tại");
                bdsPlanning.DataSource = this._medicinePlan;

                this._medicinePlanDetails = this._planingDetailRepo.GetByPlanId(this._planningId);
                var medicines = this._medicineRepo.GetAll();

                foreach (var planDetail in _medicinePlanDetails)
                {
                    foreach (var medicine in medicines)
                    {
                        if (medicine.Id != planDetail.MedicineId) continue;
                        planDetail.TradeName = medicine.TradeName;
                        planDetail.MedicineName = medicine.Define.Name;

                        var medicinePlanDetail = new MedicinePlanDetail
                                                     {
                                                         MedicineId = medicine.Id,
                                                         Version = 0,
                                                         MedicineName = medicine.Name,
                                                         UnitName = medicine.Define.Name,
                                                         TradeName = medicine.TradeName
                                                     };
                    }

                }

                bdsPlanningDetail.DataSource = this._medicinePlanDetails;

                this.txtYear.Enabled = false;
                this.txtMonth.Enabled = false;
            }
        }
        public void Insert(MedicinePlan medicinePlan, List<MedicinePlanDetail> medicinePlanDetails)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                medicinePlan.SetInfo(false);
                this.Context.MedicinePlans.Add(medicinePlan);
                this.Context.SaveChanges();

                foreach (var detail in medicinePlanDetails)
                {
                    detail.PlanId = medicinePlan.Id;
                    detail.SetInfo(false);
                    this.Context.MedicinePlanDetails.Add(detail);
                }
                this.Context.SaveChanges();
                scope.Complete();
            }
        }
        private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                Medical.Data.Entities.MedicinePlan medicinePlan = repMedicinePlan.GetById(PlanId);
                // medicinePlan.Status = cboStatus.SelectedItem.ToString();
                medicinePlan.Date = DateTime.Now;
                medicinePlan.Note = txtNote.Text;

                if (IsOwner)
                {
                    medicinePlan.Year  = int.Parse(cboYear.SelectedItem.ToString());
                    medicinePlan.Month = int.Parse(cboMonth.SelectedItem.ToString());

                    foreach (DataGridViewRow row in grd.Rows)
                    {
                        int id = int.Parse(row.Cells["Id"].Value.ToString());
                        MedicinePlanDetail item = repMedicinePlanDetail.GetById(id);
                        if (row.Cells["Required"].Value != null)
                        {
                            item.Required = int.Parse(row.Cells["Required"].Value.ToString());
                        }
                        else
                        {
                            item.Required = 0;
                        }

                        repMedicinePlanDetail.Update(item);
                    }
                }

                repMedicinePlan.Update(medicinePlan);

                // Status = medicinePlan.Status;
                MessageBox.Show("Tạo kế hoạch thành công!");
                this.Close();
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #6
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                //Insert data to MedicinePlan
                Medical.Data.Entities.MedicinePlan medicinePlan = new Medical.Data.Entities.MedicinePlan();
                medicinePlan.Year  = int.Parse(cboYear.SelectedItem.ToString());
                medicinePlan.Month = int.Parse(cboMonth.SelectedItem.ToString());
                // medicinePlan.Status = Constants.Status_Wait;
                medicinePlan.Date     = DateTime.Now;
                medicinePlan.Note     = txtNote.Text;
                medicinePlan.ClinicId = int.Parse(cbClinic.SelectedValue.ToString());
                repMedicinePlan.Insert(medicinePlan);

                //Insert data to MedicinePlanDetail
                foreach (DataGridViewRow row in grd.Rows)
                {
                    if (ValidateRowData(row))
                    {
                        MedicinePlanDetail item = new MedicinePlanDetail();
                        item.PlanId            = medicinePlan.Id;
                        item.MedicineId        = int.Parse(row.Cells["MedicineId"].Value.ToString());
                        item.InStock           = int.Parse(row.Cells["InStock"].Value.ToString());
                        item.LastMonthUsage    = int.Parse(row.Cells["LastMonthUsage"].Value.ToString());
                        item.CurrentMonthUsage = int.Parse(row.Cells["CurrentMonthUsage"].Value.ToString());
                        item.Required          = int.Parse(row.Cells["Required"].Value.ToString());
                        repMedicinePlanDetail.Insert(item);
                    }
                }

                MessageBox.Show("Tạo kế hoạch thành công!");
                grd.DataSource = new List <MedicinePlanDetail>();
            }
            catch (Exception ex)
            {
            }
        }
        private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                //Insert data to MedicinePlan
                Medical.Data.Entities.MedicinePlan medicinePlan = new Medical.Data.Entities.MedicinePlan();
                medicinePlan.Year = int.Parse(cboYear.SelectedItem.ToString());
                medicinePlan.Month = int.Parse(cboMonth.SelectedItem.ToString());
                // medicinePlan.Status = Constants.Status_Wait;
                medicinePlan.Date = DateTime.Now;
                medicinePlan.Note = txtNote.Text;
                medicinePlan.ClinicId = int.Parse(cbClinic.SelectedValue.ToString());
                repMedicinePlan.Insert(medicinePlan);

                //Insert data to MedicinePlanDetail
                foreach (DataGridViewRow row in grd.Rows)
                {
                    if (ValidateRowData(row))
                    {
                        MedicinePlanDetail item = new MedicinePlanDetail();
                        item.PlanId = medicinePlan.Id;
                        item.MedicineId = int.Parse(row.Cells["MedicineId"].Value.ToString());
                        item.InStock = int.Parse(row.Cells["InStock"].Value.ToString());
                        item.LastMonthUsage = int.Parse(row.Cells["LastMonthUsage"].Value.ToString());
                        item.CurrentMonthUsage = int.Parse(row.Cells["CurrentMonthUsage"].Value.ToString());
                        item.Required = int.Parse(row.Cells["Required"].Value.ToString());
                        repMedicinePlanDetail.Insert(item);
                    }
                }

                MessageBox.Show("Tạo kế hoạch thành công!");
                grd.DataSource = new List<MedicinePlanDetail>();
            }
            catch (Exception ex)
            {

            }
        }
 /// <summary>
 /// Updates the specified medicine plan.
 /// </summary>
 /// <param name="medicinePlan">The medicine plan.</param>
 public void Update(MedicinePlan medicinePlan)
 {
     var oldMedicinePlan = this.Context.MedicinePlans.FirstOrDefault(x => x.Id == medicinePlan.Id);
     if (oldMedicinePlan == null) return;
     oldMedicinePlan.Year = medicinePlan.Year;
     oldMedicinePlan.Month = medicinePlan.Month;
     oldMedicinePlan.Date = medicinePlan.Date;
     oldMedicinePlan.ClinicId = medicinePlan.ClinicId;
     oldMedicinePlan.ApproveId = medicinePlan.ApproveId;
     oldMedicinePlan.Status = medicinePlan.Status;
     oldMedicinePlan.Note = medicinePlan.Note;
     oldMedicinePlan.LastUpdatedUser = AppContext.LoggedInUser.Id;
     oldMedicinePlan.LastUpdatedDate = DateTime.Now;
     oldMedicinePlan.Version++;
     this.Context.SaveChanges();
 }
        /// <summary>
        /// Updates the specified medicine plan.
        /// </summary>
        /// <param name="medicinePlan">The medicine plan.</param>
        /// <param name="medicinePlanDetails">The medicine plan details.</param>
        /// <exception cref="System.Exception">Dự trù không tồn tại</exception>
        public void Update(MedicinePlan medicinePlan, List<MedicinePlanDetail> medicinePlanDetails)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                var plan = this.Context.MedicinePlans.FirstOrDefault(x => x.Id == medicinePlan.Id);
                if (plan == null) throw new Exception("Dự trù không tồn tại");
                plan.Note = medicinePlan.Note;
                plan.Status = MedicinePlaningStatus.ReEdited;
                plan.SetInfo(true);

                var detailList =this.Context.MedicinePlanDetails.Where(x => x.PlanId == plan.Id).ToList();
                foreach (var detail in medicinePlanDetails)
                {
                    foreach (var original in detailList)
                    {
                        if (original.Id != detail.Id) continue;
                        original.Required = detail.Required;
                        original.SetInfo(true);
                        break;
                    }
                }
                this.Context.SaveChanges();
                scope.Complete();
            }
        }