public DataTable UpdateDefaultTableau(ref DataTable dt, long formula_id) { try { formulas_composition formulas_composition = new formulas_composition(); try { var col_composition = formulas_composition.consultarPorFormula(formula_id); var col_composition_order = col_composition.OrderBy(f => f.ingred_id.ingred_id).OrderBy(f => f.phasis_id.phasis_id).ToList(); foreach (var item in col_composition_order) { foreach (DataRow row in dt.Rows) { if (row["ingred_id"] != DBNull.Value) { if (row["ingred_id"].ToString() != "") { var ingred = item.ingred_id.ingred_id; if (Convert.ToInt32(row["ingred_id"]) == ingred) { int iphasis = item.phasis_id.phasis_id; row[iphasis + 3] = item.ingred_qtty; row[3] = item.price; break; } } } } } } catch (Exception ex) { opInt.WRITE_ERR_LOG(ex.Message + "_UpdateDefaultTableau1"); throw ex; } Session["dt"] = dt; return(dt); } catch (Exception ex) { opInt.WRITE_ERR_LOG(ex.Message + "_UpdateDefaultTableau2"); throw ex; } }
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; } }