/// <summary> /// 得到一个对象实体 /// </summary> public MesWeb.Model.T_Axis DataRowToModel(DataRow row) { MesWeb.Model.T_Axis model = new MesWeb.Model.T_Axis(); if (row != null) { if (row["AxisID"] != null && row["AxisID"].ToString() != "") { model.AxisID = int.Parse(row["AxisID"].ToString()); } if (row["CodeNumber"] != null) { model.CodeNumber = row["CodeNumber"].ToString(); } if (row["Axis_No"] != null) { model.Axis_No = row["Axis_No"].ToString(); } if (row["DateTime"] != null && row["DateTime"].ToString() != "") { model.DateTime = DateTime.Parse(row["DateTime"].ToString()); } if (row["comment"] != null) { model.comment = row["comment"].ToString(); } if (row["Operator"] != null) { model.Operator = row["Operator"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(MesWeb.Model.T_Axis model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Axis("); strSql.Append("CodeNumber,Axis_No,DateTime,comment,Operator)"); strSql.Append(" values ("); strSql.Append("@CodeNumber,@Axis_No,@DateTime,@comment,@Operator)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CodeNumber", SqlDbType.NVarChar, 50), new SqlParameter("@Axis_No", SqlDbType.NVarChar, 50), new SqlParameter("@DateTime", SqlDbType.DateTime), new SqlParameter("@comment", SqlDbType.NVarChar, 50), new SqlParameter("@Operator", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.CodeNumber; parameters[1].Value = model.Axis_No; parameters[2].Value = model.DateTime; parameters[3].Value = model.comment; parameters[4].Value = model.Operator; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(MesWeb.Model.T_Axis model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Axis set "); strSql.Append("CodeNumber=@CodeNumber,"); strSql.Append("Axis_No=@Axis_No,"); strSql.Append("DateTime=@DateTime,"); strSql.Append("comment=@comment,"); strSql.Append("Operator=@Operator"); strSql.Append(" where AxisID=@AxisID"); SqlParameter[] parameters = { new SqlParameter("@CodeNumber", SqlDbType.NVarChar, 50), new SqlParameter("@Axis_No", SqlDbType.NVarChar, 50), new SqlParameter("@DateTime", SqlDbType.DateTime), new SqlParameter("@comment", SqlDbType.NVarChar, 50), new SqlParameter("@Operator", SqlDbType.NVarChar, 50), new SqlParameter("@AxisID", SqlDbType.Int, 4) }; parameters[0].Value = model.CodeNumber; parameters[1].Value = model.Axis_No; parameters[2].Value = model.DateTime; parameters[3].Value = model.comment; parameters[4].Value = model.Operator; parameters[5].Value = model.AxisID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MesWeb.Model.T_Axis GetModel(int AxisID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 AxisID,CodeNumber,Axis_No,DateTime,comment,Operator from T_Axis "); strSql.Append(" where AxisID=@AxisID"); SqlParameter[] parameters = { new SqlParameter("@AxisID", SqlDbType.Int, 4) }; parameters[0].Value = AxisID; MesWeb.Model.T_Axis model = new MesWeb.Model.T_Axis(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }