Example #1
0
        private void AddPrescriptionDrugsToDrugList(SavedPrescriptionDrug[] drugs)
        {
            Visit visit = (srcItem.DataSource as Visit);

            for (int i = 0; i < drugs.Length; i++)
            {
                if (!visit.VisitDrugs.Any(d => d.DrugId == drugs[i].DrugId)) // no duplication
                {
                    VisitDrug visitDrug = new VisitDrug();
                    visitDrug.Drug = drugs[i].Drug;
                    visitDrug.CustomManual = drugs[i].CustomManual;
                    visit.VisitDrugs.Add(visitDrug);
                }
            }
        }
        private void btnSaveDrug_Click(object sender, EventArgs e)
        {
            if (cmbDrugs.SelectedItem == null)
            {
                Methods.ShowStandardMsgBox(FormMessageType.Error, "خطا", "لطفا داروی مورد نظر خود را انتخاب نمایید.");
                return;
            }

            Drug item = ((GridViewDataRowInfo)cmbDrugs.SelectedItem).DataBoundItem as Drug;
            if (!EntityValidation.Validate(item))
                return;

            SavedPrescription pres = srcItem.DataSource as SavedPrescription;

            if (EntityValidation.Validate(item, txtManual.Text))
            {
                if ((pres.SavedPrescriptionDrugs.Where(x => x.DrugId == item.Id).SingleOrDefault() == null))
                {
                    SavedPrescriptionDrug newDrug = new SavedPrescriptionDrug() { Drug = item, CustomManual = txtManual.Text };
                    pres.SavedPrescriptionDrugs.Add(newDrug);
                    grvDrugs.CurrentRow = grvDrugs.Rows.Where(x => x.DataBoundItem == newDrug).FirstOrDefault();

                    btnSaveDrug.Enabled = false;
                    cmbDrugs.Enabled = false;
                }

                srcItem.ResetBindings(false);
            }
        }