コード例 #1
0
        internal protected static void ChangeRevizeSCForUpcomingOpenRevision(SCProvozu oldSCProvozu, SCProvozu newSCProvozu, DateTime PocatecniDatum)
        {
            List <RevizeSC> list = new List <RevizeSC>();

            list = GetNextOpenRevizeForRevizeSC(oldSCProvozu, PocatecniDatum);
            SwitchSCprovozu(list, newSCProvozu);
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,RevizeId,SCProvozuId,StavKoroze,StavZnecisteni,JineZavady,UmisteniId,Baterie,Pyro,TlakovaZkouska,RevizeTlakoveNadoby,VnitrniRevizeTlakoveNadoby")] RevizeSC revizeSC)
        {
            if (ModelState.IsValid)
            {
                int RevizeId = 0;
                try
                {
                    SCProvozu scprovozu = new SCProvozu();
                    scprovozu           = db.SCProvozu.Find(revizeSC.SCProvozuId);
                    revizeSC.UmisteniId = scprovozu.Umisteni;

                    db.RevizeSC.Add(revizeSC);
                    RevizeId = revizeSC.RevizeId;
                    db.SaveChanges();
                }
                catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }

                Revize revize = new Revize();
                revize = db.Revize.Find(RevizeId);
                Revize.UpdateRevizeHeader(RevizeId);
                return(RedirectToAction("Details", "Revize", new { Id = RevizeId }));
                //return RedirectToAction("Index");
            }

            ViewBag.RevizeId    = new SelectList(db.Revize, "Id", "ZjistenyStav", revizeSC.RevizeId);
            ViewBag.SCProvozuId = new SelectList(db.SCProvozu, "Id", "Lokace", revizeSC.SCProvozuId);
            ViewBag.UmisteniId  = new SelectList(db.Umisteni, "Id", "NazevUmisteni", revizeSC.UmisteniId);
            return(View(revizeSC));
        }
コード例 #3
0
        internal protected static VymenyLahvi GenerujVymenu(SCProvozu oldSCProvozu, SCProvozu newSCProvozu, DateTime DatumVymeny, int RevizeId, string SClahve)
        {
            VymenyLahvi vl = new VymenyLahvi();

            using (var dbCtx = new Model1Container())
            {
                vl.SCProvozuNova    = newSCProvozu.Id;
                vl.SCProvozuPuvodni = oldSCProvozu.Id;
                vl.DatumVymeny      = DatumVymeny;
                vl.Revize           = RevizeId;
                vl.Umisteni         = oldSCProvozu.Umisteni;
                vl.SCLahve          = SClahve;
                if (SClahve.Trim().StartsWith("R"))
                {
                    vl.Repase = true;
                    vl.Popis  = "viz. přiložený atest";
                }
                else
                {
                    vl.Repase = false;
                    vl.Popis  = "viz. přiložené prohlášení o shodě";
                }

                try
                {
                    dbCtx.VymenyLahvi.Add(vl);
                    dbCtx.SaveChanges();
                }
                catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
            }
            return(vl);
        }
コード例 #4
0
ファイル: Revize.cs プロジェクト: petnovcz/VST_sprava_servisu
 internal protected static void CallSCProvozupdate(List <RevizeSC> revizesclist, DateTime datumkontroly)
 {
     foreach (var item in revizesclist)
     {
         SCProvozu.UpdateSC(item.SCProvozuId, datumkontroly, item.Baterie, item.Pyro, item.TlakovaZkouska, item.RevizeTlakoveNadoby, item.VnitrniRevizeTlakoveNadoby);
     }
 }
コード例 #5
0
ファイル: SCList.cs プロジェクト: petnovcz/VST_sprava_servisu
        public static List <SCProvozu> AddItemsFromList(List <SCList> sclist, int revize)
        {
            List <SCProvozu> list = new List <SCProvozu>();
            SCProvozu        sc   = new SCProvozu();

            foreach (var item in sclist)
            {
                using (var dbCtx = new Model1Container())
                {
                    if (item.Revize == 1)
                    {
                        sc = dbCtx.SCProvozu.Where(r => r.Id == item.Id).FirstOrDefault();
                        var exist = dbCtx.RevizeSC.Where(r => r.RevizeId == revize && r.SCProvozuId == sc.Id).Count();
                        if (exist == 0)
                        {
                            RevizeSC revizesc = new RevizeSC
                            {
                                UmisteniId  = sc.Umisteni,
                                RevizeId    = revize,
                                SCProvozuId = sc.Id
                            };

                            if (item.Baterie == 1)
                            {
                                revizesc.Baterie = true;
                            }
                            if (item.Pyro == 1)
                            {
                                revizesc.Pyro = true;
                            }
                            if (item.TlkZk == 1)
                            {
                                revizesc.TlakovaZkouska = true;
                            }
                            try
                            {
                                dbCtx.RevizeSC.Add(revizesc);
                                dbCtx.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                log.Error($"AddItemsFromList {ex.Message} {ex.InnerException} {ex.Data}");
                            }
                        }
                    }

                    list.Add(sc);
                }
            }


            return(list);
        }
コード例 #6
0
        public static int AddSCProvozu(SCImport scimport, int id)
        {
            int       idscprovozu = 0;
            SCProvozu scprovozu   = new SCProvozu {
                SerioveCisloId = id, ProvozId = scimport.Provozy
            };

            using (var dbCtx = new Model1Container())
            {
                scprovozu.StatusId = dbCtx.Status.Where(s => s.Aktivni == true).Select(s => s.Id).FirstOrDefault();
            }
            scprovozu.DatumPrirazeni = scimport.DatumDodani;
            if (scimport.DatumPosledniZmeny == null)
            {
                scprovozu.DatumPosledniZmeny = scimport.DatumRevize;
            }
            else
            {
                scprovozu.DatumPosledniZmeny = scimport.DatumPosledniZmeny;
            }
            scprovozu.DatumVymeny                               = null;
            scprovozu.Umisteni                                  = scimport.Umisteni;
            scprovozu.DatumRevize                               = scimport.DatumRevize;
            scprovozu.DatumBaterie                              = scimport.DatumBaterie;
            scprovozu.DatumPyro                                 = scimport.DatumPyro;
            scprovozu.DatumTlkZk                                = scimport.DatumTlkZk;
            scprovozu.Lokace                                    = scimport.Lokace;
            scprovozu.Znaceni                                   = scimport.Znaceni;
            scprovozu.Baterie                                   = scimport.Baterie;
            scprovozu.Proverit                                  = scimport.Proverit;
            scprovozu.BaterieArtikl                             = scimport.BaterieArtikl;
            scprovozu.UpravenaPeriodaRevize                     = scimport.UpravenaPeriodaRevize;
            scprovozu.UpravenaPeriodaBaterie                    = scimport.UpravenaPeriodaBaterie;
            scprovozu.UpravenaPeriodaPyro                       = scimport.UpravenaPeriodaPyro;
            scprovozu.UpravenaPeriodaTlkZk                      = scimport.UpravenaPeriodaTlkZk;
            scprovozu.DatumRevizeTlakoveNadoby                  = scimport.DatumRevizeTlakoveNadoby;
            scprovozu.DatumVnitrniRevizeTlakoveNadoby           = scimport.DatumVnitrniRevizeTlakoveNadoby;
            scprovozu.UpravenaPeriodaRevizeTlakoveNadoby        = scimport.UpravenaPeriodaRevizeTlakoveNadoby;
            scprovozu.UpravenaPeriodaVnitrniRevizeTlakoveNadoby = scimport.UpravenaPeriodaVnitrniRevizeTlakoveNadoby;
            scprovozu.SCLahve                                   = scimport.SCLahve;
            using (var dbCtx = new Model1Container())
            {
                try
                {
                    dbCtx.SCProvozu.Add(scprovozu);
                    dbCtx.SaveChanges();
                }
                catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
            }
            idscprovozu = scprovozu.Id;
            return(idscprovozu);
        }
コード例 #7
0
        internal protected static bool ExistingRevizeSC(SCProvozu scprovozu, int RevizeId)
        {
            List <RevizeSC> list = new List <RevizeSC>();

            list = RevizeSC.GetListByRevizeId(RevizeId, scprovozu.Id);
            bool exist = false;

            if (list.Count() > 0)
            {
                exist = true;
            }
            return(exist);
        }
コード例 #8
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SCProvozu sCProvozu = db.SCProvozu.Find(id);

            if (sCProvozu == null)
            {
                return(HttpNotFound());
            }
            return(View(sCProvozu));
        }
コード例 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            SCProvozu sCProvozu = db.SCProvozu.Find(id);
            var       provoz    = sCProvozu.ProvozId;
            var       zakaznik  = sCProvozu.Provoz.ZakaznikId;
            var       umisteni  = sCProvozu.Umisteni;

            try
            {
                db.SCProvozu.Remove(sCProvozu);
                db.SaveChanges();
            }
            catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
            return(RedirectToAction("Details", "Umistenis", new { Id = umisteni, Provoz = provoz, Zakaznik = zakaznik }));
        }
コード例 #10
0
        internal protected static SCProvozu GetSCProvozuById(int SCProvozuId)
        {
            SCProvozu sCProvozu = new SCProvozu();

            using (var dbCtx = new Model1Container())
            {
                sCProvozu = dbCtx.SCProvozu.Where(r => r.Id == SCProvozuId).Include(r => r.SerioveCislo).Include(r => r.Artikl).FirstOrDefault();
                if (sCProvozu.SerioveCislo.ArtiklId != null)
                {
                    sCProvozu.Artikl = dbCtx.Artikl.Where(a => a.Id == sCProvozu.SerioveCislo.ArtiklId).FirstOrDefault();
                }
            }

            return(sCProvozu);
        }
コード例 #11
0
        private static List <RevizeSC> GetNextOpenRevizeForRevizeSC(SCProvozu scPRovozu, DateTime pocatecniDatum)
        {
            List <RevizeSC> list = new List <RevizeSC>();

            using (var dbCtx = new Model1Container())
            {
                var uzavrena = dbCtx.StatusRevize.Where(s => s.Realizovana != true).Select(r => r.Id).FirstOrDefault();
                var x        = dbCtx.RevizeSC.Where(r => r.SCProvozuId == scPRovozu.Id).Include(r => r.Revize)
                               .Where(r => r.Revize.DatumRevize > pocatecniDatum)
                               .Where(r => r.Revize.StatusRevizeId == uzavrena).ToList();

                list = x;
            }
            return(list);
        }
コード例 #12
0
 private static void SwitchSCprovozu(List <RevizeSC> list, SCProvozu newSCProvozu)
 {
     foreach (var item in list)
     {
         using (var dbCtx = new Model1Container())
         {
             RevizeSC revizeSC = new RevizeSC();
             revizeSC             = dbCtx.RevizeSC.Find(item.Id);
             revizeSC.SCProvozuId = newSCProvozu.Id;
             try
             {
                 dbCtx.Entry(revizeSC).State = EntityState.Modified;
                 dbCtx.SaveChanges();
             }
             catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
         }
     }
 }
コード例 #13
0
        internal protected static void ZneaktivniSCProvozu(SCProvozu oldSCProvozu, DateTime DatumRevize)
        {
            SCProvozu sc = new SCProvozu();

            using (var dbCtx = new Model1Container())
            {
                sc                    = dbCtx.SCProvozu.Find(oldSCProvozu.Id);
                sc.StatusId           = dbCtx.Status.Where(r => r.Neaktivni == true).Select(r => r.Id).FirstOrDefault();
                sc.DatumVymeny        = DatumRevize;
                sc.DatumPosledniZmeny = DatumRevize;
                try
                {
                    dbCtx.Entry(sc).State = EntityState.Modified;
                    dbCtx.SaveChanges();
                }
                catch { }
            }
        }
コード例 #14
0
        public ActionResult Create([Bind(Include = "Id,ProvozId,SerioveCisloId,StatusId,DatumPrirazeni,DatumPosledniZmeny,DatumVymeny,Umisteni,DatumRevize,DatumBaterie,DatumPyro,DatumTlkZk,Lokace,Znaceni,BaterieArtikl,UpravenaPeriodaRevize,UkonceniZaruky,UpravenaPeriodaBaterie,UpravenaPeriodaPyro,UpravenaPeriodaTlkZk,DatumRevizeTlakoveNadoby,DatumVnitrniRevizeTlakoveNadoby,UpravenaPeriodaRevizeTlakoveNadoby,UpravenaPeriodaVnitrniRevizeTlakoveNadoby,SCLahve ")] SCProvozu sCProvozu)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.SCProvozu.Add(sCProvozu);
                    db.SaveChanges();
                }
                catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
                return(RedirectToAction("Index"));
            }

            ViewBag.ProvozId       = new SelectList(db.Provoz, "Id", "NazevProvozu", sCProvozu.ProvozId);
            ViewBag.SerioveCisloId = new SelectList(db.SerioveCislo, "Id", "SerioveCislo1", sCProvozu.SerioveCisloId);
            ViewBag.StatusId       = new SelectList(db.Status, "Id", "NazevStatusu", sCProvozu.StatusId);
            ViewBag.Umisteni       = new SelectList(db.Umisteni, "Id", "NazevUmisteni", sCProvozu.Umisteni);
            return(View(sCProvozu));
        }
コード例 #15
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SCProvozu sCProvozu = db.SCProvozu.Find(id);

            if (sCProvozu == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProvozId       = new SelectList(db.Provoz, "Id", "NazevProvozu", sCProvozu.ProvozId);
            ViewBag.SerioveCisloId = new SelectList(db.SerioveCislo, "Id", "SerioveCislo1", sCProvozu.SerioveCisloId);
            ViewBag.StatusId       = new SelectList(db.Status, "Id", "NazevStatusu", sCProvozu.StatusId);
            ViewBag.Umisteni       = new SelectList(db.Umisteni, "Id", "NazevUmisteni", sCProvozu.Umisteni);
            ViewBag.Zakaznik       = db.Provoz.Where(p => p.Id == sCProvozu.ProvozId).Select(p => p.ZakaznikId).FirstOrDefault();
            ViewBag.Provoz         = sCProvozu.ProvozId;
            ViewBag.BaterieArtikl  = new SelectList(db.Artikl.Where(r => r.SkupinaArtiklu1.Id == 2), "Id", "Nazev", sCProvozu.BaterieArtikl);
            return(View(sCProvozu));
        }
コード例 #16
0
 public ActionResult Edit([Bind(Include = "Id,ProvozId,SerioveCisloId,StatusId,DatumPrirazeni,DatumPosledniZmeny,DatumVymeny,Umisteni,DatumRevize,DatumBaterie,DatumPyro,DatumTlkZk,Lokace,Znaceni,Proverit,Baterie,BaterieArtikl,UpravenaPeriodaRevize,UkonceniZaruky,UpravenaPeriodaBaterie,UpravenaPeriodaPyro,UpravenaPeriodaTlkZk,DatumRevizeTlakoveNadoby,DatumVnitrniRevizeTlakoveNadoby,UpravenaPeriodaRevizeTlakoveNadoby,UpravenaPeriodaVnitrniRevizeTlakoveNadoby,SCLahve")] SCProvozu sCProvozu)
 {
     if (ModelState.IsValid)
     {
         try
         {
             db.Entry(sCProvozu).State = EntityState.Modified;
             db.SaveChanges();
         }
         catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
         int Provoz   = sCProvozu.ProvozId;
         int Umisteni = sCProvozu.Umisteni.Value;
         int Zakaznik = db.Provoz.Where(p => p.Id == Provoz).Select(p => p.ZakaznikId).FirstOrDefault();
         return(RedirectToAction("Details", "Umistenis", new { id = Umisteni, Provoz, Zakaznik }));
     }
     ViewBag.ProvozId       = new SelectList(db.Provoz, "Id", "NazevProvozu", sCProvozu.ProvozId);
     ViewBag.SerioveCisloId = new SelectList(db.SerioveCislo, "Id", "SerioveCislo1", sCProvozu.SerioveCisloId);
     ViewBag.StatusId       = new SelectList(db.Status, "Id", "NazevStatusu", sCProvozu.StatusId);
     ViewBag.Umisteni       = new SelectList(db.Umisteni, "Id", "NazevUmisteni", sCProvozu.Umisteni);
     ViewBag.Zakaznik       = db.Provoz.Where(p => p.Id == sCProvozu.ProvozId).Select(p => p.ZakaznikId).FirstOrDefault();
     ViewBag.Provoz         = sCProvozu.ProvozId;
     ViewBag.BaterieArtikl  = new SelectList(db.Artikl.Where(r => r.SkupinaArtiklu1.Id == 2), "Id", "Nazev", sCProvozu.BaterieArtikl);
     return(View(sCProvozu));
 }
コード例 #17
0
        public static void VymenaLahve(int RevizeSCid, int AriclId, string SC, DateTime DatumVyroby, DateTime DatumDodani)
        {
            RevizeSC oldRevizeSC = new RevizeSC();
            Revize   revize      = new Revize();
            Provoz   provoz      = new Provoz();

            RevizeSC     newRevizeSC     = new RevizeSC();
            SCProvozu    oldSCProvozu    = new SCProvozu();
            SCProvozu    newSCProvozu    = new SCProvozu();
            SerioveCislo oldSerioveCislo = new SerioveCislo();
            SerioveCislo newSerioveCislo = new SerioveCislo();
            VymenyLahvi  vymenyLahvi     = new VymenyLahvi();


            oldRevizeSC     = RevizeSC.GetRevizeSCByRevizeSCid(RevizeSCid);
            oldSCProvozu    = SCProvozu.GetSCProvozuById(oldRevizeSC.SCProvozuId);
            oldSerioveCislo = SerioveCislo.GetSerioveCisloById(oldSCProvozu.SerioveCisloId);
            revize          = Revize.GetById(oldRevizeSC.RevizeId);
            provoz          = Provoz.GetById(revize.ProvozId);

            SCImport sCImport = new SCImport();

            sCImport.ArtiklId           = oldSerioveCislo.ArtiklId;
            sCImport.ArtiklSAPKod       = oldSerioveCislo.Artikl.KodSAP;
            sCImport.Baterie            = oldSCProvozu.Baterie;
            sCImport.BaterieArtikl      = oldSCProvozu.BaterieArtikl;
            sCImport.DatumBaterie       = oldSCProvozu.DatumBaterie;
            sCImport.DatumDodani        = DatumDodani;
            sCImport.DatumPosledniZmeny = revize.DatumRevize;
            sCImport.DatumPrirazeni     = revize.DatumRevize;
            sCImport.DatumPyro          = oldSCProvozu.DatumPyro;
            sCImport.DatumRevize        = oldSCProvozu.DatumRevize;
            sCImport.DatumTlkZk         = revize.DatumRevize;
            sCImport.DatumVymeny        = null;
            sCImport.DatumVyroby        = revize.DatumRevize;
            sCImport.Lokace             = oldSCProvozu.Lokace;
            sCImport.Proverit           = false;
            sCImport.Provozy            = oldSCProvozu.ProvozId;
            sCImport.SerioveCislo       = SC;
            sCImport.Submitted          = true;
            sCImport.Umisteni           = oldSCProvozu.Umisteni.Value;
            sCImport.Zakaznik           = provoz.ZakaznikId;
            sCImport.ZakaznikSAPKod     = provoz.Zakaznik.KodSAP;
            sCImport.Znaceni            = oldSCProvozu.Znaceni;

            // vytvoreni Serioveho cisla akcniho prvku
            var id = SerioveCislo.AddSeriovecislo(sCImport);

            newSerioveCislo = SerioveCislo.GetSerioveCisloById(id);
            // vyvoreni noveho provozusc
            var idscprovozu = SCProvozu.AddSCProvozu(sCImport, id);

            newSCProvozu = SCProvozu.GetSCProvozuById(idscprovozu);
            //Dohledani serioveho cisla lahve
            var seriovecislolahve = DohledaniSeriovehoCislaLahveDleSeriovehoCislaAkcnihoprvku(newSerioveCislo.SerioveCislo1, newSerioveCislo.Artikl.KodSAP);

            // vytvoření vazby vymeny mezi jednotlivými SCProvozu
            vymenyLahvi = VymenyLahvi.GenerujVymenu(oldSCProvozu, newSCProvozu, revize.DatumRevize, revize.Id, seriovecislolahve);
            // zneaktivneni stareho provozusc
            SCProvozu.ZneaktivniSCProvozu(oldSCProvozu, revize.DatumRevize);

            // odebrani stare revizesc
            RevizeSC.Remove(oldRevizeSC.Id);

            // vymena v nasledujicich otevrenych revizich stareho revizesc za noveho
            RevizeSC.ChangeRevizeSCForUpcomingOpenRevision(oldSCProvozu, newSCProvozu, revize.DatumRevize);
        }
コード例 #18
0
        public ActionResult ImportSCtoServis([Bind(Include = "Zakaznik, Provozy, Umisteni, SerioveCislo, ArtiklId, DatumVyroby, DatumVymeny, DatumDodani, Submitted, DatumRevize, DatumBaterie, DatumPyro, DatumTlkZk, DatumPrirazeni, Lokace, Znaceni,Baterie,Proverit, BaterieArtikl,UpravenaPeriodaRevize,UpravenaPeriodaBaterie,UpravenaPeriodaPyro,UpravenaPeriodaTlkZk,DatumRevizeTlakoveNadoby,DatumVnitrniRevizeTlakoveNadoby,UpravenaPeriodaRevizeTlakoveNadoby,UpravenaPeriodaVnitrniRevizeTlakoveNadoby ")] SCImport scimport)
        {
            int id          = 0;
            int idscprovozu = 0;

            ViewBag.SkupinaArtiklu = db.Artikl.Where(t => t.Id == scimport.ArtiklId).Select(t => t.SkupinaArtiklu).FirstOrDefault();
            ViewBag.Revize         = db.Artikl.Where(t => t.Id == scimport.ArtiklId).Select(t => t.Revize).FirstOrDefault();
            ViewBag.TlakovaZk      = db.Artikl.Where(t => t.Id == scimport.ArtiklId).Select(t => t.TlakovaZk).FirstOrDefault();
            ViewBag.VymenaBaterie  = db.Artikl.Where(t => t.Id == scimport.ArtiklId).Select(t => t.VymenaBaterie).FirstOrDefault();
            ViewBag.VymenaPyro     = db.Artikl.Where(t => t.Id == scimport.ArtiklId).Select(t => t.VymenaPyro).FirstOrDefault();
            ViewBag.TlakovaNadoba  = db.Artikl.Where(t => t.Id == scimport.ArtiklId).Select(t => t.TlakovaNadoba).FirstOrDefault();



            //if (scimport.DatumVyroby == DateTime.MinValue) { scimport.DatumVyroby = DateTime.Now; }
            //if (scimport.DatumDodani == DateTime.MinValue) { scimport.DatumDodani = DateTime.Now; }
            if (scimport.DatumPosledniZmeny == DateTime.MinValue)
            {
                scimport.DatumPosledniZmeny = DateTime.Now;
            }


            if (scimport.Submitted == true)
            {
                if (scimport.DatumPrirazeni == null)
                {
                    scimport.DatumPrirazeni = scimport.DatumDodani;
                }
                //if (scimport.DatumTlkZk == null) { scimport.DatumTlkZk = scimport.DatumVyroby; }
                id          = SerioveCislo.AddSeriovecislo(scimport);
                idscprovozu = SCProvozu.AddSCProvozu(scimport, id);
                // uložení datumů do sesion
                if (scimport.DatumBaterie > DateTime.MinValue || scimport.DatumBaterie == null)
                {
                    Session["DatumBaterie"] = scimport.DatumBaterie;
                }
                if (scimport.DatumDodani > DateTime.MinValue || scimport.DatumDodani == null)
                {
                    Session["DatumDodani"] = scimport.DatumDodani;
                }
                if (scimport.DatumPrirazeni > DateTime.MinValue || scimport.DatumPrirazeni == null)
                {
                    Session["DatumPrirazeni"] = scimport.DatumPrirazeni;
                }
                if (scimport.DatumPyro > DateTime.MinValue || scimport.DatumPyro == null)
                {
                    Session["DatumPyro"] = scimport.DatumPyro;
                }
                if (scimport.DatumRevize > DateTime.MinValue || scimport.DatumRevize == null)
                {
                    Session["DatumRevize"] = scimport.DatumRevize;
                }
                if (scimport.DatumTlkZk > DateTime.MinValue || scimport.DatumTlkZk == null)
                {
                    Session["DatumTlkZk"] = scimport.DatumTlkZk;
                }
                if (scimport.DatumVymeny > DateTime.MinValue || scimport.DatumVymeny == null)
                {
                    Session["DatumVymeny"] = scimport.DatumVymeny;
                }
                if (scimport.DatumVyroby > DateTime.MinValue || scimport.DatumVyroby == null)
                {
                    Session["DatumVyroby"] = scimport.DatumVyroby;
                }
                if (scimport.UpravenaPeriodaRevize != null)
                {
                    Session["UpravenaPeriodaRevize"] = scimport.UpravenaPeriodaRevize;
                }

                if ((id > 0) || (idscprovozu > 0))
                {
                    return(RedirectToAction("Details", "Umistenis", new { id = scimport.Umisteni, Provoz = scimport.Provozy, scimport.Zakaznik }));
                }
            }
            if ((scimport.Submitted == false) || ((id == 0) || (idscprovozu == 0)))
            {
                // načtení datumů ze session
                try
                {
                    var DatumBaterie = Convert.ToDateTime(Session["DatumBaterie"]);
                    if (DatumBaterie > DateTime.MinValue)
                    {
                        scimport.DatumBaterie = DatumBaterie;
                    }
                    else
                    {
                        scimport.DatumBaterie = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumBaterie - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumDodani = Convert.ToDateTime(Session["DatumDodani"]);
                    if (DatumDodani > DateTime.MinValue)
                    {
                        scimport.DatumDodani = DatumDodani;
                    }
                    else
                    {
                        scimport.DatumDodani = DateTime.Now;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumDodani - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumPrirazeni = Convert.ToDateTime(Session["DatumPrirazeni"]);
                    if (DatumPrirazeni > DateTime.MinValue)
                    {
                        scimport.DatumPrirazeni = DatumPrirazeni;
                    }
                    else
                    {
                        scimport.DatumPrirazeni = DateTime.Now;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumPrirazeni - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumPyro = Convert.ToDateTime(Session["DatumPyro"]);
                    if (DatumPyro > DateTime.MinValue)
                    {
                        scimport.DatumPyro = DatumPyro;
                    }
                    else
                    {
                        scimport.DatumPyro = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumPyro - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumRevize = Convert.ToDateTime(Session["DatumRevize"]);
                    if (DatumRevize > DateTime.MinValue)
                    {
                        scimport.DatumRevize = DatumRevize;
                    }
                    else
                    {
                        scimport.DatumRevize = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumRevize - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumTlkZk = Convert.ToDateTime(Session["DatumTlkZk"]);
                    if (DatumTlkZk > DateTime.MinValue)
                    {
                        scimport.DatumTlkZk = DatumTlkZk;
                    }
                    else
                    {
                        scimport.DatumTlkZk = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumTlkZk - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumVymeny = Convert.ToDateTime(Session["DatumVymeny"]);
                    if (DatumVymeny > DateTime.MinValue)
                    {
                        scimport.DatumVymeny = DatumVymeny;
                    }
                    else
                    {
                        scimport.DatumVymeny = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumVymeny - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    var DatumVyroby = Convert.ToDateTime(Session["DatumVyroby"]);
                    if (DatumVyroby > DateTime.MinValue)
                    {
                        scimport.DatumVyroby = DatumVyroby;
                    }
                    else
                    {
                        scimport.DatumVyroby = DateTime.Now;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumVyroby - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }
                try
                {
                    int?UpravenaPeriodaRevize = Convert.ToInt32(Session["UpravenaPeriodaRevize"]);
                    if (UpravenaPeriodaRevize != null && UpravenaPeriodaRevize != 0)
                    {
                        scimport.UpravenaPeriodaRevize = UpravenaPeriodaRevize;
                    }
                    else
                    {
                        scimport.UpravenaPeriodaRevize = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Details - Seassion Read - DatumVyroby - Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                }

                ViewBag.Zakaznik      = new SelectList(db.Zakaznik, "Id", "NazevZakaznika", scimport.Zakaznik);
                ViewBag.Provozy       = new SelectList(db.Provoz.Where(p => p.ZakaznikId == scimport.Zakaznik), "Id", "NazevProvozu", scimport.Provozy);
                ViewBag.Umisteni      = new SelectList(db.Umisteni.Where(u => u.ProvozId == scimport.Provozy), "Id", "NazevUmisteni", scimport.Umisteni);
                ViewBag.ArtiklId      = new SelectList(db.Artikl.Where(r => r.SkupinaArtiklu1.Id != 129), "Id", "Nazev", scimport.ArtiklId);
                ViewBag.BaterieArtikl = new SelectList(db.Artikl.Where(r => r.SkupinaArtiklu1.Id == 2), "Id", "Nazev");
            }
            return(View(scimport));
        }
コード例 #19
0
ファイル: SIL.cs プロジェクト: petnovcz/VST_sprava_servisu
        public static List <SIL_dobaprovozu> Calc_SIL_DobaProvozu(int Rok, SIL_dobaprovozu PrumerDobyProvozu)
        {
            List <SIL_dobaprovozu> list = new List <SIL_dobaprovozu>();

            string        connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            StringBuilder sql = new StringBuilder();


            sql.Append($" declare @rok as int = {Rok} ");
            sql.Append($" declare @prumerTAKU float = '{PrumerDobyProvozu.TAKU.ToString().Replace(",", ".")}'");
            sql.Append($" declare @prumerTAKUII float = '{PrumerDobyProvozu.TAKUII.ToString().Replace(",", ".")}'");
            sql.Append(" select *, " +
                       "case when (((x.II - X.I) * 1.0 / x.PocetdnimeziIaIIrevizi) * 1.0 IS NULL) then @prumerTAKU else CAST(((x.II - X.I) * 1.0 / x.PocetdnimeziIaIIrevizi) * 1.0 as float) end as 'TAKU',"
                       + " case when (((x.II - X.I) * 1.0 / x.PocetdnimeziIaIIrevizi * 1.0) * 365.25 IS null) then @prumerTAKUII else CAST(((x.II - X.I) * 1.0 / x.PocetdnimeziIaIIrevizi * 1.0) * 365.25 as float) end as 'TAKUII' "
                       + " from( select t0.NazevZakaznika," +
                       "t0.Id as 'ZakaznikId', " +
                       "t1.NazevProvozu,t1.Id as 'ProvozId', " +
                       "t2.NazevUmisteni,t2.Id as 'UmisteniId', " +
                       "t5.Nazev as 'Artikl'," +
                       "t5.Id as 'ArtiklId', " +
                       "t4.SerioveCislo, " +
                       "t4.Id as 'SerioveCisloId'," +
                       "t3.Id as 'SCProvozuId', " +
                       "(SELECT HodinyProvozu FROM( SELECT ROW_NUMBER() OVER(ORDER BY coalesce(t0.KontrolaProvedenaDne, t0.Datumrevize) desc) AS rownumber, t1.HodinyProvozu from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok <= @rok  and t1.SCProvozuId = t3.id) as foo  WHERE rownumber = 2) as 'I',");
            sql.Append("(SELECT KontrolaProvedenaDne FROM( SELECT ROW_NUMBER() OVER(ORDER BY coalesce(t0.KontrolaProvedenaDne, t0.Datumrevize) desc) AS rownumber, t0.KontrolaProvedenaDne from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok <= @rok  and t1.SCProvozuId = t3.id) as foo  WHERE rownumber = 2 ) as 'DatumI', ");
            sql.Append(" (SELECT HodinyProvozu FROM( SELECT ROW_NUMBER() OVER (ORDER BY coalesce(t0.KontrolaProvedenaDne, t0.Datumrevize) desc) AS rownumber, t1.HodinyProvozu from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok <= @rok  and t1.SCProvozuId = t3.id) as foo WHERE rownumber = 1) as 'II',");
            sql.Append(" (SELECT KontrolaProvedenaDne FROM( SELECT ROW_NUMBER() OVER(ORDER BY coalesce(t0.KontrolaProvedenaDne, t0.Datumrevize) desc) AS rownumber, t0.KontrolaProvedenaDne from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok <= @rok  and t1.SCProvozuId = t3.id) as foo  WHERE rownumber = 1 ) as 'DatumII',");
            sql.Append(" CAST(DateDiff(D, ((SELECT KontrolaProvedenaDne FROM( SELECT ROW_NUMBER() OVER(ORDER BY coalesce(t0.KontrolaProvedenaDne, t0.Datumrevize) desc) AS rownumber, t0.KontrolaProvedenaDne from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok <= @rok  and t1.SCProvozuId = t3.id) as foo WHERE rownumber = 2)),");
            sql.Append(" (SELECT KontrolaProvedenaDne FROM( SELECT ROW_NUMBER() OVER (ORDER BY coalesce(t0.KontrolaProvedenaDne, t0.Datumrevize) desc) AS rownumber, t0.KontrolaProvedenaDne from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok <= @rok  and t1.SCProvozuId = t3.id) as foo WHERE rownumber = 1)) as decimal) as 'PocetdnimeziIaIIrevizi',");
            sql.Append(" (select COUNT(*) from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok = @rok  and t1.SCProvozuId = t3.id) as 'count' from Zakaznik t0 left join Provoz t1 on t1.ZakaznikId = t0.Id left join Umisteni t2 on t2.ProvozId = t1.Id ");
            sql.Append(" left join SCProvozu t3 on t3.Umisteni = t2.Id left join SerioveCislo t4 on t4.Id = t3.SerioveCisloId left join Artikl t5 on t5.Id = t4.ArtiklId left join SkupinaArtiklu t6 on t6.Id = t5.SkupinaArtiklu");
            sql.Append(" where t6.Id = 130 and (select COUNT(*) from Revize t0 left join RevizeSC t1 on t0.Id = t1.RevizeId where Rok = @rok  and t1.SCProvozuId = t3.id) > 0 and t3.StatusId = 1  ) X");

            //log.Debug($"Nacteni dat pri importu artiklu z SAP {sql.ToString()}");
            SqlConnection cnn = new SqlConnection(connectionString);
            //SqlConnection con = new SqlConnection(cnn);

            SqlCommand cmd = new SqlCommand
            {
                Connection  = cnn,
                CommandText = sql.ToString()
            };

            cnn.Open();
            cmd.ExecuteNonQuery();
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                //MAKES IT HERE
                while (dr.Read())
                {
                    SIL_dobaprovozu sil = new SIL_dobaprovozu();
                    try
                    {
                        sil.ZakaznikId = dr.GetInt32(dr.GetOrdinal("ZakaznikId"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: ZakaznikId " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.ProvozId = dr.GetInt32(dr.GetOrdinal("ProvozId"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: ProvozId" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }

                    try
                    {
                        sil.UmisteniId = dr.GetInt32(dr.GetOrdinal("UmisteniId"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: UmisteniId" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.SCProvozuId = dr.GetInt32(dr.GetOrdinal("SCProvozuId"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: SCProvozuId" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.SerioveCisloId = dr.GetInt32(dr.GetOrdinal("SerioveCisloId"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: SerioveCisloId" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.ArtiklId = dr.GetInt32(dr.GetOrdinal("ArtiklId"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: ArtiklId" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.DobaprovozuI = dr.GetInt64(dr.GetOrdinal("I"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: DobaprovozuI" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.DobaprovozuII = dr.GetInt64(dr.GetOrdinal("II"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: DobaprovozuII" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.DniMeziRevizemi = dr.GetDecimal(dr.GetOrdinal("PocetdnimeziIaIIrevizi"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: DniMeziRevizemi" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.PocetReviziVRoce = dr.GetInt32(dr.GetOrdinal("count"));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: PocetReviziVRoce" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.TAKU = Convert.ToDecimal(dr.GetDouble(dr.GetOrdinal("TAKU")));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: TAKU" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.TAKUII = Convert.ToDecimal(dr.GetDouble(dr.GetOrdinal("TAKUII")));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: TAKUII" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.DatumI = (dr.GetDateTime(dr.GetOrdinal("DatumI")));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: TAKUII" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }
                    try
                    {
                        sil.DatumII = (dr.GetDateTime(dr.GetOrdinal("DatumII")));
                    }
                    catch (Exception ex)
                    {
                        log.Debug("Error number: TAKUII" + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException);
                    }


                    sil.Zakaznik     = Zakaznik.GetById(sil.ZakaznikId);
                    sil.Provoz       = Provoz.GetById(sil.ProvozId);
                    sil.Umisteni     = Umisteni.GetById(sil.UmisteniId);
                    sil.SerioveCislo = SerioveCislo.GetSerioveCisloById(sil.SerioveCisloId);
                    sil.SCProvozu    = SCProvozu.GetSCProvozuById(sil.SCProvozuId);
                    sil.Artikl       = Artikl.GetArtiklById(sil.ArtiklId);

                    list.Add(sil);
                }
            }
            cnn.Close();
            return(list);
        }