using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using System.Text; using DSWeb.Areas.TruckMng.Models.Card; using DSWeb.Areas.OA.Models.Comm; using Microsoft.Practices.EnterpriseLibrary.Data; using HcUtility.Comm; using DSWeb.Areas.CommMng.DAL; namespace DSWeb.Areas.TruckMng.DAL.Card { public partial class CardDAL { #region 充值卡列表 //卡列表 static public List GetDataList ( string strCondition ) { var strSql = new StringBuilder(); strSql.Append(" select *,(select sum(isnull(innum,0))-sum(isnull(outnum,0)) from tcard_use u where U.cardgid=tSavings_card.gid ) remain from tSavings_card where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetData(strSql); } static public CardHeadmb GetData ( string condition ) { var list = GetDataList(condition); if (list.Count > 0) return list[0]; return new CardHeadmb(); } private static List SetData ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CardHeadmb data = new CardHeadmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CARDNO = Convert.ToString(reader["CARDNO"]); data.CARDTYPE = Convert.ToString(reader["CARDTYPE"]); data.OP = Convert.ToString(reader["OP"]); data.OWNGID = Convert.ToString(reader["OWNGID"]); data.ISDELETE = Convert.ToString(reader["ISDELETE"]); data.REMAIN = Convert.ToString(reader["REMAIN"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 充值卡的使用 internal static string DealCard(string BILLNO, string OWNID, string CARDTYPE, string Operate, string Innum, string Outnum) { var strSql = new StringBuilder(); strSql.Append(" delete from tCard_Use where billno='" + BILLNO + "' and cardgid= (select gid from tsavings_card where CARDTYPE='" + CARDTYPE + "' and owngid='" + OWNID + "') "); if (double.Parse(Innum) != 0 || double.Parse(Outnum) != 0) { strSql.Append(" insert into tCard_Use (GID,CARDNO,BILLNO,OPERATE,INNUM,OUTNUM,OPTIME,REMARK,CARDGID) values "); strSql.Append(" (newid(),(select cardno from tsavings_card t where t.CARDTYPE='" + CARDTYPE + "' and t.owngid='" + OWNID + "') "); strSql.Append(" ,'" + BILLNO + "','" + Operate + "'," + Innum + "," + Outnum + ",getdate(),'',(select gid from tsavings_card where CARDTYPE='" + CARDTYPE + "' and owngid='" + OWNID + "') ) "); } var sql = strSql.ToString(); Database db = DatabaseFactory.CreateDatabase(); var _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count.ToString(); } #endregion #region 充值卡充值/使用列表 static public List GetUseList ( string strCondition ) { var strSql = new StringBuilder(); strSql.Append(" select * from tCard_Use where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" order by optime " ); return SetUseData(strSql); } private static List SetUseData ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CardUsemb data = new CardUsemb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CARDNO = Convert.ToString(reader["CARDNO"]); data.CARDGID = Convert.ToString(reader["CARDGID"]); data.BILLNO = Convert.ToString(reader["BILLNO"]); data.OPERATE = Convert.ToString(reader["OPERATE"]); data.INNUM = Convert.ToString(reader["INNUM"]); data.OUTNUM = Convert.ToString(reader["OUTNUM"]); data.OPTIME = Convert.ToString(reader["OPTIME"]); data.REMARK = Convert.ToString(reader["REMARK"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion static public string GetCardRemain(string OWNID, string CARDTYPE) { //获取剩余数量 var strSql = new StringBuilder(); strSql.Append(" select sum(isnull(innum,0))-sum(isnull(outnum,0)) Remain from tCard_Use "); strSql.Append(" where cardgid= (select gid from tsavings_card where CARDTYPE='" + CARDTYPE + "' and owngid='" + OWNID + "') "); Database db = DatabaseFactory.CreateDatabase(); var Remain = ""; using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { #region Set DB data to Object Remain = Convert.ToString(reader["Remain"]); #endregion } reader.Close(); } return Remain; } static public string SearchCardUse ( string condition ) { //获取卡片的使用明细数量 var strSql = new StringBuilder(); strSql.Append(" select count(*) _count from tcard_use " + condition ); Database db = DatabaseFactory.CreateDatabase(); var _count = "0"; using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { #region Set DB data to Object _count = Convert.ToString(reader["_count"]); #endregion } reader.Close(); } return _count; } static public int DeleteCard ( string GID ) { var strSql = new StringBuilder(); strSql.Append(" delete from tSavings_card where gid= '" + GID + "'"); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count; } static public int DeleteCardUse ( string GID ) { var strSql = new StringBuilder(); strSql.Append(" delete from tcard_Use where gid= '" + GID + "'"); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count; } } }