internal protected static Umisteni GetById(int Id)
        {
            var umisteni = new Umisteni();

            using (var dbCtx = new Model1Container())
            {
                umisteni = dbCtx.Umisteni.Where(r => r.Id == Id).FirstOrDefault();
            }
            return(umisteni);
        }
Exemple #2
0
        public ActionResult Create(int Provoz, int Zakaznik)
        {
            ViewBag.ProvozId = new SelectList(db.Provoz.Where(m => m.Id == Provoz), "Id", "NazevProvozu", Provoz);
            ViewBag.Provoz   = Provoz;
            ViewBag.Zakaznik = Zakaznik;
            Umisteni um = new Umisteni();

            um.ProvozId = Provoz;

            return(View(um));
        }
Exemple #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Umisteni umisteni = db.Umisteni.Find(id);
            var      provozId = umisteni.ProvozId;

            try
            {
                db.Umisteni.Remove(umisteni);
                db.SaveChanges();
            }
            catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
            return(RedirectToAction("Details", "Provozy", new { Id = provozId }));
        }
Exemple #4
0
        public ActionResult Header(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Umisteni umisteni = db.Umisteni.Find(id);

            if (umisteni == null)
            {
                return(HttpNotFound());
            }

            return(View(umisteni));
        }
Exemple #5
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Umisteni umisteni = db.Umisteni.Find(id);

            if (umisteni == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Provoz   = umisteni.ProvozId;
            ViewBag.Zakaznik = db.Provoz.Where(t => t.Id == umisteni.ProvozId).Select(t => t.ZakaznikId).FirstOrDefault();
            return(View(umisteni));
        }
Exemple #6
0
 public ActionResult Edit([Bind(Include = "Id,ProvozId,NazevUmisteni, SamostatnaRevize,UkonceniZaruky")] Umisteni umisteni)
 {
     if (ModelState.IsValid)
     {
         int zakaznik = db.Provoz.Where(m => m.Id == umisteni.ProvozId).Select(m => m.ZakaznikId).FirstOrDefault();
         try
         {
             db.Entry(umisteni).State = EntityState.Modified;
             db.SaveChanges();
         }
         catch (Exception ex) { log.Error("Error number: " + ex.HResult + " - " + ex.Message + " - " + ex.Data + " - " + ex.InnerException); }
         return(RedirectToAction("Details", "Provozy", new { Id = umisteni.ProvozId }));
     }
     ViewBag.ProvozId = new SelectList(db.Provoz.Where(m => m.Id == umisteni.ProvozId), "Id", "NazevProvozu", umisteni.ProvozId);
     return(View(umisteni));
 }
Exemple #7
0
        public ActionResult Edit(int?id, int Provoz, int Zakaznik)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Umisteni umisteni = db.Umisteni.Find(id);

            if (umisteni == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProvozId = new SelectList(db.Provoz.Where(m => m.Id == umisteni.ProvozId), "Id", "NazevProvozu", umisteni.ProvozId);
            ViewBag.Provoz   = Provoz;
            ViewBag.Zakaznik = Zakaznik;
            return(View(umisteni));
        }
Exemple #8
0
        public ActionResult Details(int?id, int Provoz, int Zakaznik)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Umisteni umisteni = db.Umisteni.Find(id);

            if (umisteni == null)
            {
                return(HttpNotFound());
            }
            var x = db.SCProvozu
                    .Include(s => s.Status);

            x = x.Where(s => s.StatusId != 2 && s.ProvozId == umisteni.ProvozId && s.Umisteni == umisteni.Id);

            umisteni.SCProvozu = null;
            ViewBag.SCProvozu  = x.ToList();
            ViewBag.Provoz     = Provoz;
            ViewBag.Zakaznik   = Zakaznik;

            return(View(umisteni));
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        public static void GenerujReviziTlakoveZkousky(int ZakaznikId, int ProvozId, int?UmisteniId, int Rok)
        {
            GenerovaniRevizeTlakoveZkousky GRTZ = new GenerovaniRevizeTlakoveZkousky
            {
                Rok        = Rok,
                ZakaznikId = ZakaznikId,
                Zakaznik   = Zakaznik.GetById(ZakaznikId),
                ProvozId   = ProvozId,
                Provoz     = Provoz.GetById(ProvozId),
                UmisteniId = UmisteniId,
                // dohledání exisujících revizí pro vybraný rok
                Revize1 = Revize.ReturnRevision(ZakaznikId, ProvozId, Rok, 1, UmisteniId, false),
                Revize2 = Revize.ReturnRevision(ZakaznikId, ProvozId, Rok, 2, UmisteniId, false)
            };

            if (UmisteniId != null)
            {
                GRTZ.Umisteni = Umisteni.GetById(UmisteniId.Value);
            }
            int pocetTlkZkR1 = 0; int pocetTlkZkR2 = 0; int revize1 = 0; int revize2 = 0;

            try
            {
                revize1 = GRTZ.Revize1.Id;
            }
            catch (Exception ex)
            {
                log.Debug($"Nenalazena Revize1 {ex.Data} {ex.HResult} {ex.InnerException} {ex.Message}");
            }
            try
            {
                revize2 = GRTZ.Revize2.Id;
            }
            catch (Exception ex)
            {
                log.Debug($"Nenalazena Revize2 {ex.Data} {ex.HResult} {ex.InnerException} {ex.Message}");
            }
            using (var db = new Model1Container())
            {
                //Výpočet počtu artiklů, které mají příznak tlakové zkoušky pro jednotlivé revize
                pocetTlkZkR1 = db.RevizeSC.Where(t => t.RevizeId == revize1 && t.TlakovaZkouska == true).Count();
                pocetTlkZkR2 = db.RevizeSC.Where(t => t.RevizeId == revize2 && t.TlakovaZkouska == true).Count();
            }

            int pocetTlkZ = pocetTlkZkR1 + pocetTlkZkR2;



            // Pokud existují artikly v revizích, které mají příznak tlakové zkoušky dojde ke generování třetí revize a přesun do speciální tlakové zkoušky
            if (pocetTlkZ > 0)
            {
                // načení záznamů, ketré jsou s evidovanou tlakovou zkouškou
                if (pocetTlkZkR1 > 0)
                {
                    try
                    {
                        GRTZ.TlakoveZkouskyRev1 = RevizeSC.SeznamTlakovychZkousekRevize(GRTZ.Revize1.Id);
                    }
                    catch (Exception ex) { log.Debug($" GRTZ.TlakoveZkouskyRev1 -  {ex.Data} {ex.HResult} {ex.InnerException} {ex.Message}"); }
                }
                if (pocetTlkZkR2 > 0)
                {
                    try
                    {
                        GRTZ.TlakoveZkouskyRev2 = RevizeSC.SeznamTlakovychZkousekRevize(GRTZ.Revize2.Id);
                    }
                    catch (Exception ex) { log.Debug($" GRTZ.TlakoveZkouskyRev2 -  {ex.Data} {ex.HResult} {ex.InnerException} {ex.Message}"); }
                }
                // pokud neexisuje revize na tlakovou zkoušku vygenerování revize
                var exist = Revize.ExistRevision(GRTZ.ZakaznikId, GRTZ.ProvozId, GRTZ.Rok, 3, GRTZ.UmisteniId);
                if (exist == true)
                {
                    //pokud exisuje nacte se
                    GRTZ.Revize3 = Revize.ReturnRevision(GRTZ.ZakaznikId, GRTZ.ProvozId, Rok, 3, GRTZ.UmisteniId, null);
                }
                else
                {
                    //pokud neexistuje vygeneruje se
                    try
                    {
                        GRTZ.Revize3 = Revize.GenerateRevision(GRTZ.ProvozId, GRTZ.Rok, 3, System.DateTime.Now, 1, GRTZ.UmisteniId, GRTZ.Revize1.Nabidka, GRTZ.Revize1.Projekt);
                    }
                    catch (Exception ex)
                    {
                        log.Debug($" GRTZ.Revize3 -  {ex.Data} {ex.HResult} {ex.InnerException} {ex.Message}");
                    }
                }
                //přesun tlakových zkoušek do speciální revize
                if (pocetTlkZkR1 > 0)
                {
                    try
                    {
                        RevizeSC.LoopRevizeSCTlakoveZkousky(GRTZ.Revize3, GRTZ.TlakoveZkouskyRev1);
                    }
                    catch (Exception ex) { }
                }
                if (pocetTlkZkR1 > 0)
                {
                    try
                    {
                        RevizeSC.LoopRevizeSCTlakoveZkousky(GRTZ.Revize3, GRTZ.TlakoveZkouskyRev2);
                    }
                    catch (Exception ex) { }
                }
                //aktualizace hlavičkových údajů na jednotlivých revizích
                try
                {
                    Revize.UpdateRevizeHeader(GRTZ.Revize1.Id);
                }
                catch (Exception ex)
                { }
                try
                {
                    Revize.UpdateRevizeHeader(GRTZ.Revize2.Id);
                }
                catch (Exception ex)
                { }
                try
                {
                    Revize.UpdateRevizeHeader(GRTZ.Revize3.Id);
                }
                catch (Exception ex)
                { }
            }
        }