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" })); } }
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" })); } }
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; } }
public ActionResult LoadGridFeedIngreds(string mode) { ingred_matrix ingred_matrix = new ingred_matrix(); exist_base_tables exist_base_tables = new exist_base_tables(); try { var provider = GetCurrentProvider(this); ViewBag.provider = provider; //DataTable dtMtx = MountForVisualizationGrid(provider); var usuario = (Exist_UsersDto)Session["usuario"]; DataTable dt = new DataTable(); DataTable dtTables = new DataTable(); DataTable dtMatrix = new DataTable(); exist_nutrients nutridb = new exist_nutrients(); Local_Ingred_User util = new Local_Ingred_User(); DataTable dtMatrix_Data = ingred_matrix.GetMatrixDadosBase(usuario); DataTable dt_linhas = ingred_matrix.ConsultarIngredientesBaseELocal(usuario.user_id, usuario.lang_id.lang_id); DataTable dtNutrientes = dtMatrix_Data.DefaultView.ToTable(true, "nutr_id", "nutr_name", "unit"); /*dt_linhas.AcceptChanges(); * foreach (DataRow row in dt_linhas.Rows) * { * var local = Convert.ToInt32(row["local"]); * long ing_id = Convert.ToInt64(row["ingred_id"]); * bool flag = true; * * if (local == 1) * { * * flag = util.VerificarIngUser(usuario.user_id, ing_id); * * if (!flag) * { * * row.Delete(); * } * } * } * dt_linhas.AcceptChanges(); */ var tabelas = exist_base_tables.Consultar(); // criar o for impedidor TempData["dt_nutrients"] = dt; if (dtNutrientes != null) { dtMatrix.Columns.Add("ingred_id", typeof(String)); dtMatrix.Columns.Add("table_id", typeof(String)); dtMatrix.Columns.Add("ingred", typeof(String)); dtMatrix.Columns.Add("local", typeof(String)); foreach (DataRow row in dtNutrientes.Rows) { DataColumn dc = new DataColumn(); dc.ColumnName = row["nutr_name"].ToString().Trim() + " " + row["unit"].ToString().Trim(); dc.DataType = typeof(String); dtMatrix.Columns.Add(dc); } dt.Dispose(); } DataTable dtMatrix_Data_Local = ingred_matrix.GetMatrixDadosLocal(usuario.user_id); DataTable dtMatrix_Other = ingred_matrix.GetMatrixDataOutros(usuario); if (dt_linhas != null) { foreach (DataRow row in dt_linhas.Rows) { var i_id = row[0]; DataRow trow_ingred = null; trow_ingred = dtMatrix.NewRow(); trow_ingred["ingred_id"] = row[0].ToString(); trow_ingred["table_id"] = "0"; trow_ingred["ingred"] = row[1].ToString(); string local = row["local"].ToString(); trow_ingred["local"] = local; if (local == "0") { dtMatrix.Rows.Add(trow_ingred); } try { foreach (Exist_Base_TablesDto tb in tabelas) { DataRow trow_values_pdr = null; trow_values_pdr = dtMatrix.NewRow(); DataRow trow_values_alt = null; trow_values_alt = dtMatrix.NewRow(); long tabela_id = Convert.ToInt64(tb.table_id); trow_values_pdr["ingred_id"] = row[0].ToString(); trow_values_pdr["table_id"] = tabela_id.ToString(); trow_values_alt["table_id"] = "0"; trow_values_pdr["ingred"] = tb.table_description; trow_values_pdr["local"] = row["local"].ToString(); DataView DVFilter = null; DataView DvFilterNutr = new DataView(dtNutrientes); if (local == "1") // ingrediente local { DVFilter = new DataView(dtMatrix_Data_Local); if (dtMatrix_Data_Local.Rows.Count > 0) { DVFilter.RowFilter = "ingred_id=" + i_id + " and table_id=" + tabela_id + ""; } else { DVFilter.RowFilter = "ingred_id=0"; } } else { DVFilter = new DataView(dtMatrix_Other); DVFilter.RowFilter = "ingred_id=" + i_id + " and table_id=" + tabela_id; } var alt_nutr = false; if (DVFilter != null) { foreach (DataRow item in DVFilter.ToTable().Rows) { DvFilterNutr.RowFilter = "nutr_id=" + item["nutr_id"]; DataView filt_Nut = new DataView(DVFilter.ToTable()); filt_Nut.RowFilter = "nutr_id=" + item["nutr_id"]; var nut = DvFilterNutr.ToTable().Rows[0]["nutr_name"].ToString().Trim() + " " + DvFilterNutr.ToTable().Rows[0]["unit"].ToString().Trim(); decimal val = Convert.ToDecimal(filt_Nut.ToTable().Rows[0]["nutr_value"]); if (local == "1") { trow_ingred[nut] = val.ToString("N3", provider); } else { trow_values_pdr[nut] = val.ToString("N3", provider); } if (filt_Nut.ToTable().Rows[0]["value_local"] != DBNull.Value) { val = Convert.ToDecimal(filt_Nut.ToTable().Rows[0]["value_local"]); trow_values_alt[nut] = val.ToString("N3", provider); trow_values_alt["local"] = "0"; alt_nutr = true; } } if (local == "1") { dtMatrix.Rows.Add(trow_ingred); break; } else { dtMatrix.Rows.Add(trow_values_pdr); } if (alt_nutr) { dtMatrix.Rows.Add(trow_values_alt); } } } } catch (Exception ex) { Log.LogError.WriteLog(ex.Message, "_MountForVisualizationGrid"); throw ex; } } } GetColluns(dtMatrix); var Model = GetModelTable(dtMatrix); ViewBag.mode = mode; return(PartialView(Model)); } catch (Exception ex) { Log.LogError.WriteLog(ex.Message, "_"); return(Content("<label> Error: Please contact admin! </label>")); } }