Esempio n. 1
0
 public async Task <List <Material> > SearchMaterial(string text)
 {
     using (var materialDao = new MaterialDao())
     {
         return(await materialDao.GetAllAsync().Where(m => m.Describe.Contains(text)).ToListAsync());
     }
 }
Esempio n. 2
0
 public async Task RemoveMaterial(Guid id)
 {
     using (var materialDao = new MaterialDao())
     {
         await materialDao.RemoveAsync(id);
     }
 }
Esempio n. 3
0
        private void BtnBuscarMaterial_Click(object sender, RoutedEventArgs e)
        {
            if (!txtCodigoMaterial.Text.Equals(""))
            {
                Material material = new Material
                {
                    Codigo = txtCodigoMaterial.Text
                };

                material = MaterialDao.BuscarMaterialPorCodigo(material);

                if (material != null)
                {
                    txtNomeMaterial.Text  = material.Nome;
                    txtDescricao.Text     = material.Descricao;
                    txtPrecoMaterial.Text = material.Valor.ToString("C2");
                    txtfabricante.Text    = material.Fabricante;
                }
                else
                {
                    MessageBox.Show("Esse Material não está cadastrado!",
                                    "Busca de Material");
                }
            }
            else
            {
                MessageBox.Show("Por Favor Preencha o campo Código do Material!",
                                "Busca de Material");
            }
        }
Esempio n. 4
0
 public async Task <bool> ExistsMaterial(Guid materialId)
 {
     using (IDAL.Master.IMaterialDao materialDao = new MaterialDao())
     {
         return(await materialDao.GetAllAsync().AnyAsync(m => m.Id == materialId));
     }
 }
Esempio n. 5
0
 public async Task <int> GetDataCount()
 {
     using (var materialDao = new MaterialDao())
     {
         return(await materialDao.GetAllAsync().CountAsync());
     }
 }
Esempio n. 6
0
        public IEnumerable <MaterialImpl> Get()
        {
            var dao = new MaterialDao();

            return(dao.GetAll().Select(item => new MaterialImpl()
            {
                Id = item.Id, Druh = item.Druh, Pn = item.Pn, Popis = item.Popis, SapCislo = item.SapCislo, SapPopis = item.PopisSap
            }).ToList());
        }
Esempio n. 7
0
        public MaterialImpl Get(int id)
        {
            var dao  = new MaterialDao();
            var item = dao.GetById(id);

            return(new MaterialImpl()
            {
                Id = item.Id,
                Druh = item.Druh,
                Pn = item.Pn,
                Popis = item.Popis,
                SapCislo = item.SapCislo,
                SapPopis = item.PopisSap
            });
        }
Esempio n. 8
0
        public async Task EditMaterial(Guid materialId, string code, string largyCategory, string smallCategory, string describe, string unit, string note)
        {
            using (var materialDao = new MaterialDao())
            {
                var material = await materialDao.GetOneByIdAsync(materialId);

                material.Code          = code;
                material.LargeCategory = largyCategory;
                material.SmallCategory = smallCategory;
                material.Describe      = describe;
                material.Unit          = unit;
                material.Note          = note;
                await materialDao.EditAsync(material);
            }
        }
Esempio n. 9
0
 public async Task CreateMaterial(string code, string largyCategory, string smallCategory, string describe, string unit, string note)
 {
     using (var materialDao = new MaterialDao())
     {
         await materialDao.CreateAsync(new Material()
         {
             Code          = code,
             LargeCategory = largyCategory,
             SmallCategory = smallCategory,
             Describe      = describe,
             Unit          = unit,
             Note          = note
         });
     }
 }
Esempio n. 10
0
        public ActionResult Edit(int id)
        {
            var uvd  = new UkolVzorkovaniDao();
            var item = uvd.GetById(id);

            if (item == null)
            {
                return(RedirectToAction("Index"));
            }
            var matDao       = new MaterialDao();
            var materialList = matDao.GetAll();

            ViewBag.materialList = materialList;
            TempData["UkolVzorkovaniHistory"] = item;
            return(View(item));
        }
        private void BtnSalvar_Click(object sender, RoutedEventArgs e)
        {
            if ((!txtCodigo.Text.Equals("")) && (!txtNome.Text.Equals("")) && (!txtFabricante.Text.Equals("")) && (!txtValor.Text.Equals("")))
            {
                Material material = new Material
                {
                    Codigo     = txtCodigo.Text.ToUpper(),
                    Nome       = txtNome.Text.ToUpper(),
                    Descricao  = txtDescricao.Text.ToUpper(),
                    Fabricante = txtFabricante.Text.ToUpper(),
                    Valor      = Convert.ToDouble(txtValor.Text)
                };

                if (MaterialDao.CadastrarMaterial(material))
                {
                    MessageBox.Show("Material cadastrado com sucesso!",
                                    "SistemaOrcamento", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    LimparFormulario();

                    //materiaisGrid.Add(material);
                    dtaMateriais.ItemsSource = MaterialDao.ListarMaterial();
                    dtaMateriais.Items.Refresh();
                }
                else
                {
                    MessageBox.Show("Esse material já existe!",
                                    "Sistema Orcamento", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                txtCodigo.IsEnabled     = false;
                txtNome.IsEnabled       = false;
                txtDescricao.IsEnabled  = false;
                txtFabricante.IsEnabled = false;
                txtValor.IsEnabled      = false;
                btnSalvar.Visibility    = Visibility.Collapsed;
                btnCadastrar.IsEnabled  = true;
                btnBuscar.IsEnabled     = true;
            }
            else
            {
                MessageBox.Show("Por favor preencher todos os campos!",
                                "Sistema de Orçamento", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
Esempio n. 12
0
        public async Task <List <DTO.Master.MaterialDto> > GetAllMaterial(int pageIndex = 1, int pageSize = 10, bool asc = true)
        {
            using (var materialDao = new MaterialDao())
            {
                return(await materialDao.GetAllByPageOrderAsync(pageIndex - 1, pageSize, asc).Select(m => new DTO.Master.MaterialDto()
                {
                    Id = m.Id,
                    Code = m.Code,
                    LargeCategory = m.LargeCategory,
                    SmallCategory = m.SmallCategory,
                    Describe = m.Describe,

                    Unit = m.Unit,
                    Note = m.Note,
                    CreateTime = m.CreateTime
                }).ToListAsync());
            }
        }
 private void BtnExcluir_Click(object sender, RoutedEventArgs e)
 {
     material.Nome = txtNome.Text;
     material      = MaterialDao.BuscarMaterialPorNome(material);
     if (material != null)
     {
         MaterialDao.DeletarMaterial(material);
         MessageBox.Show("Material removido com sucesso!",
                         "SistemaOrçamento", MessageBoxButton.OK, MessageBoxImage.Information);
         LimparFormulario();
     }
     else
     {
         MessageBox.Show("Material não cadastrado ou inexistente!",
                         "SistemaOrçamento", MessageBoxButton.OK, MessageBoxImage.Error);
         LimparFormulario();
     }
 }
Esempio n. 14
0
 public async Task <DTO.Master.MaterialDto> GetOneMaterialById(Guid materialId)
 {
     using (IDAL.Master.IMaterialDao materialDao = new MaterialDao())
     {
         return(await materialDao.GetAllAsync()
                .Where(m => m.Id == materialId)
                .Select(m => new DTO.Master.MaterialDto()
         {
             Id = m.Id,
             Code = m.Code,
             LargeCategory = m.LargeCategory,
             SmallCategory = m.SmallCategory,
             Describe = m.Describe,
             Unit = m.Unit,
             Note = m.Note,
             CreateTime = m.CreateTime,
         }).FirstAsync());
     }
 }
Esempio n. 15
0
        private void BtnAdicionarMaterial_Click(object sender, RoutedEventArgs e)
        {
            if (!txtNomeMaterial.Text.Equals("") && !txtCodigoMaterial.Text.Equals("") &&
                !txtPrecoMaterial.Text.Equals("") && !txtQuantidadeMaterial.Text.Equals("") && !txtfabricante.Text.Equals(""))
            {
                Material material = new Material
                {
                    Codigo = txtCodigoMaterial.Text
                };

                material = MaterialDao.BuscarMaterialPorCodigo(material);

                ItensMaterial listaMaterial = new ItensMaterial
                {
                    material   = material,
                    quantidade = Convert.ToInt32(txtQuantidadeMaterial.Text),
                };

                listaItensMateriais.Add(listaMaterial);

                dtaListaMateriais.ItemsSource = listaItensMateriais;
                dtaListaMateriais.Items.Refresh();

                //Calculo Valor Total
                totalMaterial        += material.Valor * Convert.ToInt32(txtQuantidadeMaterial.Text);
                txtTotalMaterial.Text = totalMaterial.ToString("C2");

                //Calculo do Imposto
                totalImpostoMaterial        += (material.Valor * Convert.ToInt32(txtQuantidadeMaterial.Text)) * 0.10;
                txtTotalImpostoMaterial.Text = totalImpostoMaterial.ToString("C2");

                //Calculo Valor Total
                totalGeralMaterial         = totalMaterial + totalImpostoMaterial;
                txtTotalGeralMaterial.Text = totalGeralMaterial.ToString("C2");

                LimparFormularioMaterial();
            }
            else
            {
                MessageBox.Show("Por Favor Preencha todos os campos!",
                                "Cadastro de Materiais");
            }
        }
        private void BtnBuscar_Click(object sender, RoutedEventArgs e)
        {
            txtCodigo.IsEnabled     = true;
            txtNome.IsEnabled       = false;
            txtDescricao.IsEnabled  = false;
            txtFabricante.IsEnabled = false;
            txtValor.IsEnabled      = false;


            if (!txtCodigo.Text.Equals(""))
            {
                Material material = new Material
                {
                    Codigo = txtCodigo.Text,
                };


                material = MaterialDao.BuscarMaterialPorCodigo(material);

                if (material != null)
                {
                    btnCadastrar.IsEnabled = false;
                    txtNome.Text           = material.Nome;
                    txtFabricante.Text     = material.Fabricante;
                    txtCodigo.Text         = material.Codigo;
                    txtDescricao.Text      = material.Descricao;
                    txtValor.Text          = material.Valor.ToString("C2");
                    btnEditar.IsEnabled    = true;
                    btnExcluir.IsEnabled   = true;
                }
                else
                {
                    MessageBox.Show("Material não localizado!",
                                    "Sistema de Orçamento", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Por favor Preencher o Código!",
                                "Sistema de Orçamento", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void BtnEditar_Click(object sender, RoutedEventArgs e)
        {
            Material material = new Material
            {
                Codigo = txtCodigo.Text,
            };

            material = MaterialDao.BuscarMaterialPorCodigo(material);

            if (clickEditar == false)
            {
                txtCodigo.IsEnabled     = false;
                txtNome.IsEnabled       = true;
                txtDescricao.IsEnabled  = true;
                txtFabricante.IsEnabled = true;
                txtValor.IsEnabled      = true;

                btnCadastrar.IsEnabled = false;
                btnEditar.IsEnabled    = true;
                btnExcluir.IsEnabled   = false;
                btnBuscar.IsEnabled    = false;

                btnEditar.Content = "Salvar";
                clickEditar       = true;
            }
            else
            {
                if ((!txtCodigo.Text.Equals("")) && (!txtNome.Text.Equals("")) && (!txtFabricante.Text.Equals("")) && (!txtValor.Text.Equals("")))
                {
                    material.Nome       = txtNome.Text.ToUpper();
                    material.Descricao  = txtDescricao.Text.ToUpper();
                    material.Fabricante = txtFabricante.Text.ToUpper();
                    material.Valor      = Convert.ToDouble(txtValor.Text.Replace("R$", ""));

                    MaterialDao.EditarMaterial(material);

                    MessageBox.Show("Material Alterado com sucesso!",
                                    "SistemaOrcamento", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    LimparFormulario();

                    //materiaisGrid.Add(material);
                    dtaMateriais.ItemsSource = MaterialDao.ListarMaterial();
                    dtaMateriais.Items.Refresh();

                    txtCodigo.IsEnabled     = false;
                    txtNome.IsEnabled       = false;
                    txtDescricao.IsEnabled  = false;
                    txtFabricante.IsEnabled = false;
                    txtValor.IsEnabled      = false;
                    btnSalvar.Visibility    = Visibility.Collapsed;
                    btnCadastrar.IsEnabled  = true;
                    btnBuscar.IsEnabled     = true;
                }
                else
                {
                    MessageBox.Show("Por favor preencher todos os campos!",
                                    "Sistema de Orçamento", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
        }
Esempio n. 18
0
 public MaterialService()
 {
     _daoManager = ServiceConfig.GetInstance().DaoManager;
     dao         = new MaterialDao(_daoManager);
 }
Esempio n. 19
0
        public ActionResult Edit(int id, Lop collection, bool poslatMailResiteli, bool poslatMailZadavateli, string produktyInput)
        {
            var history = TempData["LopHistory"] as Lop;

            if (history == null)
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                collection.Zadavatel = new UzivatelDao().GetByWindowsId(User.Identity.Name);
                if (ModelState.IsValid)
                {
                    if (produktyInput != history.MaterialyInput)
                    {
                        var lopMaterialDao = new LopMaterialDao();
                        foreach (var item in history.MaterialyInput.Split(';').Where(item => !produktyInput.Contains(";" + item + ";")).Where(item => item != ""))
                        { // Odebrání přebytečných
                            lopMaterialDao.Delete(history.Materialy.First(x => x.Produkt.Id == Convert.ToInt32(item)));
                        }
                        try
                        {//Přidání nových
                            foreach (var lopProdukt in produktyInput.Split(';').Where(item => item != "").Select(item => new LopMaterial()
                            {
                                Lop = new Lop()
                                {
                                    Id = collection.Id
                                },
                                Produkt = new MaterialDao().GetById(Convert.ToInt32(item)),
                                DateAdded = DateTime.Now
                            }).Where(lopProdukt => !history.MaterialyInput.Contains(lopProdukt.Produkt.Id.ToString())))
                            {
                                lopMaterialDao.Create(lopProdukt);
                            }
                        }
                        catch
                        {
                            TempData[MessagesHelper.Danger] = Resources.LopTexts.NepodariloSePripojeniProduktuKUkolu;
                        }
                    }

                    //TEST SHODNOTI

                    /*
                     * if (collection.IsSame(history)) //vrací FALSE, pokud nastala změna
                     * {
                     *  if (produktyInput != history.MaterialyInput)
                     *  {
                     *      TempData[MessagesHelper.Success] = Resources.LopTexts.ProvazaneMaterialyBylyAktualizovany;
                     *      return RedirectToAction("Detail/" + collection.Id);
                     *  }
                     *  TempData[MessagesHelper.Info] = Resources.LopTexts.NebylyProvedenyZadneZmeny;
                     *  return RedirectToAction("Detail/" + collection.Id);
                     * }
                     */

                    //KONTROLA JESTLI LZE ÚKOL UZAVŘÍT
                    if (collection.Status == StatusUkolu.Closed)
                    {
                        int celkemUkolu   = history.PocetSubUkoluCelkem();
                        int ukoluHotovych = history.PocetSubUkoluCompleted();

                        if (celkemUkolu != ukoluHotovych)
                        {
                            TempData[MessagesHelper.Info] = Resources.LopTexts.NelzeUkoncitUkol1 + " (" +
                                                            (celkemUkolu - ukoluHotovych) + ") " + Resources.LopTexts.NelzeUkoncitUkol2;
                        }
                    }
                    else
                    {
                        //ZMĚNA? - ULOŽÍME DO HISTORIE A PŘEPÍŠEME
                        var lopDao     = new LopDao();
                        var lopHistDao = new LopHistoryDao();

                        /*
                         * //uložení historie
                         * var copy = new LopHistory(history);
                         * lopHistDao.Create(copy);
                         */
                        //update objektu
                        collection.LastChangedDate = DateTime.Now;
                        lopDao.Update(collection);
                        TempData[MessagesHelper.Success] = Resources.LopTexts.LopUspesneAktualizovan;

                        if (poslatMailResiteli)
                        {
                            var s = Resources.LopTexts.BylUpravenLop +
                                    " <a href='/Lop/Detail/" + collection.Id + "?showHistory=true#historyBtn'>" + collection.Nazev + "</a>";
                            Notifikace.Create(collection.Resitel.Id, s);
                        }
                        if (poslatMailZadavateli)
                        {
                            var s = Resources.LopTexts.BylUpravenLop +
                                    " <a href='/Lop/Detail/" + collection.Id + "?showHistory=true#historyBtn'>" + collection.Nazev + "</a>";
                            Notifikace.Create(collection.Zadavatel.Id, s);
                        }
                        return(Redirect(Url.RouteUrl(new { controller = "Lop", action = "Detail", id = collection.Id, showHistory = true })));
                    }
                    //return RedirectToAction("Detail", new {id = collection.Id, showHistory = true});
                }
                TempData[MessagesHelper.Warning] = Resources.LopTexts.ZkontrolujteZadaneUdaje;
            }
            catch (Exception)
            {
                TempData[MessagesHelper.Danger] = Resources.LopTexts.DosloKNeocekavaneChybe;
            }
            TempData["LopHistory"] = history;
            var matDao       = new MaterialDao();
            var materialList = matDao.GetAll();

            ViewBag.materialList = materialList;
            collection.SubUkoly  = history.SubUkoly;
            collection.Materialy = history.Materialy;
            return(View(collection));
        }
Esempio n. 20
0
 public FrmMaterial()
 {
     InitializeComponent();
     MaterialDao = new MaterialDao();
 }
Esempio n. 21
0
        /// <summary>
        /// 保存生产信息
        /// </summary>
        /// <param name="produce"></param>
        /// <param name="scxq_list"></param>
        /// <param name="wlphl_ist"></param>
        /// <returns></returns>
        public int Save(tb_sc produce, List <tb_scxq> fjxx_list, List <tlModel> tlxx_list, List <tb_scxq> ccxx_list, List <tb_wlph> wlphl_ist)
        {
            int result = 0;

            try
            {
                ProduceDetailDao detailDao        = new ProduceDetailDao(_daoManager);
                MaterialStockDao materialStockDao = new MaterialStockDao(_daoManager);
                MaterialDao      material_Dao     = new MaterialDao(_daoManager);
                WlDao            wl_Dao           = new WlDao(_daoManager);
                UseRecordDao     user_record_Dao  = new UseRecordDao(_daoManager);


                _daoManager.BeginTransaction();

                #region 保存生产信息

                if (exist(produce))
                {
                    //存在相同的单号
                    _daoManager.RollBackTransaction();
                    return(-3);
                }

                int produceKey = 0;
                //保存生产信息
                if (produce.tb_sc_ID > 0)
                {
                    produceKey = dao.Update(produce);
                }
                else
                {
                    produceKey = dao.Insert(produce);
                }

                if (produceKey < 1)
                {
                    throw new Exception("保存生产信息出错");
                }

                #endregion

                #region 保存附加信息
                detailDao.RemoveByMap("附加信息", produce.tb_sc_ID.ToString());
                foreach (tb_scxq scxq in fjxx_list)
                {
                    scxq.tb_scxq_scbs = produceKey;
                    if (detailDao.Insert(scxq) < 1)
                    {
                        throw new Exception("保存附加信息出错");
                    }
                }
                #endregion

                #region 保存投料信息
                detailDao.RemoveByMap("投料", produce.tb_sc_ID.ToString());
                foreach (tlModel tl in tlxx_list)
                {
                    tb_scxq scxq = new tb_scxq();
                    scxq.tb_scxq_xxbs  = tl.xxbs;
                    scxq.tb_scxq_text  = tl.tb_scxq_text;
                    scxq.tb_scxq_value = tl.tb_scxq_value;
                    scxq.tb_scxq_scbs  = produceKey;
                    if (detailDao.Insert(scxq) < 1)
                    {
                        throw new Exception("保存投料信息出错");
                    }
                    string strYb   = "";
                    string strCjcl = "";
                    if (scxq.lb == 1)
                    {
                        strYb   = "tb_wlphck";
                        strCjcl = "tb_wlphck_cjcl";

                        tb_wlphck ck = materialStockDao.GetObject(1);
                        if (ck != null && ck.tb_wlphck_cjcl >= 1)
                        {
                            ck.tb_wlphck_cjcl = ck.tb_wlphck_cjcl - 1;
                            if (materialStockDao.Update(ck) < 1)
                            {
                                throw new Exception("保存投料信息出错");
                            }
                        }
                        else
                        {
                            //库存不足
                            _daoManager.RollBackTransaction();
                            return(-5);
                        }
                    }
                    else
                    {
                        strYb   = "tb_i259b";
                        strCjcl = "tb_i259b_p518h";

                        tb_i259b wl = wl_Dao.GetObject(1);
                        if (wl != null && wl.tb_i259b_p518h >= 1)
                        {
                            wl.tb_i259b_p518h = wl.tb_i259b_p518h - 1;
                            if (wl_Dao.Update(wl) < 1)
                            {
                                throw new Exception("保存投料信息出错");
                            }
                        }
                        else
                        {
                            //库存不足
                            _daoManager.RollBackTransaction();
                            return(-5);
                        }
                    }
                    tb_syjl syjl = new tb_syjl();
                    syjl.tb_syjl_wpbs = tl.tb_wp_ID;
                    syjl.tb_syjl_wpdm = tl.tb_wp_dm;
                    syjl.tb_syjl_xz   = 0;
                    syjl.tb_syjl_yb   = strYb;
                    syjl.tb_syjl_wlph = tl.tb_syjl_wlph;
                    syjl.tb_syjl_zl   = tl.tb_syjl_zl;
                    syjl.tb_syjl_cjcl = tl.tb_syjl_cjcl;
                    syjl.tb_syjl_ybs  = tl.tb_syjl_ybs;
                    syjl.tb_syjl_czlx = "生产";
                    syjl.tb_syjl_mbb  = "tb_wlph";
                    syjl.tb_syjl_czbs = "";

                    if (user_record_Dao.Insert(syjl) < 1)
                    {
                        throw new Exception("保存原料使用记录报错");
                    }
                }
                #endregion

                #region 保存产出信息
                detailDao.RemoveByMap("产出", produce.tb_sc_ID.ToString());
                foreach (tb_scxq scxq in ccxx_list)
                {
                    scxq.tb_scxq_scbs = produceKey;
                    if (detailDao.Insert(scxq) < 1)
                    {
                        throw new Exception("保存产出信息出错");
                    }
                }
                #endregion

                #region 保存物料批号
                foreach (tb_wlph wlph in wlphl_ist)
                {
                    int wlphKey = material_Dao.Insert(wlph);
                    if (wlphKey < 1)
                    {
                        throw new Exception("保存物料批号报错");
                    }

                    wlph.wlphck.tb_wlphck_wlbs = wlphKey;
                    int wlphckKey = materialStockDao.Insert(wlph.wlphck);
                    if (wlphckKey < 1)
                    {
                        throw new Exception("保存物料批号库存报错");
                    }

                    tb_syjl syjl = new tb_syjl();
                    syjl.tb_syjl_wpbs = wlph.tb_wlph_wpbs;
                    syjl.tb_syjl_wpdm = wlph.tb_wlph_wpdm;
                    syjl.tb_syjl_xz   = 1;
                    syjl.tb_syjl_yb   = "tb_wlph";
                    syjl.tb_syjl_ybs  = wlphKey;
                    syjl.tb_syjl_wlph = wlph.tb_wlph_wlph;
                    syjl.tb_syjl_zl   = wlph.tb_wlph_sl;
                    syjl.tb_syjl_cjcl = wlph.tb_wlph_sl;
                    syjl.tb_syjl_czlx = "生产";
                    syjl.tb_syjl_mbb  = "tb_wlphck";
                    syjl.tb_syjl_czbs = wlphckKey.ToString();
                    if (user_record_Dao.Insert(syjl) < 1)
                    {
                        throw new Exception("保存使用记录报错");
                    }
                }

                #endregion

                _daoManager.CommitTransaction();
                result = 1;
            }
            catch
            {
                result = -1;
                _daoManager.RollBackTransaction();
            }

            return(result);
        }
Esempio n. 22
0
        public ActionResult Edit(int id, UkolVzorkovani collection, bool poslatMailResiteli, bool poslatMailZadavateli, string produktyInput)
        {
            var history = TempData["UkolVzorkovaniHistory"] as UkolVzorkovani;

            if (history == null)
            {
                return(RedirectToAction("Index"));
            }

            try
            {
                //POKUD VŠE SEDÍ
                if (ModelState.IsValid)
                {
                    if (produktyInput != history.MaterialyInput)
                    {
                        var ukolMaterialDao = new UkolVzorkovaniMaterialDao();
                        foreach (var item in history.MaterialyInput.Split(';').Where(item => !produktyInput.Contains(";" + item + ";")).Where(item => item != ""))
                        { // Odebrání přebytečných
                            ukolMaterialDao.Delete(history.Materialy.First(x => x.Produkt.Id == Convert.ToInt32(item)));
                        }
                        try
                        {//Přidání nových
                            foreach (var ukolProdukt in produktyInput.Split(';').Where(item => item != "").Select(item => new UkolVzorkovaniMaterial()
                            {
                                Ukol = new UkolVzorkovani()
                                {
                                    Id = collection.Id
                                },
                                Produkt = new MaterialDao().GetById(Convert.ToInt32(item)),
                                DateAdded = DateTime.Now
                            }).Where(lopProdukt => !history.MaterialyInput.Contains(lopProdukt.Produkt.Id.ToString())))
                            {
                                ukolMaterialDao.Create(ukolProdukt);
                            }
                        }
                        catch
                        {
                            TempData[MessagesHelper.Danger] = "Nepodařilo se připojení produktů k úkolu vzorkovaní";
                        }
                    }
                    //TEST SHODNOTI
                    if (collection.IsSame(history)) //vrací FALSE, pokud nastala změna
                    {
                        if (produktyInput != history.MaterialyInput)
                        {
                            TempData[MessagesHelper.Success] = "Provázané materiály byly aktualizovány";
                            return(RedirectToAction("Detail/" + collection.Id));
                        }
                        TempData[MessagesHelper.Info] = "Nebyly provedeny žádné změny";
                        return(RedirectToAction("Detail/" + collection.Id));
                    }

                    //SAVE HISTORY
                    var uvhd = new UkolVzorkovaniHistoryDao();
                    var copy = new UkolVzorkovaniHistory(history);
                    uvhd.Create(copy);


                    if (collection.DateFinish != null)
                    {
                        collection.Status = StatusUkolu.Closed; //byl zadán datum ukončení? nebo tohle přepíná zadavatel??
                    }

                    //SAVE OBJECT
                    collection.DateLastChanged = DateTime.Now;
                    var uvd = new UkolVzorkovaniDao();
                    uvd.Update(collection);

                    //NOTIFIKACE
                    string s = "Byl upraven úkol <a href='/UkolVzorkovani/Detail/" + collection.Id + "?showHistory=true#historyBtn'>" + collection.Nazev + "</a>";
                    if (poslatMailResiteli)
                    {
                        Notifikace.Create(collection.Resitel.Id, s);
                    }
                    if (poslatMailZadavateli)
                    {
                        Notifikace.Create(collection.Zadavatel.Id, s);
                    }


                    //DONE
                    TempData[MessagesHelper.Success] = "Změny byly úspěšně uloženy";
                    return(RedirectToAction("Detail/" + collection.Id));
                }
            }
            catch
            {
                TempData[MessagesHelper.Danger] = "Došlo k neočekávané chybě";
            }

            //NON VALID - RE EDIT IT
            TempData["UkolVzorkovaniHistory"] = history;
            TempData[MessagesHelper.Warning]  = "Zkontrolujte zadané údaje";

            var matDao       = new MaterialDao();
            var materialList = matDao.GetAll();

            ViewBag.materialList = materialList;
            collection.Materialy = history.Materialy;
            return(View(collection));
        }