Example #1
0
        public ActionResult ExcluirIngredienteLocal(string id_ing = "0")
        {
            try
            {
                long ing_id = 0;
                if (id_ing.Trim() != "")
                {
                    ing_id = Convert.ToInt64(id_ing);
                }
                if (ing_id != 0)
                {
                    local_ingred_tables local_ingred_tables = new local_ingred_tables();
                    exist_ingredients   exist_ingredients   = new exist_ingredients();
                    Local_Ingred_User   Local_Ingred_User   = new Local_Ingred_User();

                    local_ingred_tables.GetConnection().CriaTransaction();
                    exist_ingredients.SetConnection(local_ingred_tables.GetConnection());
                    Local_Ingred_User.SetConnection(local_ingred_tables.GetConnection());

                    Local_Ingred_User.Excluir(ing_id);
                    local_ingred_tables.ExcluirPorIngrediente(ing_id);
                    exist_ingredients.Excluir(ing_id);
                    // excluir do vinculo de tabelas

                    local_ingred_tables.GetConnection().TransCommit();
                }
                return(Json(new { status = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { status = "error" }));
            }
        }
Example #2
0
        public ActionResult SalvaIngredienteLocal(string name_ingrediente, long ingred_id, string model)
        {
            try
            {
                // incluir no cadastro de ingrediente
                // salvar valores para todas as tabelas

                string[] arrValues = new string[0];
                arrValues = model.Split(',');


                var usuario = getUser().user_id;
                var lang    = GetLangId(this, Session["lang_code"].ToString());

                exist_base_tables   exist_base_tables   = new exist_base_tables();
                exist_ingredients   exist_ingredients   = new exist_ingredients();
                local_ingred_tables local_ingred_tables = new local_ingred_tables();
                Local_Ingred_User   Local_Ingred_User   = new Local_Ingred_User();
                var tabelas = exist_base_tables.Consultar(usuario, lang);

                exist_ingredients.GetConnection().CriaTransaction();

                local_ingred_tables.SetConnection(exist_ingredients.GetConnection());
                Local_Ingred_User.SetConnection(exist_ingredients.GetConnection());

                var       retorno     = exist_ingredients.Incluir(name_ingrediente);
                long      ingrediente = Convert.ToInt64(retorno);
                DataTable dt_nutrs    = (DataTable)TempData["dt_nutrients"];
                TempData.Keep("dt_nutrients");

                Local_Ingred_AlterUserDto local_ingred = new Local_Ingred_AlterUserDto();
                local_ingred.user_id   = usuario;
                local_ingred.ingred_id = ingrediente;

                Local_Ingred_User.Incluir(ingrediente, usuario);

                foreach (Exist_Base_TablesDto tabela in tabelas)
                {
                    local_ingred.table_id = tabela.table_id;

                    var index = -1;
                    for (int i = 0; i < arrValues.Length - 1; i++)
                    {
                        var nutr_id = Convert.ToInt64(dt_nutrs.Rows[i]["nutr_id"]);
                        local_ingred.nutr_id    = nutr_id;
                        local_ingred.nutr_value = Convert.ToDecimal(arrValues[i]);
                        local_ingred_tables.Inserir(local_ingred);
                    }
                }
                exist_ingredients.GetConnection().TransCommit();
                return(Json(new { status = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { status = "error" }));
            }
        }
Example #3
0
        public DataTable DefaultTableau(long sp_id, long frm_id = 0)
        {
            // cria tabela com tableau para receber ingredientes usados por ração, da espécie

            DataTable dtTableau = new DataTable();
            long      r;
            var       retorno = false;

            try
            {
                var usuario = getUser();
                //
                growth_phasis        growth_phasis        = new growth_phasis();
                formulas_composition formulas_composition = new formulas_composition();
                Local_Ingred_User    util = new Local_Ingred_User();

                DataTable dt_phases = new DataTable();

                if (frm_id == 0)
                {
                    dt_phases = growth_phasis.GetPhasesPorEspecieEUsuario(sp_id, usuario.user_id);
                    if (dt_phases.Rows.Count < 1)
                    {
                        growth_phasis.InsertDefaultGP(usuario.user_id);
                        dt_phases = growth_phasis.GetPhasesPorEspecieEUsuario(sp_id, usuario.user_id);
                    }
                }
                else
                {
                    dt_phases = formulas_composition.GetPhasesPorFormula(frm_id, sp_id, usuario.user_id);
                    if (dt_phases.Rows.Count < 1)
                    {
                        growth_phasis.InsertDefaultGP(usuario.user_id);
                        dt_phases = growth_phasis.GetPhasesPorEspecieEUsuario(sp_id, usuario.user_id);
                    }
                }

                try
                {
                    dtTableau.Columns.Add("ingred_id", typeof(string));         // col 0
                    dtTableau.Columns.Add("line_type", typeof(string));         // col 1
                    dtTableau.Columns.Add("Ration definition", typeof(string)); // col 2
                    dtTableau.Columns.Add("price", typeof(string));

                    foreach (DataRow item in dt_phases.Rows)
                    {
                        dtTableau.Columns.Add(item["phasis_mmc"].ToString(), typeof(float));
                    }

                    dtTableau.Rows.Add("", "", "");
                    // replace na unidade usada
                    var unidd = "kg";
                    if (usuario.system_id == 2)
                    {
                        unidd = "ld";
                    }
                    dtTableau.Rows.Add("19", "C", GeralResource.RecRes(12).Replace("{md}", unidd)); // title 'feed budget' 1 line type 'C'
                    dtTableau.Rows.Add("", "T", GeralResource.RecRes(11));                          // title 'ingred inclusion' line type 2

                    //
                    exist_ingredients exist_ingredients = new exist_ingredients();
                    var col_ingredientes = exist_ingredients.ConsultaringredientesParaFeedProgram(0);
                    var filter_ingreds   = col_ingredientes.Where(f => f.ingred_line != "C").OrderBy(f => f.ingred_order).ToList();

                    // tab exist_ingredientes: line_type 'I' ingrediente; 'O' outros; 'C' consumo
                    // seleciona só os 'I'ngredientes

                    // ingreds, inicia na linha 2

                    // adiciona linhas com ingredientes

                    foreach (var item in filter_ingreds)
                    {
                        var resource = 0;
                        if (item.resource_id != null)
                        {
                            resource = item.resource_id.Value;
                        }
                        string name_ingrediente = "";
                        if (resource == 0)
                        {
                            name_ingrediente = item.ingred_mmc;
                        }
                        else
                        {
                            name_ingrediente = GeralResource.RecRes(resource);
                        }
                        if (resource != 115) // foi tirado o Oil/fat por enquanto
                        {
                            dtTableau.Rows.Add(item.ingred_id, item.ingred_line, name_ingrediente);
                        }
                    }
                    foreach (DataRow it_rw in dtTableau.Rows)
                    {
                        for (int _col = 3; _col < dtTableau.Columns.Count; _col++)
                        {
                            var ingred_qtty = it_rw[_col];
                            if (it_rw["line_type"].ToString() == "C" && ingred_qtty == DBNull.Value)
                            { // caso formula nova default 1 para peso
                                it_rw[_col] = 1;
                            }
                        }
                    }
                    try
                    {
                        //dtTableau.Rows.Add("16", "O", GeralResource.RecRes(115));
                        dtTableau.Rows.Add("17", "O", GeralResource.RecRes(116));
                        Session["dt"] = dtTableau;
                        dtTableau.Dispose();
                    }
                    catch (Exception ex)
                    {
                        opInt.WRITE_ERR_LOG(ex.Message + "_DefaultTableau3");
                        throw ex;
                    }
                    long ing_id = 0;
                    dtTableau.AcceptChanges();
                    foreach (DataRow row in dtTableau.Rows)
                    {
                        var local = row["line_type"].ToString();

                        bool flag = true;

                        if (local == "L")
                        {
                            ing_id = Convert.ToInt64(row["ingred_id"]);
                            flag   = util.VerificarIngUser(usuario.user_id, ing_id);

                            if (!flag)
                            {
                                row.Delete();
                            }
                        }
                    }
                    dtTableau.AcceptChanges();

                    return(dtTableau);
                }
                catch (Exception ex)
                {
                    opInt.WRITE_ERR_LOG(ex.Message + "_DefaultTableau");
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                dtTableau.Dispose();
                opInt.WRITE_ERR_LOG(ex.Message + "_DefaultTableau1");
                throw ex;
            }
        }