Example #1
0
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (lvwDrugInList.Items.Count == 0)
            {
                MessageBox.Show("没有要提交的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txtSearch.Focus();
                return;
            }
            storeList.Clear();
            inList.Clear();
            try
            {
                var service = ServiceContainer.GetService <IDrugStoreService>();
                foreach (ListViewItem item in lvwDrugInList.Items)
                {
                    PIn   rin   = item.Tag as PIn;
                    Store store = service.GetDrugStore(rin.Code, rin.DrugID, rin.ChinseName, rin.Spec, rin.TimeLimit);
                    if (store != null)
                    {
                        store.Number = store.Number + rin.Number;
                    }
                    else
                    {
                        store            = new Store();
                        store.Code       = rin.Code;
                        store.ChinseName = rin.ChinseName;
                        store.Spec       = rin.Spec;
                        store.TimeLimit  = rin.TimeLimit;
                        store.DrugID     = rin.DrugID;

                        ColumnCollection cols = rin.GetColumns();
                        foreach (Property prop in cols)
                        {
                            if (store.ContainsProperty(prop.Name))
                            {
                                store[prop.Name] = rin[prop.Name];
                            }
                        }
                        store.ID     = ServiceContainer.GetService <IDrugStoreService>().GetMaxID();
                        store.Number = rin.Number;
                        store.DrugID = rin.DrugID;
                    }
                    storeList.Add(store);
                    inList.Add(rin);
                }
                if (inList.Count > 0)
                {
                    var s = ServiceContainer.GetService <IDrugInService>();
                    s.DrugInSave(inList, storeList);
                    MessageBox.Show("本次药房药品入库成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.lvwDrugInList.Items.Clear();
                }
                this.txtSearch.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "在保存入库记录数据的过程中发生了一个错误:\n" + ex.InnerException.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
            }
        }