/// <summary> /// 根据ID获取合同 /// </summary> public Model.ordh GetOrdhById(string compid, string factid, string ordid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * "); //strSql.Append(" isnull(ordh12,'') as ordh12, "); //strSql.Append(" isnull(maxqty,0) as maxqty "); strSql.Append(" from ordh where compid = @compid and factid = @factid and ordid = @ordid "); SqlParameter[] paras = { new SqlParameter("@compid", compid), new SqlParameter("@factid", factid), new SqlParameter("@ordid", ordid) }; ZGZY.Model.ordh ordh = null; DataTable dt = ZGZY.Common.SqlHelper.GetDataTable(ZGZY.Common.SqlHelper.connStr, CommandType.Text, strSql.ToString(), paras); if (dt.Rows.Count > 0) { ordh = new ZGZY.Model.ordh(); DataRowToModel(ordh, dt.Rows[0]); return(ordh); } else { return(null); } }
/// <summary> /// 新增数据验证 /// </summary> public void AddBeforeSave(Model.ordh ordh) { //检测合同代号是否已存在 ZGZY.Model.ordh ordhCompare = dal.GetOrdhById(ordh.compid, ordh.factid, ordh.ordid); if (ordhCompare != null) { throw new Exception("已经存在此合同!"); } }
/// <summary> /// 把DataRow行转成实体类对象 /// </summary> private void DataRowToModel(ZGZY.Model.ordh model, DataRow dr) { if (!DBNull.Value.Equals(dr["compid"])) { model.compid = dr["compid"].ToString(); } if (!DBNull.Value.Equals(dr["factid"])) { model.factid = dr["factid"].ToString(); } if (!DBNull.Value.Equals(dr["ordid"])) { model.ordid = dr["ordid"].ToString(); } if (!DBNull.Value.Equals(dr["orddate"])) { model.orddate = dr["orddate"].ToString(); } if (!DBNull.Value.Equals(dr["ordh12"])) { model.ordh12 = dr["ordh12"].ToString(); } if (!DBNull.Value.Equals(dr["maxqty"])) { model.maxqty = decimal.Parse(dr["maxqty"].ToString()); } if (!DBNull.Value.Equals(dr["custid"])) { model.custid = dr["custid"].ToString(); } if (!DBNull.Value.Equals(dr["empid"])) { model.empid = dr["empid"].ToString(); } if (!DBNull.Value.Equals(dr["ordh33"])) { model.ordh33 = dr["ordh33"].ToString(); } }