/// <summary> /// 更新一条数据 /// </summary> public bool Update(Haikan.SchoolProjectsCore.MDB.Model.Contract model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Contract set "); strSql.Append("ProjectID=@ProjectID,"); strSql.Append("EnterpriseName=@EnterpriseName,"); strSql.Append("ContractName=@ContractName,"); strSql.Append("CInformation=@CInformation,"); strSql.Append("Note=@Note,"); strSql.Append("ConsigneeA=@ConsigneeA,"); strSql.Append("ConsigneeB=@ConsigneeB,"); strSql.Append("LastTime=@LastTime,"); strSql.Append("Money=@Money"); strSql.Append(" where CID=@CID"); SqlParameter[] parameters = { new SqlParameter("@ProjectID", SqlDbType.Int, 4), new SqlParameter("@EnterpriseName", SqlDbType.VarChar, 255), new SqlParameter("@ContractName", SqlDbType.VarChar, 255), new SqlParameter("@CInformation", SqlDbType.VarChar, 255), new SqlParameter("@Note", SqlDbType.VarChar, 255), new SqlParameter("@ConsigneeA", SqlDbType.VarChar, 255), new SqlParameter("@ConsigneeB", SqlDbType.VarChar, 255), new SqlParameter("@LastTime", SqlDbType.VarChar, 255), new SqlParameter("@Money", SqlDbType.VarChar, 255), new SqlParameter("@CID", SqlDbType.Int, 4) }; parameters[0].Value = model.ProjectID; parameters[1].Value = model.EnterpriseName; parameters[2].Value = model.ContractName; parameters[3].Value = model.CInformation; parameters[4].Value = model.Note; parameters[5].Value = model.ConsigneeA; parameters[6].Value = model.ConsigneeB; parameters[7].Value = model.LastTime; parameters[8].Value = model.Money; parameters[9].Value = model.CID; int rows = DbHelperSql.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Haikan.SchoolProjectsCore.MDB.Model.Contract DataRowToModel(DataRow row) { Haikan.SchoolProjectsCore.MDB.Model.Contract model = new Haikan.SchoolProjectsCore.MDB.Model.Contract(); if (row != null) { if (row["CID"] != null && row["CID"].ToString() != "") { model.CID = int.Parse(row["CID"].ToString()); } if (row["ProjectID"] != null && row["ProjectID"].ToString() != "") { model.ProjectID = int.Parse(row["ProjectID"].ToString()); } if (row["EnterpriseName"] != null) { model.EnterpriseName = row["EnterpriseName"].ToString(); } if (row["ContractName"] != null) { model.ContractName = row["ContractName"].ToString(); } if (row["CInformation"] != null) { model.CInformation = row["CInformation"].ToString(); } if (row["Note"] != null) { model.Note = row["Note"].ToString(); } if (row["ConsigneeA"] != null) { model.ConsigneeA = row["ConsigneeA"].ToString(); } if (row["ConsigneeB"] != null) { model.ConsigneeB = row["ConsigneeB"].ToString(); } if (row["LastTime"] != null) { model.LastTime = row["LastTime"].ToString(); } if (row["Money"] != null) { model.Money = row["Money"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Haikan.SchoolProjectsCore.MDB.Model.Contract model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Contract("); strSql.Append("ProjectID,EnterpriseName,ContractName,CInformation,Note,ConsigneeA,ConsigneeB,LastTime,Money)"); strSql.Append(" values ("); strSql.Append("@ProjectID,@EnterpriseName,@ContractName,@CInformation,@Note,@ConsigneeA,@ConsigneeB,@LastTime,@Money)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ProjectID", SqlDbType.Int, 4), new SqlParameter("@EnterpriseName", SqlDbType.VarChar, 255), new SqlParameter("@ContractName", SqlDbType.VarChar, 255), new SqlParameter("@CInformation", SqlDbType.VarChar, 255), new SqlParameter("@Note", SqlDbType.VarChar, 255), new SqlParameter("@ConsigneeA", SqlDbType.VarChar, 255), new SqlParameter("@ConsigneeB", SqlDbType.VarChar, 255), new SqlParameter("@LastTime", SqlDbType.VarChar, 255), new SqlParameter("@Money", SqlDbType.VarChar, 255) }; parameters[0].Value = model.ProjectID; parameters[1].Value = model.EnterpriseName; parameters[2].Value = model.ContractName; parameters[3].Value = model.CInformation; parameters[4].Value = model.Note; parameters[5].Value = model.ConsigneeA; parameters[6].Value = model.ConsigneeB; parameters[7].Value = model.LastTime; parameters[8].Value = model.Money; object obj = DbHelperSql.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Haikan.SchoolProjectsCore.MDB.Model.Contract GetModel(int CID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CID,ProjectID,EnterpriseName,ContractName,CInformation,Note,ConsigneeA,ConsigneeB,LastTime,Money from Contract "); strSql.Append(" where CID=@CID"); SqlParameter[] parameters = { new SqlParameter("@CID", SqlDbType.Int, 4) }; parameters[0].Value = CID; Haikan.SchoolProjectsCore.MDB.Model.Contract model = new Haikan.SchoolProjectsCore.MDB.Model.Contract(); DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }