@ -20,20 +20,31 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
{
{
static JavaScriptSerializer serializer = new JavaScriptSerializer ( ) ;
static JavaScriptSerializer serializer = new JavaScriptSerializer ( ) ;
/ *
* //原型
SELECT w2 . id , w1 . * FROM B3ClientService_WeightBill w1 , (
SELECT TOP 1 0 0 row_number ( ) OVER ( order by ( case when Remark is null or Remark = ' ' then 0 else 1 end ) , ID ) n , ID FROM B3ClientService_WeightBill ) w2 WHERE w1 . ID = w2 . ID AND w2 . n > 9 0 ORDER BY w2 . n ASC
* /
[Rpc]
[Rpc]
public static string GetHouseAndSanctionList ( DateTime date )
public static string GetHouseAndSanctionList ( DateTime date , int pageSize , int pageNumber )
{
{
var temp = new JoinAlias ( typeof ( OrderTemp ) ) ;
var query = new DQueryDom ( temp ) ;
OrderTemp . Register ( query , date , pageSize * pageNumber ) ;
var main = new JoinAlias ( typeof ( WeightBill ) ) ;
var main = new JoinAlias ( typeof ( WeightBill ) ) ;
var detail = new JoinAlias ( typeof ( WeightBill_Detail ) ) ;
var detail = new JoinAlias ( typeof ( WeightBill_Detail ) ) ;
var query = new DQueryDom ( main ) ;
query . From . AddJoin ( JoinType . Left , new DQDmoSource ( main ) , DQCondition . EQ ( temp , "ID" , main , "ID" ) ) ;
query . From . AddJoin ( JoinType . Left , new DQDmoSource ( detail ) , DQCondition . And ( DQCondition . EQ ( detail , "DeleteState" , false ) , DQCondition . EQ ( main , "ID" , detail , "WeightBill_ID" ) ) ) ;
query . From . AddJoin ( JoinType . Left , new DQDmoSource ( detail ) , DQCondition . And ( DQCondition . EQ ( detail , "DeleteState" , false ) , DQCondition . EQ ( main , "ID" , detail , "WeightBill_ID" ) ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "ID" ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "B3ID" ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "Employee_Name" ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "Supplier_Name" ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "HouseNames" ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "ID" , main ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "B3ID" , main ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "Employee_Name" , main ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "Supplier_Name" , main ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "HouseNames" , main ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "Number" , detail ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "Number" , detail ) ) ;
query . Where . Conditions . Add ( DQCondition . And ( DQCondition . Between ( "WeighTime" , date , date + new TimeSpan ( 2 3 , 5 9 , 2 9 ) ) , DQCondition . EQ ( "DeleteState" , false ) ) ) ;
query . Where . Conditions . Add ( DQCondition . GreaterThan ( temp , "RowNumber" , pageSize * ( pageNumber - 1 ) ) ) ;
var list = new List < HouseAndSanctionList > ( ) ;
var list = new List < HouseAndSanctionList > ( ) ;
using ( var session = Dmo . NewSession ( ) )
using ( var session = Dmo . NewSession ( ) )
{
{
@ -55,6 +66,36 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
return serializer . Serialize ( list ) ;
return serializer . Serialize ( list ) ;
}
}
class OrderTemp
{
public int RowNumber { get ; set ; }
public long ID { get ; set ; }
public static void Register ( DQueryDom root , DateTime date , int total )
{
var query = new DQueryDom ( new JoinAlias ( "_pageTemp" , typeof ( WeightBill ) ) ) ;
query . Range = SelectRange . Top ( total ) ;
query . Columns . Add ( DQSelectColumn . Create ( DQExpression . Snippet ( "row_number() OVER (order by (case when [_pageTemp].[HouseNames] is null or [_pageTemp].[HouseNames]='' then 0 else 1 end),[_pageTemp].[ID])" ) , "RowNumber" ) ) ;
query . Columns . Add ( DQSelectColumn . Field ( "ID" ) ) ;
query . Where . Conditions . Add ( DQCondition . And ( DQCondition . Between ( "WeighTime" , date , date + new TimeSpan ( 2 3 , 5 9 , 2 9 ) ) , DQCondition . EQ ( "DeleteState" , false ) ) ) ;
root . RegisterQueryTable ( typeof ( OrderTemp ) , new string [ ] { "RowNumber" , "ID" } , query ) ;
}
}
[Rpc]
public static int GetMaxPageNumber ( DateTime date , int pageSize )
{
var query = new DQueryDom ( new JoinAlias ( typeof ( WeightBill ) ) ) ;
query . Where . Conditions . Add ( DQCondition . And ( DQCondition . Between ( "WeighTime" , date , date + new TimeSpan ( 2 3 , 5 9 , 2 9 ) ) , DQCondition . EQ ( "DeleteState" , false ) ) ) ;
query . Columns . Add ( DQSelectColumn . Count ( ) ) ;
var total = Convert . ToInt32 ( query . EExecuteScalar ( ) ) ;
var maxPageSize = total / pageSize ;
if ( total % pageSize ! = 0 )
maxPageSize + = 1 ;
return maxPageSize ;
}
[Rpc]
[Rpc]
public static int GetDetailTotalNumber ( DateTime date )
public static int GetDetailTotalNumber ( DateTime date )
{
{
@ -77,6 +118,9 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
var result = new HouseAndSanctionEdit ( ) ;
var result = new HouseAndSanctionEdit ( ) ;
using ( var session = Dmo . NewSession ( ) )
using ( var session = Dmo . NewSession ( ) )
{
{
var exist = ClientServiceUtils . Exist < WeightBill > ( id ) ;
if ( ! exist )
throw new Exception ( "过磅单已被删除" ) ;
result . ID = id ;
result . ID = id ;
result . HogGrade_ID = InnerBLUtil . GetDmoPropertyByID < long? > ( session , typeof ( WeightBill ) , "HogGrade_ID" , id ) ;
result . HogGrade_ID = InnerBLUtil . GetDmoPropertyByID < long? > ( session , typeof ( WeightBill ) , "HogGrade_ID" , id ) ;
result . Number = InnerBLUtil . GetDmoProperty < int? > ( session , typeof ( WeightBill_Detail ) , "Number" , new Tuple < string , object > ( "WeightBill_ID" , id ) , new Tuple < string , object > ( "DeleteState" , false ) ) ;
result . Number = InnerBLUtil . GetDmoProperty < int? > ( session , typeof ( WeightBill_Detail ) , "Number" , new Tuple < string , object > ( "WeightBill_ID" , id ) , new Tuple < string , object > ( "DeleteState" , false ) ) ;
@ -97,6 +141,12 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
public static int UpdateInsertHouseAndSanction ( string json )
public static int UpdateInsertHouseAndSanction ( string json )
{
{
var entity = serializer . Deserialize < HouseAndSanctionEdit > ( json ) ;
var entity = serializer . Deserialize < HouseAndSanctionEdit > ( json ) ;
var exist = ClientServiceUtils . Exist < WeightBill > ( entity . ID ) ;
if ( ! exist )
throw new Exception ( "过磅单已被删除,提交失败!" ) ;
var detailExist = ClientServiceUtils . Exist < WeightBill_Detail > ( "WeightBill_ID" , entity . ID ) ;
if ( ! detailExist )
throw new Exception ( "过磅记录已被删除,提交失败!" ) ;
using ( var session = Dmo . NewSession ( ) )
using ( var session = Dmo . NewSession ( ) )
{
{
//为了节省ID,把传过来的通过栋舍匹配,并到原有明细里。然后从新的集合里把上传的集合里不存在的剔除掉
//为了节省ID,把传过来的通过栋舍匹配,并到原有明细里。然后从新的集合里把上传的集合里不存在的剔除掉
@ -172,6 +222,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
update . Columns . Add ( new DQUpdateColumn ( "HouseNames" , string . Join ( "," , houseNames ) ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "HouseNames" , string . Join ( "," , houseNames ) ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "SanctionNumber" , entity . SanctionDetails . Sum ( x = > x . Number ? ? 0 ) ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "SanctionNumber" , entity . SanctionDetails . Sum ( x = > x . Number ? ? 0 ) ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "Sync" , false ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "Sync" , false ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "RowVersion" , DQExpression . Add ( DQExpression . Field ( "RowVersion" ) , DQExpression . Value ( 1 ) ) ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "ModifyTime" , DateTime . Now ) ) ;
update . Columns . Add ( new DQUpdateColumn ( "ModifyTime" , DateTime . Now ) ) ;
update . Where . Conditions . Add ( DQCondition . EQ ( "ID" , entity . ID ) ) ;
update . Where . Conditions . Add ( DQCondition . EQ ( "ID" , entity . ID ) ) ;
session . ExecuteNonQuery ( update ) ;
session . ExecuteNonQuery ( update ) ;