/// <summary> /// 得到一个对象实体 /// </summary> public static Model.ContractInfo DataRowToModel(DataRow row) { Model.ContractInfo model = new Model.ContractInfo(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["contractNumber"] != null) { model.contractNumber = row["contractNumber"].ToString(); } if (row["userId"] != null && row["userId"].ToString() != "") { model.userId = int.Parse(row["userId"].ToString()); } if (row["contractType"] != null && row["contractType"].ToString() != "") { model.contractType = int.Parse(row["contractType"].ToString()); } if (row["typeId"] != null && row["typeId"].ToString() != "") { model.typeId = int.Parse(row["typeId"].ToString()); } if (row["timeFrom"] != null && row["timeFrom"].ToString() != "") { model.timeFrom = DateTime.Parse(row["timeFrom"].ToString()); } if (row["timeEnd"] != null && row["timeEnd"].ToString() != "") { model.timeEnd = DateTime.Parse(row["timeEnd"].ToString()); } if (row["storeMoney"] != null && row["storeMoney"].ToString() != "") { model.storeMoney = double.Parse(row["storeMoney"].ToString()); } if (row["status"] != null && row["status"].ToString() != "") { model.status = int.Parse(row["status"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["addTime"] != null && row["addTime"].ToString() != "") { model.addTime = DateTime.Parse(row["addTime"].ToString()); } if (row["otherTime"] != null && row["otherTime"].ToString() != "") { model.otherTime = DateTime.Parse(row["otherTime"].ToString()); } if (row["infoType"] != null && row["infoType"].ToString() != "") { model.infoType = int.Parse(row["infoType"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.ContractInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ContractInfo set "); strSql.Append("contractNumber=@contractNumber,"); strSql.Append("userId=@userId,"); strSql.Append("contractType=@contractType,"); strSql.Append("typeId=@typeId,"); strSql.Append("timeFrom=@timeFrom,"); strSql.Append("timeEnd=@timeEnd,"); strSql.Append("storeMoney=@storeMoney,"); strSql.Append("status=@status,"); strSql.Append("remark=@remark,"); strSql.Append("addTime=@addTime,"); strSql.Append("otherTime=@otherTime,"); strSql.Append("infoType=@infoType"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@contractNumber", SqlDbType.VarChar, 50), new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@contractType", SqlDbType.Int, 4), new SqlParameter("@typeId", SqlDbType.Int, 4), new SqlParameter("@timeFrom", SqlDbType.DateTime), new SqlParameter("@timeEnd", SqlDbType.DateTime), new SqlParameter("@storeMoney", SqlDbType.Money, 8), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.VarChar, 1500), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@otherTime", SqlDbType.DateTime), new SqlParameter("@infoType", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.contractNumber; parameters[1].Value = model.userId; parameters[2].Value = model.contractType; parameters[3].Value = model.typeId; parameters[4].Value = model.timeFrom; parameters[5].Value = model.timeEnd; parameters[6].Value = model.storeMoney; parameters[7].Value = model.status; parameters[8].Value = model.remark; parameters[9].Value = model.addTime; parameters[10].Value = model.otherTime; parameters[11].Value = model.infoType; parameters[12].Value = model.id; int rows = DBHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public static int Add(Model.ContractInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ContractInfo("); strSql.Append("contractNumber,userId,contractType,typeId,timeFrom,timeEnd,storeMoney,status,remark,addTime,otherTime,infoType)"); strSql.Append(" values ("); strSql.Append("@contractNumber,@userId,@contractType,@typeId,@timeFrom,@timeEnd,@storeMoney,@status,@remark,@addTime,@otherTime,@infoType)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@contractNumber", SqlDbType.VarChar, 50), new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@contractType", SqlDbType.Int, 4), new SqlParameter("@typeId", SqlDbType.Int, 4), new SqlParameter("@timeFrom", SqlDbType.DateTime), new SqlParameter("@timeEnd", SqlDbType.DateTime), new SqlParameter("@storeMoney", SqlDbType.Money, 8), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.VarChar, 1500), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@otherTime", SqlDbType.DateTime), new SqlParameter("@infoType", SqlDbType.Int, 4) }; parameters[0].Value = model.contractNumber; parameters[1].Value = model.userId; parameters[2].Value = model.contractType; parameters[3].Value = model.typeId; parameters[4].Value = model.timeFrom; parameters[5].Value = model.timeEnd; parameters[6].Value = model.storeMoney; parameters[7].Value = model.status; parameters[8].Value = model.remark; parameters[9].Value = model.addTime; parameters[10].Value = model.otherTime; parameters[11].Value = model.infoType; object obj = DBHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public static Model.ContractInfo GetModel(int id, int type) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,contractNumber,userId,contractType,typeId,timeFrom,timeEnd,storeMoney,status,remark,addTime,otherTime,infoType from ContractInfo "); strSql.Append(" where userId=@userId and typeId = " + type + " order by id desc"); SqlParameter[] parameters = { new SqlParameter("@userId", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.ContractInfo model = new Model.ContractInfo(); DataSet ds = DBHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.ContractInfo GetModel(decimal C_ID) { var strSql = new StringBuilder(); strSql.Append("select top 1 C_ID,C_PID,C_Name,C_Fco,C_Sco,C_Date,C_FHeader,C_SHeader,C_Price,C_BillAmount,C_UnBillAmount,C_PayAmount,C_UnpayAmount,C_SDate,C_EDate,C_Condition,C_Type,C_Time,C_State,C_File,C_Remark,C_Inputer,C_InputDate,C_Editer,C_Editdate from tbl_ContractInfo "); strSql.Append(" where C_ID=@C_ID "); SqlParameter[] parameters = { new SqlParameter("@C_ID", SqlDbType.Decimal,9) }; parameters[0].Value = C_ID; var model = new Model.ContractInfo(); DataSet ds = SqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["C_ID"] != null && ds.Tables[0].Rows[0]["C_ID"].ToString() != "") { model.C_ID = decimal.Parse(ds.Tables[0].Rows[0]["C_ID"].ToString()); } if (ds.Tables[0].Rows[0]["C_PID"] != null && ds.Tables[0].Rows[0]["C_PID"].ToString() != "") { model.C_PID = decimal.Parse(ds.Tables[0].Rows[0]["C_PID"].ToString()); } if (ds.Tables[0].Rows[0]["C_Name"] != null && ds.Tables[0].Rows[0]["C_Name"].ToString() != "") { model.C_Name = ds.Tables[0].Rows[0]["C_Name"].ToString(); } if (ds.Tables[0].Rows[0]["C_Fco"] != null && ds.Tables[0].Rows[0]["C_Fco"].ToString() != "") { model.C_Fco = ds.Tables[0].Rows[0]["C_Fco"].ToString(); } if (ds.Tables[0].Rows[0]["C_Sco"] != null && ds.Tables[0].Rows[0]["C_Sco"].ToString() != "") { model.C_Sco = ds.Tables[0].Rows[0]["C_Sco"].ToString(); } if (ds.Tables[0].Rows[0]["C_Date"] != null && ds.Tables[0].Rows[0]["C_Date"].ToString() != "") { model.C_Date = DateTime.Parse(ds.Tables[0].Rows[0]["C_Date"].ToString()); model.Date = DateTime.Parse(ds.Tables[0].Rows[0]["C_Date"].ToString()).ToShortDateString(); } if (ds.Tables[0].Rows[0]["C_FHeader"] != null && ds.Tables[0].Rows[0]["C_FHeader"].ToString() != "") { model.C_FHeader = ds.Tables[0].Rows[0]["C_FHeader"].ToString(); } if (ds.Tables[0].Rows[0]["C_SHeader"] != null && ds.Tables[0].Rows[0]["C_SHeader"].ToString() != "") { model.C_SHeader = ds.Tables[0].Rows[0]["C_SHeader"].ToString(); } if (ds.Tables[0].Rows[0]["C_Price"] != null && ds.Tables[0].Rows[0]["C_Price"].ToString() != "") { model.C_Price = decimal.Parse(ds.Tables[0].Rows[0]["C_Price"].ToString()); } if (ds.Tables[0].Rows[0]["C_BillAmount"] != null && ds.Tables[0].Rows[0]["C_BillAmount"].ToString() != "") { model.C_BillAmount = decimal.Parse(ds.Tables[0].Rows[0]["C_BillAmount"].ToString()); } if (ds.Tables[0].Rows[0]["C_UnBillAmount"] != null && ds.Tables[0].Rows[0]["C_UnBillAmount"].ToString() != "") { model.C_UnBillAmount = decimal.Parse(ds.Tables[0].Rows[0]["C_UnBillAmount"].ToString()); } if (ds.Tables[0].Rows[0]["C_PayAmount"] != null && ds.Tables[0].Rows[0]["C_PayAmount"].ToString() != "") { model.C_PayAmount = decimal.Parse(ds.Tables[0].Rows[0]["C_PayAmount"].ToString()); } if (ds.Tables[0].Rows[0]["C_UnpayAmount"] != null && ds.Tables[0].Rows[0]["C_UnpayAmount"].ToString() != "") { model.C_UnpayAmount = decimal.Parse(ds.Tables[0].Rows[0]["C_UnpayAmount"].ToString()); } if (ds.Tables[0].Rows[0]["C_SDate"] != null && ds.Tables[0].Rows[0]["C_SDate"].ToString() != "") { model.C_SDate = DateTime.Parse(ds.Tables[0].Rows[0]["C_SDate"].ToString()); model.SDate = DateTime.Parse(ds.Tables[0].Rows[0]["C_SDate"].ToString()).ToShortDateString(); } if (ds.Tables[0].Rows[0]["C_EDate"] != null && ds.Tables[0].Rows[0]["C_EDate"].ToString() != "") { model.C_EDate = DateTime.Parse(ds.Tables[0].Rows[0]["C_EDate"].ToString()); model.EDate = DateTime.Parse(ds.Tables[0].Rows[0]["C_EDate"].ToString()).ToShortDateString(); } if (ds.Tables[0].Rows[0]["C_Condition"] != null && ds.Tables[0].Rows[0]["C_Condition"].ToString() != "") { model.C_Condition = ds.Tables[0].Rows[0]["C_Condition"].ToString(); } if (ds.Tables[0].Rows[0]["C_Type"] != null && ds.Tables[0].Rows[0]["C_Type"].ToString() != "") { model.C_Type = int.Parse(ds.Tables[0].Rows[0]["C_Type"].ToString()); } if (ds.Tables[0].Rows[0]["C_Time"] != null && ds.Tables[0].Rows[0]["C_Time"].ToString() != "") { model.C_Time = int.Parse(ds.Tables[0].Rows[0]["C_Time"].ToString()); } if (ds.Tables[0].Rows[0]["C_State"] != null && ds.Tables[0].Rows[0]["C_State"].ToString() != "") { model.C_State = int.Parse(ds.Tables[0].Rows[0]["C_State"].ToString()); } if (ds.Tables[0].Rows[0]["C_File"] != null && ds.Tables[0].Rows[0]["C_File"].ToString() != "") { model.C_File = ds.Tables[0].Rows[0]["C_File"].ToString(); } if (ds.Tables[0].Rows[0]["C_Remark"] != null && ds.Tables[0].Rows[0]["C_Remark"].ToString() != "") { model.C_Remark = ds.Tables[0].Rows[0]["C_Remark"].ToString(); } if (ds.Tables[0].Rows[0]["C_Inputer"] != null && ds.Tables[0].Rows[0]["C_Inputer"].ToString() != "") { model.C_Inputer = decimal.Parse(ds.Tables[0].Rows[0]["C_Inputer"].ToString()); } if (ds.Tables[0].Rows[0]["C_InputDate"] != null && ds.Tables[0].Rows[0]["C_InputDate"].ToString() != "") { model.C_InputDate = DateTime.Parse(ds.Tables[0].Rows[0]["C_InputDate"].ToString()); model.InputDate = DateTime.Parse(ds.Tables[0].Rows[0]["C_InputDate"].ToString()).ToShortDateString(); } if (ds.Tables[0].Rows[0]["C_Editer"] != null && ds.Tables[0].Rows[0]["C_Editer"].ToString() != "") { model.C_Editer = decimal.Parse(ds.Tables[0].Rows[0]["C_Editer"].ToString()); } if (ds.Tables[0].Rows[0]["C_Editdate"] != null && ds.Tables[0].Rows[0]["C_Editdate"].ToString() != "") { model.C_Editdate = DateTime.Parse(ds.Tables[0].Rows[0]["C_Editdate"].ToString()); model.Editdate = DateTime.Parse(ds.Tables[0].Rows[0]["C_Editdate"].ToString()).ToShortDateString(); } return model; } else { return null; } }
/// <summary> /// 获得数据列表 /// </summary> public List<Model.ContractInfo> DataTableToList(DataTable dt) { List<Model.ContractInfo> modelList = new List<Model.ContractInfo>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.ContractInfo model; for (int n = 0; n < rowsCount; n++) { model = new Model.ContractInfo(); if (dt.Rows[n]["C_ID"] != null && dt.Rows[n]["C_ID"].ToString() != "") { model.C_ID = decimal.Parse(dt.Rows[n]["C_ID"].ToString()); } if (dt.Rows[n]["C_PID"] != null && dt.Rows[n]["C_PID"].ToString() != "") { model.C_PID = decimal.Parse(dt.Rows[n]["C_PID"].ToString()); } if (dt.Rows[n]["C_Name"] != null && dt.Rows[n]["C_Name"].ToString() != "") { model.C_Name = dt.Rows[n]["C_Name"].ToString(); } if (dt.Rows[n]["C_Fco"] != null && dt.Rows[n]["C_Fco"].ToString() != "") { model.C_Fco = dt.Rows[n]["C_Fco"].ToString(); } if (dt.Rows[n]["C_Sco"] != null && dt.Rows[n]["C_Sco"].ToString() != "") { model.C_Sco = dt.Rows[n]["C_Sco"].ToString(); } if (dt.Rows[n]["C_Date"] != null && dt.Rows[n]["C_Date"].ToString() != "") { model.C_Date = DateTime.Parse(dt.Rows[n]["C_Date"].ToString()); model.Date = Convert.ToDateTime(dt.Rows[n]["C_Date"].ToString()).ToShortDateString(); } if (dt.Rows[n]["C_FHeader"] != null && dt.Rows[n]["C_FHeader"].ToString() != "") { model.C_FHeader = dt.Rows[n]["C_FHeader"].ToString(); } if (dt.Rows[n]["C_SHeader"] != null && dt.Rows[n]["C_SHeader"].ToString() != "") { model.C_SHeader = dt.Rows[n]["C_SHeader"].ToString(); } if (dt.Rows[n]["C_Price"] != null && dt.Rows[n]["C_Price"].ToString() != "") { model.C_Price = decimal.Parse(dt.Rows[n]["C_Price"].ToString()); } if (dt.Rows[n]["C_BillAmount"] != null && dt.Rows[n]["C_BillAmount"].ToString() != "") { model.C_BillAmount = decimal.Parse(dt.Rows[n]["C_BillAmount"].ToString()); } if (dt.Rows[n]["C_UnBillAmount"] != null && dt.Rows[n]["C_UnBillAmount"].ToString() != "") { model.C_UnBillAmount = decimal.Parse(dt.Rows[n]["C_UnBillAmount"].ToString()); } if (dt.Rows[n]["C_PayAmount"] != null && dt.Rows[n]["C_PayAmount"].ToString() != "") { model.C_PayAmount = decimal.Parse(dt.Rows[n]["C_PayAmount"].ToString()); } if (dt.Rows[n]["C_UnpayAmount"] != null && dt.Rows[n]["C_UnpayAmount"].ToString() != "") { model.C_UnpayAmount = decimal.Parse(dt.Rows[n]["C_UnpayAmount"].ToString()); } if (dt.Rows[n]["C_SDate"] != null && dt.Rows[n]["C_SDate"].ToString() != "") { model.C_SDate = DateTime.Parse(dt.Rows[n]["C_SDate"].ToString()); model.SDate = Convert.ToDateTime(dt.Rows[n]["C_SDate"].ToString()).ToShortDateString(); } if (dt.Rows[n]["C_EDate"] != null && dt.Rows[n]["C_EDate"].ToString() != "") { model.C_EDate = DateTime.Parse(dt.Rows[n]["C_EDate"].ToString()); model.EDate = Convert.ToDateTime(dt.Rows[n]["C_EDate"].ToString()).ToShortDateString(); } if (dt.Rows[n]["C_Condition"] != null && dt.Rows[n]["C_Condition"].ToString() != "") { model.C_Condition = dt.Rows[n]["C_Condition"].ToString(); } if (dt.Rows[n]["C_Type"] != null && dt.Rows[n]["C_Type"].ToString() != "") { model.C_Type = int.Parse(dt.Rows[n]["C_Type"].ToString()); } if (dt.Rows[n]["C_Time"] != null && dt.Rows[n]["C_Time"].ToString() != "") { model.C_Time = int.Parse(dt.Rows[n]["C_Time"].ToString()); } if (dt.Rows[n]["C_State"] != null && dt.Rows[n]["C_State"].ToString() != "") { model.C_State = int.Parse(dt.Rows[n]["C_State"].ToString()); } if (dt.Rows[n]["C_File"] != null && dt.Rows[n]["C_File"].ToString() != "") { model.C_File = dt.Rows[n]["C_File"].ToString(); } if (dt.Rows[n]["C_Remark"] != null && dt.Rows[n]["C_Remark"].ToString() != "") { model.C_Remark = dt.Rows[n]["C_Remark"].ToString(); } if (dt.Rows[n]["C_Inputer"] != null && dt.Rows[n]["C_Inputer"].ToString() != "") { model.C_Inputer = decimal.Parse(dt.Rows[n]["C_Inputer"].ToString()); } if (dt.Rows[n]["C_InputDate"] != null && dt.Rows[n]["C_InputDate"].ToString() != "") { model.C_InputDate = DateTime.Parse(dt.Rows[n]["C_InputDate"].ToString()); model.InputDate = Convert.ToDateTime(dt.Rows[n]["C_InputDate"].ToString()).ToShortDateString(); } if (dt.Rows[n]["C_Editer"] != null && dt.Rows[n]["C_Editer"].ToString() != "") { model.C_Editer = decimal.Parse(dt.Rows[n]["C_Editer"].ToString()); } if (dt.Rows[n]["C_Editdate"] != null && dt.Rows[n]["C_Editdate"].ToString() != "") { model.C_Editdate = DateTime.Parse(dt.Rows[n]["C_Editdate"].ToString()); model.Editdate = Convert.ToDateTime(dt.Rows[n]["C_Editdate"].ToString()).ToShortDateString(); } if (dt.Rows[n]["P_Type"] != null && dt.Rows[n]["P_Type"].ToString() != "") { model.P_Type = int.Parse(dt.Rows[n]["P_Type"].ToString()); } if (dt.Rows[n]["U_RealName"] != null && dt.Rows[n]["U_RealName"].ToString() != "") { model.U_RealName = dt.Rows[n]["U_RealName"].ToString(); } if (dt.Rows[n]["P_No"] != null && dt.Rows[n]["P_No"].ToString() != "") { model.P_No = dt.Rows[n]["P_No"].ToString(); } if (dt.Rows[n]["P_Tag"] != null && dt.Rows[n]["P_Tag"].ToString() != "") { model.P_Tag = Convert.ToInt32(dt.Rows[n]["P_Tag"]); } if (dt.Rows[n]["P_BidSDate"] != null && dt.Rows[n]["P_BidSDate"].ToString() != "") { model.P_BidSDate = Convert.ToDateTime(dt.Rows[n]["P_BidSDate"]); model.BidSDate = Convert.ToDateTime(dt.Rows[n]["P_BidSDate"]).ToShortDateString(); } if (dt.Rows[n]["P_Number"] != null && dt.Rows[n]["P_Number"].ToString() != "") { model.P_Number = dt.Rows[n]["P_Number"].ToString(); } if (dt.Rows[n]["P_CDate"] != null && dt.Rows[n]["P_CDate"].ToString() != "") { model.P_CDate = Convert.ToDateTime(dt.Rows[n]["P_CDate"]); model.CDate = Convert.ToDateTime(dt.Rows[n]["P_CDate"]).ToShortDateString(); } if (dt.Rows[n]["P_Header"] != null && dt.Rows[n]["P_Header"].ToString() != "") { model.P_Header = dt.Rows[n]["P_Header"].ToString(); } if (dt.Rows[n]["P_Name"] != null && dt.Rows[n]["P_Name"].ToString() != "") { model.P_Name = dt.Rows[n]["P_Name"].ToString(); } modelList.Add(model); } } return modelList; }