Example #1
0
        public InventarizacionnajaVedomost()
        {
            InitializeComponent();
            datePrevInvent = new DateTime();
            using (CRM_magEntities context = new CRM_magEntities())
            {
                try
                {
                    if (context.Materialy.FirstOrDefault().date_ostatok_cur != null)
                    {
                        txtBPrevInvent.Text = ((DateTime)context.spInventVed(dtCurInvent.SelectedDate).FirstOrDefault().date_ostatok_cur).ToString("dd/MM/yyyy");

                        datePrevInvent = (DateTime)context.spInventVed(dtCurInvent.SelectedDate).FirstOrDefault().date_ostatok_cur;
                    }
                    else
                    {
                        btnRun.IsEnabled = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
            }
            Zapoln((DateTime)dtCurInvent.SelectedDate);
        }
        private void MakeFresh()
        {
            lstvClient.ItemsSource = null;

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    var dataClient = from c in contextDB.RequestList
                                     select new
                    {
                        c.id_request,
                        c.famil,
                        c.f_name,
                        c.s_name
                    };
                    listsRLC = new List <RequestListC>();
                    foreach (var itemC in dataClient)
                    {
                        RequestListC rlc = new RequestListC();
                        rlc.IdItem = itemC.id_request;
                        rlc.Client = itemC.famil + " " + itemC.f_name + " " + itemC.s_name;
                        listsRLC.Add(rlc);
                    }
                    lstvClient.ItemsSource       = listsRLC.OrderBy(n => n.Number);
                    lstvClient.SelectedValuePath = "IdItem";
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Example #3
0
        public VvodPervonachalnOstatkov()
        {
            InitializeComponent();
            using (CRM_magEntities context = new CRM_magEntities())
            {
                try
                {
                    lstVvPervOst = new List <InventVed>();

                    foreach (var item in context.Materialy)
                    {
                        InventVed mt = new InventVed();

                        mt.id_material  = item.id_material;
                        mt.artikul      = item.artikul;
                        mt.NameMaterial = item.NameMaterial;
                        mt.id_ed_izm    = item.id_ed_izm;
                        Ed_izm ei = context.Ed_izm.Find(item.id_ed_izm);
                        mt.nameEI = ei.nameEI;
                        if (item.ostatok_cur == null)
                        {
                            mt.ostatok_cur = 0;
                        }

                        lstVvPervOst.Add(mt);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
                dgInventVedomost.ItemsSource = lstVvPervOst;
            }
        }
Example #4
0
        private void IntVedomost_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    Params p = contextDB.Params.Find(1);

                    p.p_date_to = (DateTime)dtCurInvent.SelectedDate;

                    contextDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (_pr != null)
            {
                try
                {
                    _pr.Kill();
                }
                catch { };
            }
            _pr = Process.Start("D:\\Projects\\CRM\\CRM_Access.accdb", "/X mcrIntVedomost");
            //_pr = Process.Start("D:\\Fujitsu\\CRM\\2019-06-12_1\\CRM\\CRM_Access.accdb", "/X mcrIntVedomost");
        }
Example #5
0
        private void btnOtkazyShow_Click(object sender, RoutedEventArgs e)
        {
            dgOtkazy.ItemsSource = null;
            otk = new List <Otkazy>();
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    dOtkFrom = (DateTime)dpOtkazyFrom.SelectedDate;
                    dOtkTo   = (DateTime)dpOtkazyTo.SelectedDate;

                    var v = contextDB.spOtkazy(dOtkFrom, dOtkTo).ToList();

                    foreach (var item in v)
                    {
                        Otkazy o = new Otkazy();

                        o.FIO_zakazchika = item.FIO_zakazchika;

                        o.NumberRequest = item.id_request;
                        o.DateRequest   = (DateTime)item.date_request;
                        o.DateOtkaza    = (DateTime)item.date_otkaza;
                        o.ReasonOtkaza  = item.reason_otkaza;
                        otk.Add(o);
                    }

                    dgOtkazy.ItemsSource = otk;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void TekOstRefresh(DateTime dt)
        {
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    var v = contextDB.spOstatok(dt).ToList().OrderBy(od => od.OstatokDni);

                    foreach (var item in v)
                    {
                        TekOstPoOsnSkl t = new TekOstPoOsnSkl();
                        t.Artikul = item.Artikul;

                        t.Nomenklatura = item.NameMaterial;
                        t.EdIzm        = item.NameEI;
                        t.Kolvo        = Convert.ToDecimal(item.Ostatok);
                        t.SrSutRash    = Convert.ToDecimal(item.SredSytRash);
                        t.OstVDnjah    = Convert.ToDecimal(item.OstatokDni);
                        topos.Add(t);
                    }

                    dgTekOstatki.ItemsSource = topos;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #7
0
        public override ValidationResult Validate(object value,
                                                  System.Globalization.CultureInfo cultureInfo)
        {
            Rashod_2 r_2    = (value as BindingGroup).Items[0] as Rashod_2;
            decimal  kolMat = 0;

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    kolMat = Convert.ToDecimal(contextDB.spInventVed(DateTime.Now).FirstOrDefault().ostatok_new);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (r_2.kol > kolMat)
            {
                MessageBox.Show("На складе " + kolMat.ToString() + ".", "Ошибка!");
                return(new ValidationResult(false,
                                            "Start Date must be earlier than End Date."));
            }
            else
            {
                return(ValidationResult.ValidResult);
            }
        }
        private void btnOborVedPoSkladu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    dateFrom = (DateTime)dtpDateFrom.SelectedDate;
                    dateTo   = (DateTime)dtpDateTo.SelectedDate;
                    Params p = contextDB.Params.Find(1);
                    p.p_date_from = dateFrom;
                    p.p_date_to   = dateTo;
                    contextDB.SaveChanges();

                    var v = contextDB.spOborotkaSklad(dateFrom, dateTo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (_pr != null)
            {
                try
                {
                    _pr.Kill();
                }
                catch { };
            }
            //_pr = Process.Start("D:\\Fujitsu\\CRM\\2019-06-12_1\\CRM\\CRM_Access.accdb", "/X mcrOborotkaSklad");
            _pr = Process.Start("D:\\Projects\\CRM\\CRM_Access.accdb", "/X mcrOborotkaSklad");
        }
Example #9
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    Params p = contextDB.Params.Find(1);

                    p.param_int = Convert.ToInt32(txtBNomerNakladnoj.Text);
                    contextDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (_pr != null)
            {
                try
                {
                    _pr.Kill();
                }
                catch { };
            }
            //_pr = Process.Start("D:\\Fujitsu\\CRM\\2019-06-12_1\\CRM\\CRM_Access.accdb", "/X mcrRashod");
            _pr = Process.Start("D:\\Projects\\CRM\\CRM_Access.accdb", "/X mcrRashod");
        }
        public PrihodWindow()
        {
            InitializeComponent();
            prihod2s = new ObservableCollection <Prihod2>();

            using (CRM_magEntities contextDB = new CRM_magEntities())
            {
                dgPrihod.ItemsSource = prihod2s;

                var dataPostavshik = from p in contextDB.Postavshiki
                                     select new { p.id_postavsh, p.name_postavsh };

                cmbPostavshik.ItemsSource       = dataPostavshik.ToList();
                cmbPostavshik.DisplayMemberPath = "name_postavsh";
                cmbPostavshik.SelectedValuePath = "id_postavsh";
                cmbPostavshik.SelectedValue     = -1;

                var materEdIzm = from m in contextDB.Materialy
                                 join ei in contextDB.tEdIzm on m.id_ed_izm equals ei.id
                                 select new
                {
                    IdMater   = m.id_material,
                    NameMater = m.NameMaterial + "  (" + ei.NameEI + ")",
                    IdEdIzm   = m.id_ed_izm,
                    Artikul   = m.artikul
                };


                listMat = new List <MaterEdIzm>();
                foreach (var n in materEdIzm)
                {
                    MaterEdIzm e = new MaterEdIzm();
                    e.IdMater1   = n.IdMater;
                    e.NameMater1 = n.NameMater;
                    e.IdEdIzm1   = n.IdEdIzm;
                    e.Artikul    = n.Artikul;
                    listMat.Add(e);
                }

                cmbMaterial.ItemsSource = listMat;

                cmbMaterial.DisplayMemberPath = "NameMater1";

                cmbMaterial.SelectedValuePath = "IdMater1";
                dtpDatePrih.SelectedDate      = DateTime.Now;
            }
        }
        private void txtBNameClient_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (txtBNameClient.Text != "")
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        var dataClientSearch = from c in contextDB.RequestList
                                               where c.famil.ToLower()
                                               .Contains(txtBNameClient.Text
                                                         .ToLower())
                                               select new
                        {
                            c.id_request,
                            c.famil,
                            c.f_name,
                            c.s_name
                        };
                        listsRLC = new List <RequestListC>();
                        foreach (var item in dataClientSearch)
                        {
                            RequestListC sRequest = new RequestListC();
                            sRequest.IdItem = item.id_request;
                            sRequest.Client = item.famil + " " + item.f_name + " " + item.s_name;



                            listsRLC.Add(sRequest);
                        }

                        lstvClient.ItemsSource       = listsRLC.OrderBy(s => s.Client);
                        lstvClient.SelectedValuePath = "IdItem";
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MakeFresh();
            }
        }
 private void rbtnPerezv_Checked(object sender, RoutedEventArgs e)
 {
     try
     {
         using (CRM_magEntities contextDB = new CRM_magEntities())
         {
             Perenos_request pr = new Perenos_request();
             pr.vyezd_or_perezvon = false;
             contextDB.Perenos_request.Add(pr);
             contextDB.SaveChanges();
             idPerenosReq = pr.id_perenos_request;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Example #13
0
        public RashodWindow()
        {
            InitializeComponent();
            rashod2s = new ObservableCollection <Rashod_2>();

            using (CRM_magEntities contextDB = new CRM_magEntities())
            {
                dgRashod.ItemsSource = rashod2s;

                var dataMontajnik = from p in contextDB.Montazhniki
                                    select new { p.id_mont, p.full_name };

                cmbPoluchatel.ItemsSource       = dataMontajnik.ToList();
                cmbPoluchatel.DisplayMemberPath = "full_name";
                cmbPoluchatel.SelectedValuePath = "id_mont";
                cmbPoluchatel.SelectedValue     = -1;

                var materEdIzm = from m in contextDB.Materialy
                                 join ei in contextDB.tEdIzm on m.id_ed_izm equals ei.id
                                 select new
                {
                    IdMater   = m.id_material,
                    NameMater = m.NameMaterial + "  (" + ei.NameEI + ")",
                    IdEdIzm   = m.id_ed_izm,
                };

                listMat = new List <MaterEdIzm>();
                foreach (var n in materEdIzm)
                {
                    MaterEdIzm e = new MaterEdIzm();
                    e.IdMater1   = n.IdMater;
                    e.NameMater1 = n.NameMater;
                    e.IdEdIzm1   = n.IdEdIzm;
                    listMat.Add(e);
                }

                cmbMaterial.ItemsSource = listMat;

                cmbMaterial.DisplayMemberPath = "NameMater1";

                cmbMaterial.SelectedValuePath = "IdMater1";
                dtPRashod.SelectedDate        = DateTime.Now;
            }
        }
        private void btnShow_Click(object sender, RoutedEventArgs e)
        {
            unsd = new List <UstNaCledDen>();

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    dtUstFrom = (DateTime)dtpDateUstFrom.SelectedDate;
                    dtUstTo   = (DateTime)dtpDateUstTo.SelectedDate;

                    var v = contextDB.spProizvodOtdel1(dtUstFrom, dtUstTo).ToList();

                    foreach (var item in v)
                    {
                        UstNaCledDen iu = new UstNaCledDen();

                        iu.FIO_zakazchika = item.FIO_zakazchika;

                        iu.Adres         = item.Adres;
                        iu.NumberRequest = item.id_request;
                        iu.DateExecution = (DateTime)item.datetime_vyezda_montazhnika;
                        iu.IdMont        = item.id_mont;
                        iu.NameMont      = item.full_name;
                        unsd.Add(iu);
                    }

                    dgUstanovka.ItemsSource = unsd;

                    var dataMont = from m in contextDB.Montazhniki
                                   select new { m.id_mont, m.full_name };

                    cmbMont.ItemsSource       = dataMont.ToList();
                    cmbMont.DisplayMemberPath = "full_name";
                    cmbMont.SelectedValuePath = "id_mont";
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #15
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    Rashod1 rash1 = new Rashod1();
                    rash1.data_nakl = (DateTime)dtPRashod.SelectedDate;
                    if (cmbPoluchatel.SelectedValue != null)
                    {
                        rash1.id_mont = Convert.ToInt32(cmbPoluchatel.SelectedValue);
                    }
                    contextDB.Rashod1.Add(rash1);
                    contextDB.SaveChanges();

                    idRash1 = rash1.id;
                    txtBNomerNakladnoj.Text = idRash1.ToString();

                    foreach (Rashod_2 item in rashod2s)
                    {
                        Rashod_2 rashod2 = new Rashod_2();
                        rashod2.id          = idRash1;
                        rashod2.id_material = item.id_material;

                        rashod2.kod_ed_izm = contextDB.Materialy.Find(item.id_material).id_ed_izm;


                        rashod2.kol  = item.kol;
                        rashod2.cena = item.cena;
                        contextDB.Rashod_2.Add(rashod2);
                    }

                    contextDB.SaveChanges();
                    dgRashod.ItemsSource = null;
                    dgRashod.ItemsSource = rashod2s;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (CRM_magEntities contextDB = new CRM_magEntities())
         {
             foreach (var item in unsd)
             {
                 int idRA = Convert.ToInt32(contextDB.Request_reception.Find(item.NumberRequest).id_request_execution);
                 Request_attachment ra = contextDB.Request_attachment.Find(idRA);
                 ra.id_mont = item.IdMont;
             }
             contextDB.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 public Password()
 {
     InitializeComponent();
     try
     {
         using (CRM_magEntities contextDB = new CRM_magEntities())
         {
             var dataDB = from s in contextDB.Sotrudniki
                          select new { s.id_sotrudnik, s.full_name };
             cmbSotrudnik.ItemsSource       = dataDB.ToList();
             cmbSotrudnik.DisplayMemberPath = "full_name";
             cmbSotrudnik.SelectedValuePath = "id_sotrudnik";
             cmbSotrudnik.SelectedValue     = -1;
             cmbSotrudnik.SelectedValue     = "1";
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
Example #18
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     using (CRM_magEntities context = new CRM_magEntities())
     {
         try
         {
             foreach (var it in lstVvPervOst)
             {
                 Materialy mat = new Materialy();
                 mat                  = context.Materialy.Find(it.id_material);
                 mat.ostatok_cur      = it.ostatok_cur;
                 mat.date_ostatok_cur = (DateTime)dtVvPervOst.SelectedDate;
             }
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString(), "Error");
         }
     }
 }
        private void lstvClient_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int idCl = 0;

            using (CRM_magEntities contextDB = new CRM_magEntities())
            {
                int idAdr = Convert.ToInt32(contextDB.Request_reception.Find(Convert.ToInt32(lstvClient.SelectedValue)).id_adr_installation);
                idCl = Convert.ToInt32(contextDB.Adr_installation.Find(idAdr).id_client);
            }

            if ((lstvClient.SelectedValue != null) && isView)
            {
                ClientView cv = new ClientView(idCl);
                cv.ShowDialog();
            }
            else if ((lstvClient.SelectedValue != null) && !isView)
            {
                ClientUpdate cu = new ClientUpdate(idCl);
                cu.ShowDialog();
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    Prihod1 prih1 = new Prihod1();
                    prih1.data_prihod = (DateTime)dtpDatePrih.SelectedDate;
                    if (cmbPostavshik.SelectedValue != null)
                    {
                        prih1.id_postavsh = Convert.ToInt32(cmbPostavshik.SelectedValue);
                    }
                    contextDB.Prihod1.Add(prih1);
                    contextDB.SaveChanges();

                    idPrih1 = prih1.id;
                    txtbNumPrihOrder.Text = idPrih1.ToString();

                    foreach (Prihod2 item in prihod2s)
                    {
                        Prihod2 prihod2 = new Prihod2();
                        prihod2.id          = idPrih1;
                        prihod2.id_material = item.id_material;

                        prihod2.kod_ed_izm = contextDB.Materialy.Find(item.id_material).id_ed_izm;

                        prihod2.kol  = item.kol;
                        prihod2.cena = item.cena;
                        contextDB.Prihod2.Add(prihod2);
                    }
                    contextDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void Vhod_Click(object sender, RoutedEventArgs e)
        {
            string pw          = "";
            string rol         = "";
            int    idSotrudnik = Convert.ToInt32(cmbSotrudnik.SelectedValue);

            using (CRM_magEntities contextDB = new CRM_magEntities())
            {
                pw = (((from st in contextDB.Sotrudniki
                        where (st.id_sotrudnik == idSotrudnik)
                        select new { st.parol }).FirstOrDefault()).parol).ToString();
                rol = (((from st in contextDB.Sotrudniki
                         where (st.id_sotrudnik == idSotrudnik)
                         select new { st.rol }).FirstOrDefault()).rol).ToString();
            }

            //if (pw == parolBox.Password.ToString())
            //{
            if (rol == "л")
            {
                TekushOstatkiPoSkladu lg = new TekushOstatkiPoSkladu();
                lg.Show();
            }
            else if (rol == "д")
            {
                MainWindow mw = new MainWindow(idSotrudnik);
                mw.Show();
            }
            else
            {
                Rukovodstvo r = new Rukovodstvo(idSotrudnik);
                r.Show();
            }
            //}
            this.Close();
        }
Example #22
0
        public ClientUpdate(int pIdClient)
        {
            InitializeComponent();
            idClient = pIdClient;

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    ClientView_Result clv = contextDB.ClientView(idClient).FirstOrDefault();
                    idAdrInst = Convert.ToInt32(clv.id_adr_installation);
                    idClient  = Convert.ToInt32(clv.id_client);
                    idReqSnab = Convert.ToInt32(clv.id_request_snab);
                    idReqAtt  = Convert.ToInt32(clv.id_request_execution);
                    idReqBuhg = Convert.ToInt32(clv.id_request_buhg);
                    idReqRec  = Convert.ToInt32(clv.id_request);

                    if (clv.famil != null)
                    {
                        txtbFamilCl.Text = clv.famil;
                    }
                    if (clv.f_name != null)
                    {
                        txtbNameCl.Text = clv.f_name;
                    }
                    if (clv.s_name != null)
                    {
                        txtbSurnameCl.Text = clv.s_name;
                    }
                    if (clv.number_pasp != null)
                    {
                        txtbPasp.Text = clv.number_pasp;
                    }
                    if (clv.tel != null)
                    {
                        txtbTel.Text = clv.tel;
                    }
                    if (clv.city_town != null)
                    {
                        txtbCityTown.Text = clv.city_town;
                    }

                    if (clv.city_town == "Москва")
                    {
                        rbtnMoscow.IsChecked = true;
                    }
                    else
                    {
                        rbtnMO.IsChecked = true;
                    }

                    if (clv.street != null)
                    {
                        txtbStreet.Text = clv.street;
                    }
                    if (clv.house != null)
                    {
                        txtbHouse.Text = clv.house.ToString();
                    }
                    if (clv.korp != null)
                    {
                        txtbKorp.Text = clv.korp;
                    }
                    if (clv.flat != null)
                    {
                        txtbFlat.Text = clv.flat.ToString();
                    }
                    if (clv.podezd != null)
                    {
                        txtbPodezd.Text = clv.podezd.ToString();
                    }
                    if (clv.etag != null)
                    {
                        txtbEtag.Text = clv.etag.ToString();
                    }
                    if (clv.domofon != null)
                    {
                        txtbDomofon.Text = clv.domofon;
                    }

                    var dataMetro = from me in contextDB.Metro
                                    select new { me.id_metro, me.name_metro };

                    cmbMetro.ItemsSource       = dataMetro.ToList();
                    cmbMetro.DisplayMemberPath = "name_metro";
                    cmbMetro.SelectedValuePath = "id_metro";

                    if (clv.id_metro != null)
                    {
                        cmbMetro.SelectedValue = clv.id_metro;
                    }

                    if (clv.raion != null)
                    {
                        txtbRajon.Text = clv.raion;
                    }

                    if (clv.kol_hol != null)
                    {
                        txtbKolHol.Text = clv.kol_hol.ToString();
                    }

                    var dataMarkaHol = from mh in contextDB.H_Schetchik
                                       select new { mh.id_hol_schetch, mh.marka_hol_schetch };
                    cmbMarkaHol.ItemsSource       = dataMarkaHol.ToList();
                    cmbMarkaHol.DisplayMemberPath = "marka_hol_schetch";
                    cmbMarkaHol.SelectedValuePath = "id_hol_schetch";

                    if (clv.id_hol_schetch != null)
                    {
                        cmbMarkaHol.SelectedValue = clv.id_hol_schetch;
                    }
                    if (clv.kol_gor != null)
                    {
                        txtbKolGor.Text = clv.kol_gor.ToString();
                    }

                    var dataMarkaGor = from mg in contextDB.G_Schetchik
                                       select new { mg.id_gor_schetch, mg.marka_gor_schetch };
                    cmbMarkaGor.ItemsSource       = dataMarkaGor.ToList();
                    cmbMarkaGor.DisplayMemberPath = "marka_gor_schetch";
                    cmbMarkaGor.SelectedValuePath = "id_gor_schetch";

                    if (clv.id_gor_schetch != null)
                    {
                        cmbMarkaGor.SelectedValue = clv.id_gor_schetch;
                    }
                    if (clv.kol_teplo != null)
                    {
                        txtbKolTeplo.Text = clv.kol_teplo.ToString();
                    }

                    var dataMarkaTeplo = from mt in contextDB.Teplo_Schetchik
                                         select new { mt.id_teplo_schetch, mt.marka_teplo_schetch };
                    cmbMarkaTeplo.ItemsSource       = dataMarkaTeplo.ToList();
                    cmbMarkaTeplo.DisplayMemberPath = "marka_teplo_schetch";
                    cmbMarkaTeplo.SelectedValuePath = "id_teplo_schetch";

                    if (clv.id_teplo_schetch != null)
                    {
                        cmbMarkaTeplo.SelectedValue = clv.id_teplo_schetch;
                    }

                    if (clv.datetime_vyezda_montazhnika != null)
                    {
                        txtbVyezd.Text = ((DateTime)clv.datetime_vyezda_montazhnika).ToString("dd.MM.yyyy");
                    }

                    if (clv.date_execution != null)
                    {
                        txtbDateExecution.Text = ((DateTime)clv.date_execution).ToString("dd.MM.yyyy");
                    }

                    var dataMont = from m in contextDB.Montazhniki
                                   select new { m.id_mont, m.full_name };
                    cmbMont.ItemsSource       = dataMont.ToList();
                    cmbMont.DisplayMemberPath = "full_name";
                    cmbMont.SelectedValuePath = "id_mont";

                    if (clv.id_mont != null)
                    {
                        cmbMont.SelectedValue = clv.id_mont;
                    }

                    if (clv.dispetcher != null)
                    {
                        txtbDisp.Text = clv.dispetcher;
                    }

                    if (clv.date_request != null)
                    {
                        txtbDTRegistr.Text = ((DateTime)clv.date_request).ToString("dd.MM.yyyy");
                    }
                    if (clv.sum_contract != null)
                    {
                        txtbSum.Text = clv.sum_contract.ToString();
                    }

                    if (clv.id_request != null)
                    {
                        txtbNumberRequest.Text = clv.id_request.ToString();
                    }
                    if (clv.date_otkaza != null)
                    {
                        txtbDateOtkaz.Text = ((DateTime)clv.date_otkaza).ToString("dd.MM.yyyy");
                    }
                    if (clv.reason_otkaza != null)
                    {
                        txtbReasonOtkaza.Text = clv.reason_otkaza;
                    }

                    var dataKindOfWork = from k in contextDB.Kind_of_work
                                         select new { k.id_kind_of_work, k.kind_of_work1 };
                    cmbKindOfWork.ItemsSource       = dataKindOfWork.ToList();
                    cmbKindOfWork.DisplayMemberPath = "kind_of_work1";
                    cmbKindOfWork.SelectedValuePath = "id_kind_of_work";

                    if (clv.kind_of_work != null)
                    {
                        cmbKindOfWork.SelectedValue = clv.id_kind_of_work;
                    }

                    var dataStatus = from s in contextDB.Status
                                     select new { s.id_status, s.status1 };
                    cmbStatus.ItemsSource       = dataStatus.ToList();
                    cmbStatus.DisplayMemberPath = "status1";
                    cmbStatus.SelectedValuePath = "id_status";

                    if (clv.status != null)
                    {
                        cmbStatus.SelectedValue = clv.id_status;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    txtbNumberRequest.IsEnabled = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        private void btnOKFizL_Click(object sender, RoutedEventArgs e)
        {
            if (IsErrorFizLico())
            {
                MessageBox.Show(sErrorFizLico, "Ошибка!");
            }
            else
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        Client cl = new Client();

                        cl.famil       = txtbFamilCl.Text;
                        cl.f_name      = txtbNameCl.Text;
                        cl.s_name      = txtbSurnameCl.Text;
                        cl.number_pasp = txtbPasp.Text;
                        cl.tel         = txtbTel.Text;
                        contextDB.Client.Add(cl);
                        contextDB.SaveChanges();
                        idClient = cl.id_client;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }


            if (!IsErrorFizLico())
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        Adr_installation adr = new Adr_installation();
                        if (rbtnMoscow.IsChecked == true)
                        {
                            adr.city_town = "Москва";
                        }
                        else if (rbtnMO.IsChecked == true)
                        {
                            adr.city_town = txtbCityTown.Text;
                        }
                        adr.raion = txtbRajon.Text;
                        if (txtbStreet.Text != null)
                        {
                            adr.street = txtbStreet.Text;
                        }
                        adr.house = Convert.ToInt32(txtbHouse.Text);
                        adr.korp  = txtbKorp.Text;
                        adr.flat  = Convert.ToInt32(txtbFlat.Text);
                        if (cmbMetro.SelectedValue != null)
                        {
                            adr.id_metro = Convert.ToInt32(cmbMetro.SelectedValue);
                        }

                        adr.podezd    = Convert.ToInt32(txtbPodezd.Text);
                        adr.etag      = Convert.ToInt32(txtbEtag.Text);
                        adr.domofon   = txtbDomofon.Text;
                        adr.id_client = idClient;
                        contextDB.Adr_installation.Add(adr);
                        contextDB.SaveChanges();
                        idAdrInst = adr.id_adr_installation;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }


            if (!IsErrorFizLico())
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        Request_snab rs = new Request_snab();
                        if (cmbMarkaGor.SelectedValue != null)
                        {
                            rs.id_gor_schetch = Convert.ToInt32(cmbMarkaGor.SelectedValue);
                        }
                        if (cmbMarkaHol.SelectedValue != null)
                        {
                            rs.id_hol_schetch = Convert.ToInt32(cmbMarkaHol.SelectedValue);
                        }
                        if (cmbMarkaTeplo.SelectedValue != null)
                        {
                            rs.id_teplo_schetch = Convert.ToInt32(cmbMarkaTeplo.SelectedValue);
                        }
                        int  numbKolGor;
                        bool resultKolGor = int.TryParse(txtbKolGor.Text, out numbKolGor);
                        if (resultKolGor == true)
                        {
                            rs.kol_gor = numbKolGor;
                        }

                        int  numbKolHol;
                        bool resultKolHol = int.TryParse(txtbKolHol.Text, out numbKolHol);
                        if (resultKolHol == true)
                        {
                            rs.kol_hol = numbKolHol;
                        }

                        int  numbKolTeplo;
                        bool resultKolTeplo = int.TryParse(txtbKolTeplo.Text, out numbKolTeplo);
                        if (resultKolTeplo == true)
                        {
                            rs.kol_teplo = numbKolTeplo;
                        }

                        contextDB.Request_snab.Add(rs);
                        contextDB.SaveChanges();

                        idReqSnab = rs.id_request_snab;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }


            if (!IsErrorFizLico())
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        Request_attachment ra = new Request_attachment();
                        ra.datetime_vyezda_montazhnika = Convert
                                                         .ToDateTime(txtbVyezd.Text);

                        if (cmbMont.SelectedValue != null)
                        {
                            ra.id_mont = Convert.ToInt32(cmbMont.SelectedValue);
                        }

                        contextDB.Request_attachment.Add(ra);
                        contextDB.SaveChanges();

                        idReqAtt = ra.id_request_execution;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }



            if (!IsErrorFizLico())
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        Request_buhg rb = new Request_buhg();
                        decimal      sum;
                        bool         resultSum = decimal.TryParse(txtbSum.Text, out sum);
                        if (resultSum == true)
                        {
                            rb.sum_contract = sum;
                        }

                        contextDB.Request_buhg.Add(rb);
                        contextDB.SaveChanges();
                        idReqBuhg = rb.id_request_buhg;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            if (!IsErrorFizLico())
            {
                try
                {
                    using (CRM_magEntities contextDB = new CRM_magEntities())
                    {
                        Request_reception rr = new Request_reception();
                        rr.id_request_snab      = idReqSnab;
                        rr.id_request_buhg      = idReqBuhg;
                        rr.id_request_execution = idReqAtt;
                        rr.id_adr_installation  = idAdrInst;
                        rr.id_status            = 1;
                        rr.id_kind_of_work      = Convert.ToInt32(cmbKindOfWork.SelectedValue);
                        if (idPerenosReq != 0)
                        {
                            rr.id_perenos_request = idPerenosReq;
                        }
                        rr.dispetcher   = txtbDispR.Text;
                        rr.date_request = Convert.ToDateTime(txtbDateReg.Text);

                        contextDB.Request_reception.Add(rr);
                        contextDB.SaveChanges();
                        txtbNumberRequest.Text = rr.id_request.ToString();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                if (evNewClient != null)
                {
                    evNewClient();
                }
            }
        }
        public ClientView(int pIdClient)
        {
            InitializeComponent();
            idClient = pIdClient;

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    ClientView_Result clv = contextDB.ClientView(idClient).FirstOrDefault();

                    if (clv.famil != null)
                    {
                        txtbFamilCl.Text = clv.famil;
                    }
                    if (clv.f_name != null)
                    {
                        txtbNameCl.Text = clv.f_name;
                    }
                    if (clv.s_name != null)
                    {
                        txtbSurnameCl.Text = clv.s_name;
                    }
                    if (clv.number_pasp != null)
                    {
                        txtbPasp.Text = clv.number_pasp;
                    }
                    if (clv.tel != null)
                    {
                        txtbTel.Text = clv.tel;
                    }

                    if (clv.city_town != null)
                    {
                        txtbCityTown.Text = clv.city_town;
                    }

                    if (clv.city_town == "Москва")
                    {
                        rbtnMoscow.IsChecked = true;
                    }
                    else
                    {
                        rbtnMO.IsChecked = true;
                    }

                    if (clv.street != null)
                    {
                        txtbStreet.Text = clv.street;
                    }
                    if (clv.house != null)
                    {
                        txtbHouse.Text = clv.house.ToString();
                    }
                    if (clv.korp != null)
                    {
                        txtbKorp.Text = clv.korp;
                    }
                    if (clv.flat != null)
                    {
                        txtbFlat.Text = clv.flat.ToString();
                    }
                    if (clv.podezd != null)
                    {
                        txtbPodezd.Text = clv.podezd.ToString();
                    }
                    if (clv.etag != null)
                    {
                        txtbEtag.Text = clv.etag.ToString();
                    }
                    if (clv.domofon != null)
                    {
                        txtbDomofon.Text = clv.domofon;
                    }

                    if (clv.id_metro != null)
                    {
                        txtBMetro.Text = contextDB.Metro
                                         .Where(c => c.id_metro == clv.id_metro)
                                         .FirstOrDefault()
                                         .name_metro
                                         .ToString();
                    }


                    if (clv.raion != null)
                    {
                        txtbRajon.Text = clv.raion;
                    }


                    if (clv.kol_hol != null)
                    {
                        txtbKolHol.Text = clv.kol_hol.ToString();
                    }
                    if (clv.id_hol_schetch != null)
                    {
                        txtbMarkaHol.Text = contextDB.Request_snab.Where(c => c.id_hol_schetch == clv.id_hol_schetch)
                                            .FirstOrDefault().H_Schetchik.marka_hol_schetch.ToString();
                    }
                    if (clv.kol_gor != null)
                    {
                        txtbKolGor.Text = clv.kol_gor.ToString();
                    }
                    if (clv.id_gor_schetch != null)
                    {
                        txtbMarkaGor.Text = contextDB.Request_snab.Where(c => c.id_gor_schetch == clv.id_gor_schetch)
                                            .FirstOrDefault().G_Schetchik.marka_gor_schetch.ToString();
                    }
                    if (clv.kol_teplo != null)
                    {
                        txtbKolTeplo.Text = clv.kol_teplo.ToString();
                    }
                    if (clv.id_teplo_schetch != null)
                    {
                        txtbMarkaTeplo.Text = contextDB.Request_snab.Where(c => c.id_teplo_schetch == clv.id_teplo_schetch)
                                              .FirstOrDefault().Teplo_Schetchik.marka_teplo_schetch.ToString();
                    }

                    if (clv.datetime_vyezda_montazhnika != null)
                    {
                        txtbVyezd.Text = ((DateTime)clv.datetime_vyezda_montazhnika).ToString("dd.MM.yyyy");
                    }

                    if (clv.date_execution != null)
                    {
                        txtbDateExecution.Text = ((DateTime)clv.date_execution).ToString("dd.MM.yyyy");
                    }

                    if (clv.id_mont != null)
                    {
                        txtbMont.Text = contextDB.Request_attachment
                                        .Where(c => c.id_mont == clv.id_mont)
                                        .FirstOrDefault()
                                        .Montazhniki.full_name
                                        .ToString();
                    }

                    if (clv.sum_contract != null)
                    {
                        txtbSum.Text = clv.sum_contract.ToString();
                    }

                    if (clv.id_request != null)
                    {
                        txtbNumberRequest.Text = clv.id_request.ToString();
                    }
                    if (clv.date_request != null)
                    {
                        txtbDateReg.Text = ((DateTime)clv.date_request).ToString("dd.MM.yyyy");
                    }
                    if (clv.dispetcher != null)
                    {
                        txtbDispR.Text = clv.dispetcher;
                    }
                    if (clv.kind_of_work != null)
                    {
                        txtbKindOfWork.Text = contextDB.Request_reception
                                              .Where(c => c.id_kind_of_work == clv.id_kind_of_work)
                                              .FirstOrDefault()
                                              .Kind_of_work
                                              .kind_of_work1
                                              .ToString();
                    }
                    if (clv.status != null)
                    {
                        txtbStatus.Text = clv.status;
                    }

                    if (clv.date_otkaza != null)
                    {
                        txtbDateOtkaz.Text = ((DateTime)clv.date_otkaza).ToString("dd.MM.yyyy");
                    }
                    if (clv.reason_otkaza != null)
                    {
                        txtbReasonOtkaza.Text = clv.reason_otkaza;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        public ClientAdd(int ncidSotrudnik)
        {
            InitializeComponent();
            idSotrudnik      = ncidSotrudnik;
            this.idWhoRegist = idSotrudnik;

            try
            {
                using (CRM_magEntities contextDB = new CRM_magEntities())
                {
                    var dataWhoRegist = (from s in contextDB.Sotrudniki
                                         where s.id_sotrudnik == idWhoRegist
                                         select s).FirstOrDefault();
                    txtbDateReg.Text = DateTime.Now.ToString("dd/MM/yy HH:mm");
                    txtbDispR.Text   = dataWhoRegist.full_name;

                    var dataKindOfWork = from k in contextDB.Kind_of_work
                                         select new { k.id_kind_of_work, k.kind_of_work1 };
                    cmbKindOfWork.ItemsSource       = dataKindOfWork.ToList();
                    cmbKindOfWork.DisplayMemberPath = "kind_of_work1";
                    cmbKindOfWork.SelectedValuePath = "id_kind_of_work";
                    cmbKindOfWork.SelectedValue     = -1;

                    var dataMarkaHol = from mh in contextDB.H_Schetchik
                                       select new { mh.id_hol_schetch, mh.marka_hol_schetch };
                    cmbMarkaHol.ItemsSource       = dataMarkaHol.ToList();
                    cmbMarkaHol.DisplayMemberPath = "marka_hol_schetch";
                    cmbMarkaHol.SelectedValuePath = "id_hol_schetch";
                    cmbMarkaHol.SelectedValue     = -1;

                    var dataMarkaGor = from mg in contextDB.G_Schetchik
                                       select new { mg.id_gor_schetch, mg.marka_gor_schetch };
                    cmbMarkaGor.ItemsSource       = dataMarkaGor.ToList();
                    cmbMarkaGor.DisplayMemberPath = "marka_gor_schetch";
                    cmbMarkaGor.SelectedValuePath = "id_gor_schetch";
                    cmbMarkaGor.SelectedValue     = -1;

                    var dataMarkaTeplo = from mt in contextDB.Teplo_Schetchik
                                         select new { mt.id_teplo_schetch, mt.marka_teplo_schetch };
                    cmbMarkaTeplo.ItemsSource       = dataMarkaTeplo.ToList();
                    cmbMarkaTeplo.DisplayMemberPath = "marka_teplo_schetch";
                    cmbMarkaTeplo.SelectedValuePath = "id_teplo_schetch";
                    cmbMarkaTeplo.SelectedValue     = -1;

                    var dataMont = from m in contextDB.Montazhniki
                                   select new { m.id_mont, m.full_name };
                    cmbMont.ItemsSource       = dataMont.ToList();
                    cmbMont.DisplayMemberPath = "full_name";
                    cmbMont.SelectedValuePath = "id_mont";
                    cmbMont.SelectedValue     = -1;

                    var dataMetro = from me in contextDB.Metro
                                    select new { me.id_metro, me.name_metro };

                    cmbMetro.ItemsSource       = dataMetro.ToList();
                    cmbMetro.DisplayMemberPath = "name_metro";
                    cmbMetro.SelectedValuePath = "id_metro";
                    cmbMetro.SelectedValue     = -1;

                    txtbNumberRequest.IsEnabled = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Example #26
0
        private void Zapoln(DateTime dt)
        {
            using (CRM_magEntities context = new CRM_magEntities())
            {
                try
                {
                    lstIntVed = new List <InventVed>();
                    foreach (var item in context.spInventVed(dt))
                    {
                        InventVed mt = new InventVed();

                        mt.id_material  = item.id_material;
                        mt.artikul      = item.artikul;
                        mt.NameMaterial = item.NameMaterial;
                        mt.id_ed_izm    = item.id_ed_izm;
                        Ed_izm ei = context.Ed_izm.Find(item.id_ed_izm);
                        mt.date_ostatok = (DateTime)item.date_ostatok_cur;
                        mt.nameEI       = ei.nameEI;
                        if (item.prih == null)
                        {
                            mt.prih = 0;
                        }
                        else
                        {
                            mt.prih = (decimal)item.prih;
                        }

                        if (item.rash == null)
                        {
                            mt.rash = 0;
                        }
                        else
                        {
                            mt.rash = (decimal)item.rash;
                        }


                        if (item.ostatok_cur == null)
                        {
                            mt.ostatok_cur = 0;
                        }
                        else
                        {
                            mt.ostatok_cur = (decimal)item.ostatok_cur;
                        }

                        if (item.ostatok_new == null)
                        {
                            mt.ostatok_new = 0;
                        }
                        else
                        {
                            mt.ostatok_new = (decimal)item.ostatok_new;
                        }

                        lstIntVed.Add(mt);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
                dgInventVedomost.ItemsSource = null;
                dgInventVedomost.ItemsSource = lstIntVed;
            }
        }