using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using DSWeb.Areas.Import.Models.RptImportKc; using DSWeb.TruckMng.Helper; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.TruckMng.Comm.Cookie; namespace DSWeb.Areas.Import.Controllers { /// /// 库存信息列表 /// public class RptImportKcController : Controller { // // GET: /Import/RptImportKc/ public ActionResult Index() { return View(); } public ContentResult GetDataList(int start, int limit, string sort, string condition) { var corpid = CookieConfig.GetCookie_OrgCode(Request); var dataList = GetDataList(condition, corpid); var list = dataList.Skip(start).Take(limit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() }); return new ContentResult() { Content = json }; } private static List GetDataList(string strCondition,string corpid) { var strSql = new StringBuilder(); strSql.Append(" Select K.id,k.ContractNo,m.HTH,k.CZState, "); strSql.Append(" (select enumvaluename from tsysenumvalue where enumtypeid=8 and enumvalueid=K.czstate) as CZRf,k.InNum,k.OutNum, "); strSql.Append(" k.KFstate,(select description from info_client where shortname=k.KFstate) as KFRf,c.FactoryNo, "); strSql.Append(" K.CZdate,K.[text],m.seller,m.buyer,m.Billno,m.Vessel,m.Voyage,m.Sailingdate,m.ArrivalDate,m.ContainerNo,m.SealNo, "); strSql.Append(" c.name as goodname,c.cargoinfo_id,(select code from import_cargoinfo where import_cargoinfo.id=c.cargoinfo_id) as cargoinfoRf, "); strSql.Append(" c.cargociq_id,(select ciqcode from import_cargociq where import_cargociq.id=c.cargociq_id) as cargociqRf "); strSql.Append(" ,case k.CZstate when 1 then k.quantity else 0 end as [weight],case k.CZstate when 3 then k.quantity else 0 end as [weight_out] "); strSql.Append(" ,comp.name as companyname from [Import_KC] K "); strSql.Append(" left join import_cargo c on convert(varchar(50),c.id)=k.cargo_id "); strSql.Append(" left join Import_main m on m.ContractNo=k.ContractNo "); strSql.Append(" left join company comp on comp.gid=M.company "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition ); // strSql.Append(" where " + strCondition + " and K.corpid=(select gid from company where codename='" + corpid + "')"); }/* else { strSql.Append(" where K.corpid='" + corpid + "'"); }*/ strSql.Append(" order by ContractNo,goodname,CZdate "); return SetData(strSql); } 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()) { var data = new RptImportKc(); #region Set DB data to Object data.Id = Convert.ToDecimal(reader["Id"]); data.Billno = Convert.ToString(reader["BillNo"]); data.ContractNo = Convert.ToString(reader["ContractNo"]); data.HTH = Convert.ToString(reader["HTH"]); data.CZRf = Convert.ToString(reader["CZRf"]); data.KFRf = Convert.ToString(reader["KFRf"]); data.CZdate = Convert.ToString(reader["CZdate"]); data.text = Convert.ToString(reader["text"]); data.seller = Convert.ToString(reader["seller"]); data.buyer = Convert.ToString(reader["buyer"]); data.Vessel = Convert.ToString(reader["Vessel"]); data.Voyage = Convert.ToString(reader["Voyage"]); data.Sailingdate = Convert.ToString(reader["Sailingdate"]); data.ArrivalDate = Convert.ToString(reader["ArrivalDate"]); data.ContainerNo = Convert.ToString(reader["ContainerNo"]); data.SealNo = Convert.ToString(reader["SealNo"]); data.goodname = Convert.ToString(reader["goodname"]); data.cargoinfoRf = Convert.ToString(reader["cargoinfoRf"]); data.cargociqRf = Convert.ToString(reader["cargociqRf"]); data.InNum = Convert.ToDecimal(reader["InNum"]); data.OutNum = Convert.ToDecimal(reader["OutNum"]); data.FactoryNo = Convert.ToString(reader["FactoryNo"]); data.Weight = Convert.ToString(reader["Weight"]); data.Weight_Out = Convert.ToString(reader["Weight_Out"]); data.CompanyName = Convert.ToString(reader["CompanyName"]); #endregion headList.Add(data); } reader.Close(); } return headList; } /*select cargo_id,K.ContractNo,m.HTH,m.buyer,cg.name,k.KFstate,cg.[weight],cg.BoxCount,cg.price,cg.price_agio,sum(innum-outnum) boxcount_remain ,isnull((select sum(quantity) from import_kc where CZState=1 and cargo_id=k.cargo_id),0) -isnull((select sum(quantity) from import_kc where CZState=3and cargo_id=k.cargo_id),0) weight_remain ,(select min(CZdate) from import_kc where CZState=1 and cargo_id=k.cargo_id ) inDate ,(select max(CZdate) from import_kc where CZState=3 and cargo_id=k.cargo_id ) outdate from Import_KC K left join import_main m on m.ContractNo=k.ContractNo left join import_cargo cg on cg.id=k.cargo_id group by K.cargo_id,K.ContractNo,m.HTH,m.buyer,cg.name,cg.[weight],cg.BoxCount,cg.price,cg.price_agio,k.KFstate */ public ContentResult GetWMSList ( int start, int limit, string sort, string condition ) { var corpid = CookieConfig.GetCookie_OrgCode(Request); var dataList = GetWMSList(condition, corpid); var list = dataList.Skip(start).Take(limit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() }); return new ContentResult() { Content = json }; } private static List GetWMSList ( string strCondition, string corpid ) { var strSql = new StringBuilder(); strSql.Append(" select k.cargo_id,k.ContractNo,M.HTH,M.ContainerNo,M.seller,M.buyer,comp.NAME companyname,k.KFstate,c.name goodname "); strSql.Append(" ,dbo.trimdate((select min(czdate) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=1 and k1.KFstate=k.KFstate)) indate "); strSql.Append(" ,isnull((select sum(isnull(innum,0)) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=1 and k1.KFstate=k.KFstate),0) innum "); strSql.Append(" ,isnull((select sum(isnull(Quantity,0)) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=1 and k1.KFstate=k.KFstate),0) [weight] "); strSql.Append(" ,dbo.trimdate((select max(czdate) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=3 and k1.KFstate=k.KFstate)) outdate "); strSql.Append(" ,isnull((select sum(isnull(outnum,0)) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=3 and k1.KFstate=k.KFstate),0) outnum "); strSql.Append(" ,isnull((select sum(isnull(k1.Quantity,0)) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=3 and k1.KFstate=k.KFstate),0) [weight_out] "); strSql.Append(" ,isnull((select isnull(sum(innum),0)-isnull(sum(outnum),0) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState in(1,3) and k1.KFstate=k.KFstate),0) remainnum "); strSql.Append(" ,isnull((select isnull(sum(k1.Quantity),0) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=1 and k1.KFstate=k.KFstate),0) "); strSql.Append(" -isnull((select isnull(sum(k1.Quantity),0) from import_kc k1 where k1.cargo_id=k.cargo_id and k1.CZState=3 and k1.KFstate=k.KFstate),3) RemainWeight "); strSql.Append(" from import_kc k "); strSql.Append(" left join import_cargo c on k.cargo_id=c.id "); strSql.Append(" left join import_main m on m.ContractNo=k.ContractNo "); strSql.Append(" left join company comp on comp.gid=M.company "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" group by k.cargo_id,k.ContractNo,M.HTH,M.ContainerNo,c.name,M.seller,M.buyer,comp.NAME,k.KFstate "); return SetWMSData(strSql); } private static List SetWMSData ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var data = new RptImportKc_WMS(); #region Set DB data to Object data.cargo_id = Convert.ToString(reader["cargo_id"]); data.ContractNo = Convert.ToString(reader["ContractNo"]); data.HTH = Convert.ToString(reader["HTH"]); data.ContainerNo = Convert.ToString(reader["ContainerNo"]); data.seller = Convert.ToString(reader["seller"]); data.buyer = Convert.ToString(reader["buyer"]); data.CompanyName = Convert.ToString(reader["CompanyName"]); data.KFstate = Convert.ToString(reader["KFstate"]); data.goodname = Convert.ToString(reader["goodname"]); data.InDate = Convert.ToString(reader["InDate"]); data.InNum = Convert.ToString(reader["InNum"]); data.OutDate = Convert.ToString(reader["OutDate"]); data.OutNum = Convert.ToString(reader["OutNum"]); data.RemainNum = Convert.ToString(reader["RemainNum"]); data.Weight = Convert.ToString(reader["Weight"]); data.Weight_Out = Convert.ToString(reader["Weight_Out"]); data.RemainWeight = Convert.ToString(reader["RemainWeight"]); #endregion headList.Add(data); } reader.Close(); } return headList; } } }