using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsOp_YAXIANG; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using System.Web.Mvc;//ContentResult using DSWeb.TruckMng.Helper.Repository;//ModelObjectRepository using DSWeb.MvcShipping.Helper; using DSWeb.Areas.CommMng.DAL;//使用获取权限子句 using DSWeb.Areas.SysMng.DAL.SysTask; namespace DSWeb.Areas.MvcShipping.DAL.WMS_IN { public class Op_WMS_INDAL { #region 押箱业务 头表/明细表 static public List GetDataList ( string strCondition,string USERID, string sort = "" ) { var strSql = new StringBuilder(); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by YXNO "); } return SetData(strSql, USERID); } public static YXmb GetData(string condition, string USERID) { var dataList = GetDataList(condition, USERID); var result = new YXmb(); if (dataList.Count > 0) { result = dataList[0]; } else { result.getDef(USERID); } return result; } public static string getHeadListStr(string condition, string USERID) { string sql = YXmb.getSQL() ; var rangestr = BasicDataRefDAL.GetVisableRange("modYAXIANG", USERID, "COMPANYID", "CREATEUSER", "DEPTID"); if (!string.IsNullOrEmpty(rangestr)) { sql += " and " + rangestr; } if (!string.IsNullOrEmpty(condition)) { sql += condition; } return sql; } public static string getBodyListStr(string condition) { string sql = YX_DETAILmb.getSQL() + condition; //var rangestr = BasicDataRefDAL.GetVisableRange("modYAXIANG", USERID, "COMPANYID", "CREATEUSER", "DEPTID"); //if (!string.IsNullOrEmpty(rangestr)) { sql += " and " + rangestr; } return sql; } private static List SetData(StringBuilder strSql,string USERID)//, List fieldlist { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); string sql = getHeadListStr(strSql.ToString(), USERID); //var rangestr = BasicDataRefDAL.GetVisableRange("modYAXIANG", USERID, "COMPANYID","CREATEUSER","DEPTID"); //if (!string.IsNullOrEmpty(rangestr)) sql += " and " + rangestr; using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql)) { while (reader.Read()) { ////根据字段名设定同名属性值 YXmb data = new YXmb(); data.SetExtendValue(reader); headList.Add(data); } reader.Close(); } return headList; } static public List GetBodyList(string strCondition, string sort = null) { var strSql = new StringBuilder(); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by sort "); } return SetBodyData(strSql); } private static List SetBodyData(StringBuilder strSql)//, List fieldlist { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); string sql = getBodyListStr(strSql.ToString()); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql)) { while (reader.Read()) { ////根据字段名设定同名属性值 YX_DETAILmb data = new YX_DETAILmb(); data.SetExtendValue(reader); headList.Add(data); } reader.Close(); } return headList; } #endregion static public Resultmb ReCount(YXmb head) { var strSql = new StringBuilder(); var Result = new Resultmb(); var needrecount = SysTaskDAL.TaskGetWord(head.GetValue("YXSTATE"), "recount"); var needclear = SysTaskDAL.TaskGetWord(head.GetValue("YXSTATE"), "clear"); //strSql.Append(" delete from [workflow_using] where cargo_id in( " + cargo_id + ")"); if (needrecount) { strSql.Append(" update msop_yaxiang set spendmoney =isnull( (select sum(totalfee) from msop_yaxiang_detail where yxno=msop_yaxiang.yxno),0) "); strSql.Append(" , RETURNMONEY = isnull(YXMONEY, 0) - isnull((select sum(totalfee) from msop_yaxiang_detail where yxno = msop_yaxiang.yxno), 0) "); strSql.Append(" where yxno = '" + head.GetValue("YXNO") + "'"); } if (needclear) { strSql.Append(" update msop_yaxiang set spendmoney =isnull( (select sum(totalfee) from msop_yaxiang_detail where yxno=msop_yaxiang.yxno),0) "); strSql.Append(" , RETURNMONEY = 0 "); strSql.Append(" where yxno = '" + head.GetValue("YXNO") + "'"); } var _Result = new Resultmb(); Database db = DatabaseFactory.CreateDatabase(); try { _Result.totalCount = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); } catch (Exception ee) { _Result.Success = false; _Result.Message = ee.Message; } return _Result; } static public Resultmb DeleteDetail(YXmb head) { var strSql = new StringBuilder(); var Result = new Resultmb(); //strSql.Append(" delete from [workflow_using] where cargo_id in( " + cargo_id + ")"); strSql.Append(" update msop_yaxiang set spendmoney =isnull( (select sum(totalfee) from msop_yaxiang_detail where yxno=msop_yaxiang.yxno),0) "); strSql.Append(" , RETURNMONEY = isnull(YXMONEY, 0) - isnull((select sum(totalfee) from msop_yaxiang_detail where yxno = msop_yaxiang.yxno), 0) "); strSql.Append(" where yxno = '" + head.GetValue("YXNO") + "'"); var _Result = new Resultmb(); Database db = DatabaseFactory.CreateDatabase(); try { _Result.totalCount = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); } catch (Exception ee) { _Result.Success = false; _Result.Message = ee.Message; } return _Result; } } }