Beispiel #1
0
        public static void Run(Apteka.SqlServer.AptekaSqlServerDbContext sqlDb, MyDbContext pgDb)
        {
            var dlist = sqlDb.spDrugs
                                     .Include(x => x.Manufacturer)
                                     .Include(x => x.DrugCategory)
                                     .Include(x => x.PharmGroup)
                                     .Include(x => x.Unit).AsNoTracking().ToList();
            spManufacturer sm = null;
            spDrugCategory sd = null;
            spPharmGroup sp = null;
            spUnit su = null;

            foreach (var it in dlist)
            {

                if (it.Manufacturer != null)
                {
                    sm = new spManufacturer();
                   // sm.Id = it.Manufacturer.ServerId ?? it.Manufacturer.ServerId.Value;
                    sm.CountryId = it.Manufacturer.CountryId;
                    sm.Name = it.Manufacturer.Name;
                    sm.CreateDate = DateTime.Now;
                    sm.CreateUser = 1;
                    sm.Status = 1;
                }

                if (it.DrugCategory != null)
                {
                    sd = new spDrugCategory();
                   // sd.Id = it.DrugCategory.ServerId ?? it.DrugCategory.ServerId.Value;
                    sd.Name = it.DrugCategory.Name;
                    sd.CreateDate = DateTime.Now;
                    sd.CreateUser = 1;
                    sd.Status = 1;
                }

                if (it.PharmGroup != null)
                {
                    sp = new spPharmGroup();
                   // sp.Id = it.PharmGroup.ServerId ?? it.PharmGroup.ServerId.Value;
                    sp.Name = it.PharmGroup.Name;
                    sp.CreateDate = DateTime.Now;
                    sp.CreateUser = 1;
                    sp.Status = 1;
                }

                if (it.Unit != null)
                {
                    su = new spUnit();
                    //su.Id = it.Unit.ServerId ?? it.Unit.ServerId.Value;
                    su.Name = it.Unit.Name;
                    su.Impartible = it.Unit.Impartible;
                    su.CreateDate = DateTime.Now;
                    su.CreateUser = 1;
                    su.Status = 1;
                }

                if (it.ServerId == null) continue;

                var di = new spDrug();
                di.Id = it.ServerId??it.ServerId.Value;
                di.Barcode = it.Barcode;
                di.Name = it.Name;
                di.Description = it.Description;
                di.InternationalName = it.InternationalName;
                di.Dose = it.Dose;
                di.Manufacturer = sm;
                di.DrugCategory = sd;
                di.PharmGroup = sp;
                di.Unit = su;
                di.Piece = it.Piece;
                di.Special = 0;
                di.Photo = it.Photo;
                di.VatRate = it.VatRate;
                di.DrugRecomendation = it.DrugRecomendation;
                di.Status = 1;
                di.CreateDate = DateTime.Now;
                di.CreateUser = 1;

                pgDb.spDrugs.Add(di);
            }

            pgDb.ChangeTracker.DetectChanges();
            pgDb.SaveChanges();
        }
Beispiel #2
0
        private void OnBtnSpListAdd(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            FrmNewSp f;

            try
            {
                if (e.Button.Index == 1)
                {
                    int i = e.Button.Tag.ToInt();

                    switch (i)
                    {
                    case 1:
                        var fm = new FrmNewManufacturer();

                        if (!string.IsNullOrWhiteSpace(drug.PriceManufacturer))
                        {
                            fm.edName.Text = drug.PriceManufacturer;
                        }

                        if (fm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            cbManufacturer.Properties.DataSource = db.Manufacturer.GetSp();
                            AlertMessage.Show("Данные успешно сохранены");
                        }
                        break;

                    case 2:
                        f = new FrmNewSp();
                        if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var name = f.edName.Text;
                            if (!string.IsNullOrWhiteSpace(name))
                            {
                                var ss = new spDrugCategory();
                                ss.Id         = Guid.NewGuid();
                                ss.Name       = name;
                                ss.Status     = 1;
                                ss.CreateUser = Vars.UserId;
                                ss.CreateDate = DateTime.Now;
                                db.DrugCategory.Add(ss);
                                db.Complete();
                                cbDrugCategory.Properties.DataSource = db.DrugCategory.GetSp();
                                AlertMessage.Show("Данные успешно сохранены");
                            }
                        }
                        f.Dispose();
                        break;

                    case 3:
                        f = new FrmNewSp();
                        if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var name = f.edName.Text;
                            if (!string.IsNullOrWhiteSpace(name))
                            {
                                var sc = new spPharmGroup();

                                sc.Id         = Guid.NewGuid();
                                sc.Name       = name;
                                sc.Status     = 1;
                                sc.CreateUser = Vars.UserId;
                                sc.CreateDate = DateTime.Now;

                                db.PharmGroup.Add(sc);
                                db.Complete();
                                cbPharmGroup.Properties.DataSource = db.PharmGroup.GetSp();
                                AlertMessage.Show("Данные успешно сохранены");
                            }
                        }
                        f.Dispose();
                        break;

                    case 4:
                        f = new FrmNewSp();
                        if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var name = f.edName.Text;
                            if (!string.IsNullOrWhiteSpace(name))
                            {
                                var su = new spUnit();
                                su.Name       = name;
                                su.Status     = 1;
                                su.CreateUser = Vars.UserId;
                                su.CreateDate = DateTime.Now;
                                db.Unit.Add(su);
                                db.Complete();
                                cbUnit.Properties.DataSource = db.Unit.GetSp();
                                AlertMessage.Show("Данные успешно сохранены");
                            }
                        }
                        f.Dispose();
                        break;
                    }
                }
            }
            catch (System.Exception ee)
            {
                var li = new LogItem
                {
                    App        = "Sklad",
                    Stacktrace = ee.GetStackTrace(5),
                    Message    = ee.GetAllMessages(),
                    Method     = "FrmProductList.OnBtnSpListAdd"
                };
                CLogJson.Write(li);
                AlertMessage.ShowError("Ошибка при сохранении");
            }
        }