using System; using System.Text; using System.Data; using System.Data.SqlClient; using DSWeb.Models; using WebSqlHelper; namespace DSWeb.EntityDA { /// /// 数据访问类:WmsRateDA /// public partial class WmsRateDA { public WmsRateDA() { } #region Method /// /// 是否存在该记录 /// public bool Exists(string GID) { using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from wms_rate"); strSql.Append(" where GID='@GID' "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,36) }; parameters[0].Value = GID; try { return bool.Parse(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters).ToString()); } catch { return false; } } } /// /// 增加一条数据 /// public bool Add(WmsRateEntity model) { using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wms_rate("); strSql.Append("GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME,{0}ADDPRICE,FEENAME,RATETYPE,FEETYPE,CAPPRICE)"); strSql.Append(" values ("); strSql.Append("@GID,@BSNO,@FEEGRADE,@FEESCALE,@FEEPRICE,@FEEUNIT,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),@REMARK,@CUSTOMERNAME,{1}@ADDPRICE,@FEENAME,@RATETYPE,@FEETYPE,@CAPPRICE)"); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,36), new SqlParameter("@BSNO", SqlDbType.VarChar,100), new SqlParameter("@FEEGRADE", SqlDbType.Int,4), new SqlParameter("@FEESCALE", SqlDbType.Int,4), new SqlParameter("@FEEPRICE", SqlDbType.Decimal,9), new SqlParameter("@FEEUNIT", SqlDbType.VarChar,20), new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36), new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36), new SqlParameter("@REMARK", SqlDbType.VarChar,1024), new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20), new SqlParameter("@ADDPRICE", SqlDbType.Decimal,9) , new SqlParameter("@FEENAME", SqlDbType.VarChar,100) , new SqlParameter("@RATETYPE", SqlDbType.Int,4) , new SqlParameter("@FEETYPE", SqlDbType.Int,4) , new SqlParameter("@CAPPRICE", SqlDbType.Decimal,9) }; parameters[0].Value = model.GID; parameters[1].Value = model.BSNO; parameters[2].Value = model.FEEGRADE; parameters[3].Value = model.FEESCALE; parameters[4].Value = model.FEEPRICE; parameters[5].Value = model.FEEUNIT; parameters[6].Value = model.CREATEUSER; parameters[7].Value = model.MODIFIEDUSER; parameters[8].Value = model.REMARK; parameters[9].Value = model.CUSTOMERNAME; parameters[10].Value = model.ADDPRICE; parameters[11].Value = model.FEENAME; parameters[12].Value = model.RATETYPE; parameters[13].Value = model.FEETYPE; parameters[14].Value = model.CAPPRICE; string sSQL = strSql.ToString(); //操作时间 string strENDBILLINGDATE = model.ENDBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.ENDBILLINGDATE.ToString() + "',"; string strENDBILLINGDATE_name = strENDBILLINGDATE.Equals("") ? "" : "ENDBILLINGDATE,"; sSQL = String.Format(sSQL, strENDBILLINGDATE_name, strENDBILLINGDATE); int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sSQL, parameters); if (rows > 0) { return true; } else { return false; } } } /// /// 更新一条数据 /// public bool Update(WmsRateEntity model) { using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wms_rate set "); strSql.Append("BSNO=@BSNO,"); strSql.Append("FEEGRADE=@FEEGRADE,"); strSql.Append("FEESCALE=@FEESCALE,"); strSql.Append("FEEPRICE=@FEEPRICE,"); strSql.Append("FEEUNIT=@FEEUNIT,"); strSql.Append("MODIFIEDUSER=@MODIFIEDUSER,"); strSql.Append("MODIFIEDTIME=getdate(),"); strSql.Append("REMARK=@REMARK,"); strSql.Append("CUSTOMERNAME=@CUSTOMERNAME, "); strSql.Append(" {0} "); strSql.Append(" ADDPRICE = @ADDPRICE , "); strSql.Append(" FEENAME = @FEENAME , "); strSql.Append(" RATETYPE = @RATETYPE, "); strSql.Append(" FEETYPE = @FEETYPE, "); strSql.Append(" CAPPRICE = @CAPPRICE "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@BSNO", SqlDbType.VarChar,100), new SqlParameter("@FEEGRADE", SqlDbType.Int,4), new SqlParameter("@FEESCALE", SqlDbType.Int,4), new SqlParameter("@FEEPRICE", SqlDbType.Decimal,9), new SqlParameter("@FEEUNIT", SqlDbType.VarChar,20), new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36), new SqlParameter("@REMARK", SqlDbType.VarChar,1024), new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20), new SqlParameter("@GID", SqlDbType.VarChar,36), new SqlParameter("@ADDPRICE", SqlDbType.Decimal,9) , new SqlParameter("@FEENAME", SqlDbType.VarChar,100) , new SqlParameter("@RATETYPE", SqlDbType.Int,4) , new SqlParameter("@FEETYPE", SqlDbType.Int,4), new SqlParameter("@CAPPRICE", SqlDbType.Decimal,9) }; parameters[0].Value = model.BSNO; parameters[1].Value = model.FEEGRADE; parameters[2].Value = model.FEESCALE; parameters[3].Value = model.FEEPRICE; parameters[4].Value = model.FEEUNIT; parameters[5].Value = model.MODIFIEDUSER; parameters[6].Value = model.REMARK; parameters[7].Value = model.CUSTOMERNAME; parameters[8].Value = model.GID; parameters[9].Value = model.ADDPRICE; parameters[10].Value = model.FEENAME; parameters[11].Value = model.RATETYPE; parameters[12].Value = model.FEETYPE; parameters[13].Value = model.CAPPRICE; string sSQL = strSql.ToString(); //开船日期 string strENDBILLINGDATE = model.ENDBILLINGDATE.ToString().IndexOf("0001") > -1 ? "null," : "ENDBILLINGDATE='" + model.ENDBILLINGDATE.ToString() + "',"; sSQL = String.Format(sSQL, strENDBILLINGDATE); int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sSQL, parameters); if (rows > 0) { return true; } else { return false; } } } /// /// 删除一条数据 /// public bool Delete(string GID) { using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from wms_rate "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,36) }; parameters[0].Value = GID; //int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } } /// /// 批量删除数据 /// public bool DeleteList(string GIDlist) { using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from wms_rate "); strSql.Append(" where GID in (" + GIDlist + ") "); //int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString()); if (rows > 0) { return true; } else { return false; } } } /// /// 删除一条数据 /// public bool DeleteDTj(string Bsno) { using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from wms_rate "); strSql.Append(" where BSNO=@BSNO "); SqlParameter[] parameters = { new SqlParameter("@BSNO", SqlDbType.VarChar,100) }; parameters[0].Value = Bsno; int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } } /// /// 得到一个对象实体 /// public WmsRateEntity GetModel(string GID) { WmsRateEntity model =new WmsRateEntity(); StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE, ADDPRICE, FEENAME, (CASE WHEN RATETYPE = 1 THEN '仓储费' ELSE '' END) as RATETYPE,(CASE WHEN FEETYPE = 1 THEN '收' ELSE '付' END) as FEETYPE,ISCHANGE,CAPPRICE from wms_rate "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,36) }; parameters[0].Value = GID; using(SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters)) { try { while (sqlRead.Read()) { if (sqlRead["GID"] != null && sqlRead["GID"].ToString() != "") { model.GID = sqlRead["GID"].ToString(); } if (sqlRead["BSNO"] != null && sqlRead["BSNO"].ToString() != "") { model.BSNO = sqlRead["BSNO"].ToString(); } if (sqlRead["FEEGRADE"] != null && sqlRead["FEEGRADE"].ToString() != "") { model.FEEGRADE = int.Parse(sqlRead["FEEGRADE"].ToString()); } if (sqlRead["FEESCALE"] != null && sqlRead["FEESCALE"].ToString() != "") { model.FEESCALE = int.Parse(sqlRead["FEESCALE"].ToString()); } if (sqlRead["FEEPRICE"] != null && sqlRead["FEEPRICE"].ToString() != "") { model.FEEPRICE = decimal.Parse(sqlRead["FEEPRICE"].ToString()); } if (sqlRead["FEEUNIT"] != null && sqlRead["FEEUNIT"].ToString() != "") { model.FEEUNIT = sqlRead["FEEUNIT"].ToString(); } if (sqlRead["CREATEUSER"] != null && sqlRead["CREATEUSER"].ToString() != "") { model.CREATEUSER = sqlRead["CREATEUSER"].ToString(); } if (sqlRead["CREATETIME"] != null && sqlRead["CREATETIME"].ToString() != "") { model.CREATETIME = DateTime.Parse(sqlRead["CREATETIME"].ToString()); } if (sqlRead["MODIFIEDUSER"] != null && sqlRead["MODIFIEDUSER"].ToString() != "") { model.MODIFIEDUSER = sqlRead["MODIFIEDUSER"].ToString(); } if (sqlRead["MODIFIEDTIME"] != null && sqlRead["MODIFIEDTIME"].ToString() != "") { model.MODIFIEDTIME = DateTime.Parse(sqlRead["MODIFIEDTIME"].ToString()); } if (sqlRead["REMARK"] != null && sqlRead["REMARK"].ToString() != "") { model.REMARK = sqlRead["REMARK"].ToString(); } if (sqlRead["CUSTOMERNAME"] != null && sqlRead["CUSTOMERNAME"].ToString() != "") { model.CUSTOMERNAME = sqlRead["CUSTOMERNAME"].ToString(); } if (sqlRead["ENDBILLINGDATE"].ToString() != "") { model.ENDBILLINGDATE = DateTime.Parse(sqlRead["ENDBILLINGDATE"].ToString()); } if (sqlRead["ADDPRICE"].ToString() != "") { model.ADDPRICE = decimal.Parse(sqlRead["ADDPRICE"].ToString()); } model.FEENAME = sqlRead["FEENAME"].ToString(); if (sqlRead["RATETYPE"].ToString() != "") { model.RATETYPE = int.Parse(sqlRead["RATETYPE"].ToString()); } if (sqlRead["ISCHANGE"] != null && sqlRead["ISCHANGE"].ToString() != "") { if ((sqlRead["ISCHANGE"].ToString() == "1") || (sqlRead["ISCHANGE"].ToString().ToLower() == "true")) { model.ISCHANGE = true; } else { model.ISCHANGE = false; } } if (sqlRead["CAPPRICE"] != null && sqlRead["CAPPRICE"].ToString() != "") { model.CAPPRICE = decimal.Parse(sqlRead["CAPPRICE"].ToString()); } } } catch (Exception exceError) { //抛出异常 throw exceError; } } return model; } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE, ADDPRICE, FEENAME, (CASE WHEN RATETYPE = 1 THEN '仓储费' ELSE '' END) as RATETYPE,(CASE WHEN FEETYPE = 1 THEN '收' ELSE '付' END) as FEETYPE,CAPPRICE "); strSql.Append(" FROM wms_rate "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE, ADDPRICE, FEENAME, (CASE WHEN RATETYPE = 1 THEN '仓储费' ELSE '' END) as RATETYPE,(CASE WHEN FEETYPE = 1 THEN '收' ELSE '付' END) as FEETYPE,CAPPRICE "); strSql.Append(" FROM wms_rate "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); //return DbHelperSQL.Query(strSql.ToString()); return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString()); } /// /// 获取记录总数 /// public int GetRecordCount(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) FROM wms_rate "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } //object obj = DbHelperSQL.GetSingle(strSql.ToString()); object obj = SqlHelper.GetSingle(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString()); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 分页获取数据列表 /// public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT * FROM ( "); strSql.Append(" SELECT ROW_NUMBER() OVER ("); if (!string.IsNullOrEmpty(orderby.Trim())) { strSql.Append("order by T." + orderby); } else { strSql.Append("order by T.GID desc"); } strSql.Append(")AS Row, T.* from wms_rate T "); if (!string.IsNullOrEmpty(strWhere.Trim())) { strSql.Append(" WHERE " + strWhere); } strSql.Append(" ) TT"); strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex); //return DbHelperSQL.Query(strSql.ToString()); return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString()); } /// /// 分页获取数据列表 /// public DataSet GetList(int PageSize,int PageIndex,string strWhere) { SqlParameter[] parameters = { new SqlParameter("@tblName", SqlDbType.VarChar, 255), new SqlParameter("@fldName", SqlDbType.VarChar, 255), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int), new SqlParameter("@IsReCount", SqlDbType.Bit), new SqlParameter("@OrderType", SqlDbType.Bit), new SqlParameter("@strWhere", SqlDbType.VarChar,1000), }; parameters[0].Value = "wms_rate"; parameters[1].Value = "GID"; parameters[2].Value = PageSize; parameters[3].Value = PageIndex; parameters[4].Value = 0; parameters[5].Value = 0; parameters[6].Value = strWhere; return SqlHelper.RunProcedure(SqlHelper.ConnectionStringLocalTransaction.ToString(), "UP_GetRecordByPage", parameters, "ds"); } #region 根据SQL语句查询仓储费率数据集 /// /// 根据SQL语句查询仓储费率数据集 /// /// /// public DataSet GetExcuteSql(string strSql) { DataSet userSet = new DataSet(); userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return userSet; } #endregion #endregion Method } }