public static bool Save(G_DATA entity) { using (MainDataContext dbContext = new MainDataContext()) { if (entity.ID == 0) { var list = from p in dbContext.G_DATA select p.ID; long total = list.LongCount(); if (total == 0) { entity.ID = 1; } else { entity.ID = dbContext.G_DATA.Max(t => t.ID) + 1; } dbContext.G_DATA.InsertOnSubmit(entity); dbContext.SubmitChanges(); return(true); } else { var model = dbContext.G_DATA.FirstOrDefault(t => t.ID == entity.ID); model.ID = entity.ID; model.Name = entity.Name; model.Remark = entity.Remark; model.Sequence = entity.Sequence; model.Type = entity.Type; model.Value = entity.Value; dbContext.SubmitChanges(); return(true); } } }
public static object Edit(int?id) { using (MainDataContext dbContext = new MainDataContext()) { G_DATA entity = null; if (id != null) { entity = dbContext.G_DATA.FirstOrDefault(g => g.ID == id); } entity = entity ?? new G_DATA { ID = 0, Name = string.Empty, Type = string.Empty, Value = string.Empty, Sequence = 0, Remark = string.Empty, }; return(entity); } }
/* * LLENAR GRIDCONTROL */ public void LlenarTabla() { //using (SqlConnection conexion=new SqlConnection(ConfigurationManager.ConnectionStrings["SILVER_INVENTORY.Properties.Settings.SILV_INVENTORYConnectionString"].ConnectionString.ToString())) try { mt.ConectarBaseDatos(); mt.comando = new SqlCommand("SP_SILV_USUARIOS_VIEW", mt.conexion); mt.comando.CommandType = CommandType.StoredProcedure; /*parametros*/ mt.mensaje = new SqlParameter("@MENSAJE", SqlDbType.NVarChar, 200); mt.mensaje.Direction = ParameterDirection.Output; mt.comando.Parameters.Add(mt.mensaje); int filas = mt.comando.ExecuteNonQuery(); if (filas > 0) { LBL_RESULT.Visibility = BarItemVisibility.Always; LBL_RESULT.Caption = Convert.ToString(mt.mensaje); } else { LBL_RESULT.Visibility = BarItemVisibility.Always; LBL_RESULT.Caption = Convert.ToString(mt.mensaje); } mt.adaptador = new SqlDataAdapter(mt.comando); mt.datatables = new DataTable(); mt.adaptador.Fill(mt.datatables); DGV_DATA.DataSource = mt.datatables; G_DATA.BestFitColumns(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { mt.DesconectarBaseDatos(); } }
public bool Save(G_DATA entity) { return(DAL.BasicInfo.CommonData.Save(entity)); }