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 ActionResult Formulation() { try { // var usuario = getUser(); //var user_id = usuario.user_id; //var lang_id = usuario.lang_id; //var table_id = usuario.table_id; //var langcode = usuario.lang_id.lang_mmc; //var langcode = GetLangCode(this); ViewBag.langcode = Session["lang_code"]; Exist_UsersDto usuario = (Exist_UsersDto)Session["usuario"]; exist_base_tables basetb = new exist_base_tables(); List <Exist_Base_TablesDto> tabelas = basetb.Consultar(usuario.user_id, usuario.lang_id.lang_id); ViewBag.tabelas = tabelas; var tabela = tabelas.Where(f => f.table_id == usuario.table_id).ToList()[0]; ViewBag.tabela_ativa_id = usuario.table_id; ViewBag.tabela_ativa_nome = tabela.table_description; Measure_Systems MeasSystem = new Measure_Systems(); Measure_SystemsDtoCollection measure_systems = MeasSystem.Consultar(); ViewBag.units = measure_systems; List <SelectListItem> BaseCalcs = new List <SelectListItem>(); BaseCalcs.Add(new SelectListItem() { Text = GeralResource.RecRes(242), Value = "0" }); BaseCalcs.Add(new SelectListItem() { Text = GeralResource.RecRes(243), Value = "1" }); ViewBag.BaseCalcs = BaseCalcs; List <SelectListItem> EnUnits = new List <SelectListItem>(); EnUnits.Add(new SelectListItem() { Text = GeralResource.RecRes(1112), Value = "1" }); EnUnits.Add(new SelectListItem() { Text = GeralResource.RecRes(1113), Value = "2" }); ViewBag.EnUnits = EnUnits; ViewBag.Dose = usuario.dose; GetConfigEnergia(usuario); paises(); tratamentos(); ViewBag.usuario = usuario; ViewBag.specie = usuario.specie_id; GetSelectionSubProducts(); } catch (Exception ex) { ViewBag.ErrorPage = ex.Message; } return(View()); }
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>")); } }