/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.LabInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_LabInfo set "); strSql.Append("Lab_ID=@Lab_ID,"); strSql.Append("Name=@Name,"); strSql.Append("Value=@Value"); strSql.Append(" where ID_Key=@ID_Key"); SqlParameter[] parameters = { new SqlParameter("@Lab_ID", SqlDbType.VarChar, 50), new SqlParameter("@Name", SqlDbType.VarChar, 100), new SqlParameter("@Value", SqlDbType.VarChar, 255), new SqlParameter("@ID_Key", SqlDbType.Decimal, 9) }; parameters[0].Value = model.Lab_ID; parameters[1].Value = model.Name; parameters[2].Value = model.Value; parameters[3].Value = model.ID_Key; int rows = dbs.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public decimal Add(Maticsoft.Model.LabInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_LabInfo("); strSql.Append("Lab_ID,Name,Value)"); strSql.Append(" values ("); strSql.Append("@Lab_ID,@Name,@Value)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Lab_ID", SqlDbType.VarChar, 50), new SqlParameter("@Name", SqlDbType.VarChar, 100), new SqlParameter("@Value", SqlDbType.VarChar, 255) }; parameters[0].Value = model.Lab_ID; parameters[1].Value = model.Name; parameters[2].Value = model.Value; object obj = dbs.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToDecimal(obj)); } }
// //提交单元格 的更改到类 // private void dgv_TemplateInfo_CellEditEnding(object sender, System.Windows.Controls.DataGridCellEditEndingEventArgs e) { if (e.EditAction == System.Windows.Controls.DataGridEditAction.Commit) { int i = e.Row.GetIndex(); //Get Rows Index 获取行号索引 Maticsoft.Model.LabInfo li = (Maticsoft.Model.LabInfo)e.Row.Item; // Convert to LabInfo 转换为LabInfo类型 _WTT_LabInfo[i] = li; // Assignment _WTT 修改全局变量 My_MessageBox.My_MessageBox_Message(li.ToString()); //MessageShow 显示信息 } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.LabInfo DataRowToModel(DataRow row) { Maticsoft.Model.LabInfo model = new Maticsoft.Model.LabInfo(); if (row != null) { if (row["Lab_ID"] != null) { model.Lab_ID = row["Lab_ID"].ToString(); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Value"] != null) { model.Value = row["Value"].ToString(); } if (row["ID_Key"] != null && row["ID_Key"].ToString() != "") { model.ID_Key = decimal.Parse(row["ID_Key"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.LabInfo GetModel(decimal ID_Key) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Lab_ID,Name,Value,ID_Key from tb_LabInfo "); strSql.Append(" where ID_Key=@ID_Key"); SqlParameter[] parameters = { new SqlParameter("@ID_Key", SqlDbType.Decimal) }; parameters[0].Value = ID_Key; Maticsoft.Model.LabInfo model = new Maticsoft.Model.LabInfo(); DataSet ds = dbs.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }