@ -47,17 +47,21 @@ namespace WeighBusiness.BL
public static void Insert ( List < ProductCatalog > productCatalogs , List < ProductCatalog_Detail > catalogDetails )
public static void Insert ( List < ProductCatalog > productCatalogs , List < ProductCatalog_Detail > catalogDetails )
{
{
using ( var she = new SqlHelperEx ( ) ) {
using ( var she = new SqlHelperEx ( ) )
{
she . CreateTransaction ( ) ;
she . CreateTransaction ( ) ;
bool success = false ;
bool success = false ;
string errorMessage ;
string errorMessage ;
if ( productCatalogs . Count ( ) > 0 ) {
foreach ( var catalog in productCatalogs ) {
if ( productCatalogs . Count ( ) > 0 )
{
foreach ( var catalog in productCatalogs )
{
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 ,
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 ,
new string [ ] { "ProductCatalog_ID" , "Name" , "RowVersion" } ,
new string [ ] { "ProductCatalog_ID" , "Name" , "RowVersion" } ,
new string [ ] { catalog . ProductCatalog_ID . ToString ( ) , catalog . Name , catalog . RowVersion . ToString ( ) } ) ;
new string [ ] { catalog . ProductCatalog_ID . ToString ( ) , catalog . Name , catalog . RowVersion . ToString ( ) } ) ;
she . ExecuteNonQuery ( insertSql , out success , out errorMessage ) ;
she . ExecuteNonQuery ( insertSql , out success , out errorMessage ) ;
if ( ! success & & ! string . IsNullOrEmpty ( errorMessage ) ) {
if ( ! success & & ! string . IsNullOrEmpty ( errorMessage ) )
{
she . Rollback ( ) ;
she . Rollback ( ) ;
throw new ApplicationException ( errorMessage ) ;
throw new ApplicationException ( errorMessage ) ;
}
}
@ -67,8 +71,8 @@ namespace WeighBusiness.BL
if ( catalogDetails . Count ( ) > 0 ) {
if ( catalogDetails . Count ( ) > 0 ) {
foreach ( var detail in catalogDetails ) {
foreach ( var detail in catalogDetails ) {
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 明 细 ,
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 明 细 ,
new string [ ] { "ProductCatalog_ID" , "CatalogDetail_ID" , "Goods_Name" , "Goods_ID" , "UnitConvertDirection" , "MainUnitRatio" , "SecondUnitRatio" , "Goods_Spec" , "Goods_Code" } ,
new string [ ] { detail . ProductCatalog_ID . ToString ( ) , detail . CatalogDetail_ID . ToString ( ) , detail . Goods_Name , detail . Goods_ID . ToString ( ) , detail . UnitConvertDirection = = null ? "null" : detail . UnitConvertDirection . ToString ( ) , detail . MainUnitRatio = = null ? "null" : detail . MainUnitRatio . ToString ( ) , detail . SecondUnitRatio = = null ? "null" : detail . SecondUnitRatio . ToString ( ) , detail . Goods_Spec , detail . Goods_Code } ) ;
new string [ ] { "ProductCatalog_ID" , "CatalogDetail_ID" , "Goods_Name" , "Goods_ID" , "UnitConvertDirection" , "MainUnitRatio" , "SecondUnitRatio" , "Goods_Spec" , "Goods_Code" , "Employee_Name" } ,
new string [ ] { detail . ProductCatalog_ID . ToString ( ) , detail . CatalogDetail_ID . ToString ( ) , detail . Goods_Name , detail . Goods_ID . ToString ( ) , detail . UnitConvertDirection = = null ? "null" : detail . UnitConvertDirection . ToString ( ) , detail . MainUnitRatio = = null ? "null" : detail . MainUnitRatio . ToString ( ) , detail . SecondUnitRatio = = null ? "null" : detail . SecondUnitRatio . ToString ( ) , detail . Goods_Spec , detail . Goods_Code , detail . Employee_Name ? ? string . Empty } ) ;
she . ExecuteNonQuery ( insertSql , out success , out errorMessage ) ;
she . ExecuteNonQuery ( insertSql , out success , out errorMessage ) ;
if ( ! success & & ! string . IsNullOrEmpty ( errorMessage ) ) {
if ( ! success & & ! string . IsNullOrEmpty ( errorMessage ) ) {
she . Rollback ( ) ;
she . Rollback ( ) ;
@ -108,62 +112,63 @@ namespace WeighBusiness.BL
public static void SyncProductCatalog ( )
public static void SyncProductCatalog ( )
{
{
var domain_ID = ConfigurationManager . AppSettings [ "Domain_ID" ] ;
var domain_ID = ConfigurationManager . AppSettings [ "Domain_ID" ] ;
var method = "/MainSystem/B3_HaoYue/Rpcs/B3CowButcherManageRpc/GetProductCatalogRowVersion" ;
var clientNode = ConfigurationManager . AppSettings [ "ClientNode" ] ;
var method = "/MainSystem/B3_HaoYue/Rpcs/B3CowButcherManageRpc/MewGetProductCatalogRowVersion" ;
if ( domain_ID ! = null & & ! string . IsNullOrEmpty ( domain_ID . ToString ( ) ) ) {
if ( domain_ID ! = null & & ! string . IsNullOrEmpty ( domain_ID . ToString ( ) ) ) {
var productCatalogRowVersion = RpcFacade . Call < List < Tuple < long? , int? , string > > > ( method , long . Parse ( domain_ID ) ) ;
var productCatalogRowVersion = RpcFacade . Call < List < Tuple < long? , int? , string > > > ( method , long . Parse ( domain_ID ) , clientNode ) ;
Delete ( ) ;
Delete ( ) ;
//var oldpCatalogRowVersion = GetProductCatalogRowVersion();
//var oldpCatalogRowVersion = GetProductCatalogRowVersion();
var oldpCatalogRowVersion = new List < ProductCatalog > ( ) ;
// var oldpCatalogRowVersion = new List<ProductCatalog>();
var needInsertCatalogID = new List < long? > ( ) ;
var needInsertCatalogID = new List < long? > ( ) ;
var needDeleteAndInsertCatalogID = new List < long? > ( ) ;
if ( productCatalogRowVersion . Count > 0 ) {
if ( oldpCatalogRowVersion . Count ( ) < = 0 ) {
productCatalogRowVersion . ForEach ( x = > needInsertCatalogID . Add ( x . Item1 ) ) ;
} else {
foreach ( var catalogRowVersion in productCatalogRowVersion ) {
var catalog_ID = catalogRowVersion . Item1 ;
var oldCatalogs = oldpCatalogRowVersion . Where ( x = > x . ProductCatalog_ID = = catalog_ID ) ;
if ( oldCatalogs . Count ( ) > 0 & & oldCatalogs . FirstOrDefault ( ) . RowVersion ! = catalogRowVersion . Item2 ) {
needDeleteAndInsertCatalogID . Add ( catalog_ID ) ;
} else if ( oldCatalogs . Count ( ) < = 0 ) {
needInsertCatalogID . Add ( catalog_ID ) ;
}
}
foreach ( var oldVersion in oldpCatalogRowVersion ) {
if ( ! productCatalogRowVersion . Any ( x = > x . Item1 = = oldVersion . ProductCatalog_ID ) ) {
Delete ( oldVersion . ProductCatalog_ID ) ;
}
}
}
} else {
//var needDeleteAndInsertCatalogID = new List<long?>();
if ( productCatalogRowVersion . Count > 0 )
{
productCatalogRowVersion . ForEach ( x = > needInsertCatalogID . Add ( x . Item1 ) ) ;
//{ } else {
//foreach (var catalogRowVersion in productCatalogRowVersion) {
// var catalog_ID = catalogRowVersion.Item1;
// var oldCatalogs = oldpCatalogRowVersion.Where(x => x.ProductCatalog_ID == catalog_ID);
// if (oldCatalogs.Count() > 0 && oldCatalogs.FirstOrDefault().RowVersion != catalogRowVersion.Item2) {
// needDeleteAndInsertCatalogID.Add(catalog_ID);
// } else if (oldCatalogs.Count() <= 0) {
// needInsertCatalogID.Add(catalog_ID);
// }
//}
//foreach (var oldVersion in oldpCatalogRowVersion) {
// if (!productCatalogRowVersion.Any(x => x.Item1 == oldVersion.ProductCatalog_ID)) {
// Delete(oldVersion.ProductCatalog_ID);
// }
//}
//}
}
else
{
Delete ( ) ;
Delete ( ) ;
}
}
if ( needDeleteAndInsertCatalogID . Count ( ) > 0 ) {
foreach ( var catalogID in needDeleteAndInsertCatalogID ) {
var error = Delete ( catalogID . Value ) ;
if ( ! string . IsNullOrEmpty ( error ) ) {
throw new ApplicationException ( error ) ;
}
needInsertCatalogID . Add ( catalogID ) ;
}
}
//if (needDeleteAndInsertCatalogID.Count() > 0) {
// foreach (var catalogID in needDeleteAndInsertCatalogID) {
// var error = Delete(catalogID.Value);
// if (!string.IsNullOrEmpty(error)) {
// throw new ApplicationException(error);
// }
// needInsertCatalogID.Add(catalogID);
// }
//}
if ( needInsertCatalogID . Count > 0 ) {
if ( needInsertCatalogID . Count > 0 ) {
var method2 = "/MainSystem/B3_HaoYue/Rpcs/B3CowButcherManageRpc/GetProductCatalogDetailData" ;
var catalogDetails = RpcFacade . Call < List < RpcObject > > ( method2 , needInsertCatalogID . ToArray ( ) ) ;
var method2 = "/MainSystem/B3_HaoYue/Rpcs/B3CowButcherManageRpc/New GetProductCatalogDetailData" ;
var catalogDetails = RpcFacade . Call < List < RpcObject > > ( method2 , needInsertCatalogID . Distinct ( ) . ToArray ( ) , clientNode ) ;
var list = new List < ProductCatalog > ( ) ;
var list = new List < ProductCatalog > ( ) ;
var detailList = new List < ProductCatalog_Detail > ( ) ;
var detailList = new List < ProductCatalog_Detail > ( ) ;
foreach ( var catalogID in needInsertCatalogID ) {
var catalog = new ProductCatalog ( ) ;
catalog . ProductCatalog_ID = catalogID . Value ;
var result = productCatalogRowVersion . Where ( x = > x . Item1 = = catalogID ) . First ( ) ;
catalog . ProductCatalog_ID = result . Item1 . Value ;
catalog . RowVersion = result . Item2 . Value ;
catalog . Name = result . Item3 ;
foreach ( var tuple in productCatalogRowVersion ) {
var catalog = new ProductCatalog ( ) ;
catalog . ProductCatalog_ID = tuple . Item1 ? ? 0 ;
catalog . RowVersion = tuple . Item2 ? ? 0 ;
catalog . Name = tuple . Item3 ;
list . Add ( catalog ) ;
list . Add ( catalog ) ;
}
}
@ -180,6 +185,7 @@ namespace WeighBusiness.BL
catalogDetail . SecondUnitRatio = detail . Get < decimal? > ( "SecondUnitRatio" ) ;
catalogDetail . SecondUnitRatio = detail . Get < decimal? > ( "SecondUnitRatio" ) ;
catalogDetail . Goods_Spec = detail . Get < string > ( "Goods_Spec" ) ;
catalogDetail . Goods_Spec = detail . Get < string > ( "Goods_Spec" ) ;
catalogDetail . Goods_Code = detail . Get < string > ( "Goods_Code" ) ;
catalogDetail . Goods_Code = detail . Get < string > ( "Goods_Code" ) ;
catalogDetail . Employee_Name = detail . Get < string > ( "Employee_Name" ) ;
detailList . Add ( catalogDetail ) ;
detailList . Add ( catalogDetail ) ;
}
}
}
}
@ -221,6 +227,7 @@ namespace WeighBusiness.BL
catalog . ProductCatalog_ID = ( long ) ( int . Parse ( row [ 0 ] . ToString ( ) ) ) ;
catalog . ProductCatalog_ID = ( long ) ( int . Parse ( row [ 0 ] . ToString ( ) ) ) ;
catalog . Name = row [ 1 ] . ToString ( ) ;
catalog . Name = row [ 1 ] . ToString ( ) ;
catalog . Sequence = DataTypeUtil . GetIntNullNum ( row [ 2 ] ) ;
catalog . Sequence = DataTypeUtil . GetIntNullNum ( row [ 2 ] ) ;
list . Add ( catalog ) ;
list . Add ( catalog ) ;
}
}
return list ;
return list ;
@ -230,7 +237,15 @@ namespace WeighBusiness.BL
public static List < ProCataGoods > GetProductCatalogDetails ( bool? isSelected = null )
public static List < ProCataGoods > GetProductCatalogDetails ( bool? isSelected = null )
{
{
var table = SqlHelperEx . DoQuery ( "select a.ProductCatalog_ID,a.CatalogDetail_ID,a.Goods_Name,a.Goods_ID,b.Goods_ID,a.UnitConvertDirection,a.MainUnitRatio,a.SecondUnitRatio,a.Goods_Spec,a.Goods_Code from {0} a left outer join {1} b on a.ProductCatalog_ID = b.ProductCatalog_ID and a.Goods_ID = b.Goods_ID where 1=1 {2}" . FormatWith ( TableNames . 客 户 端 产 品 分 类 明 细 , TableNames . 客 户 端 产 品 分 类 配 制 存 货 , isSelected = = true ? "and b.Goods_ID is not null" : string . Empty ) ) ;
var table = SqlHelperEx . DoQuery ( @ "select a.ProductCatalog_ID,a.CatalogDetail_ID,a.Goods_Name,a.Goods_ID,b.Goods_ID,a.UnitConvertDirection,
a . MainUnitRatio , a . SecondUnitRatio , a . Goods_Spec , a . Goods_Code , a . Employee_Name
from { 0 } a
left outer join { 1 } b on a . ProductCatalog_ID = b . ProductCatalog_ID and a . Goods_ID = b . Goods_ID and a . Employee_Name = b . Employee_Name
where a . Employee_Name = ' { 2 } ' { 3 } ".FormatWith(
TableNames . 客 户 端 产 品 分 类 明 细 ,
TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
UserBL . CurrentUser . ERP_User_Name ,
isSelected = = true ? "and b.Goods_ID is not null" : string . Empty ) ) ;
if ( table . Rows . Count = = 0 )
if ( table . Rows . Count = = 0 )
return new List < ProCataGoods > ( ) ;
return new List < ProCataGoods > ( ) ;
var list = new List < ProCataGoods > ( ) ;
var list = new List < ProCataGoods > ( ) ;
@ -246,6 +261,7 @@ namespace WeighBusiness.BL
catalog . SecondUnitRatio = DataTypeUtil . GetDecimalNullNum ( row [ 7 ] ) ;
catalog . SecondUnitRatio = DataTypeUtil . GetDecimalNullNum ( row [ 7 ] ) ;
catalog . Goods_Spec = DataTypeUtil . ToStringEmptyIfNull ( row [ 8 ] ) ;
catalog . Goods_Spec = DataTypeUtil . ToStringEmptyIfNull ( row [ 8 ] ) ;
catalog . Goods_Code = DataTypeUtil . ToStringEmptyIfNull ( row [ 9 ] ) ;
catalog . Goods_Code = DataTypeUtil . ToStringEmptyIfNull ( row [ 9 ] ) ;
catalog . Employee_Name = DataTypeUtil . ToStringEmptyIfNull ( row [ 1 0 ] ) ;
list . Add ( catalog ) ;
list . Add ( catalog ) ;
}
}
return list ;
return list ;
@ -261,8 +277,8 @@ namespace WeighBusiness.BL
if ( selectedList . Count ( ) > 0 ) {
if ( selectedList . Count ( ) > 0 ) {
foreach ( var catalogDetail in selectedList ) {
foreach ( var catalogDetail in selectedList ) {
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
new string [ ] { "ProductCatalog_ID" , "Goods_ID" } ,
new string [ ] { catalogDetail . ProductCatalog_ID . ToString ( ) , catalogDetail . Goods_ID . ToString ( ) } ) ;
new string [ ] { "ProductCatalog_ID" , "Goods_ID" , "Employee_Name" } ,
new string [ ] { catalogDetail . ProductCatalog_ID . ToString ( ) , catalogDetail . Goods_ID . ToString ( ) , catalogDetail . Employee_Name ? ? string . Empty } ) ;
she . ExecuteNonQuery ( insertSql , out success ) ;
she . ExecuteNonQuery ( insertSql , out success ) ;
if ( ! success )
if ( ! success )
she . Rollback ( ) ;
she . Rollback ( ) ;
@ -283,8 +299,9 @@ namespace WeighBusiness.BL
foreach ( DataRow row in table . Rows )
foreach ( DataRow row in table . Rows )
{
{
var catalog = new ProductCatalog ( ) ;
var catalog = new ProductCatalog ( ) ;
catalog . ProductCatalog_ID = int . Parse ( row [ 0 ] . ToString ( ) ) ;
catalog . ProductCatalog_ID = int . Parse ( row [ 0 ] . ToString ( ) ) ;
catalog . Sequence = DataTypeUtil . GetIntNullNum ( row [ 1 ] ) ;
catalog . Sequence = DataTypeUtil . GetIntNullNum ( row [ 1 ] ) ;
selectedList . Add ( catalog ) ;
selectedList . Add ( catalog ) ;
}
}
}
}
@ -301,7 +318,11 @@ namespace WeighBusiness.BL
{
{
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 ,
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 ,
new string [ ] { "ProductCatalog_ID" , "Name" , "Sequence" , "RowVersion" } ,
new string [ ] { "ProductCatalog_ID" , "Name" , "Sequence" , "RowVersion" } ,
new string [ ] { catalog . ProductCatalog_ID . ToString ( ) , catalog . ProductCatalog_ID . ToString ( ) , catalog . Sequence = = null ? "null" : catalog . Sequence . ToString ( ) , "0" } ) ;
new string [ ] {
catalog . ProductCatalog_ID . ToString ( ) ,
catalog . ProductCatalog_ID . ToString ( ) ,
catalog . Sequence = = null ? "null" : catalog . Sequence . ToString ( ) , "0" } ) ;
she . ExecuteNonQuery ( insertSql , out success , out errorMessage ) ;
she . ExecuteNonQuery ( insertSql , out success , out errorMessage ) ;
if ( ! success )
if ( ! success )
{
{
@ -324,8 +345,8 @@ namespace WeighBusiness.BL
foreach ( var catalogDetail in goodslist )
foreach ( var catalogDetail in goodslist )
{
{
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
new string [ ] { "ProductCatalog_ID" , "Goods_ID" } ,
new string [ ] { catalogDetail . ProductCatalog_ID . ToString ( ) , catalogDetail . Goods_ID . ToString ( ) } ) ;
new string [ ] { "ProductCatalog_ID" , "Goods_ID" , "Employee_Name" } ,
new string [ ] { catalogDetail . ProductCatalog_ID . ToString ( ) , catalogDetail . Goods_ID . ToString ( ) , catalogDetail . Employee_Name ? ? string . Empty } ) ;
she . ExecuteNonQuery ( insertSql , out success ) ;
she . ExecuteNonQuery ( insertSql , out success ) ;
if ( ! success )
if ( ! success )
she . Rollback ( ) ;
she . Rollback ( ) ;
@ -342,16 +363,17 @@ namespace WeighBusiness.BL
{
{
var selectedList = new List < ProCataGoods > ( ) ;
var selectedList = new List < ProCataGoods > ( ) ;
var table = SqlHelperEx . DoQuery ( "select ProductCatalog_ID, Goods_ID from {0} b " . FormatWith ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ) , TableNames . 数 据 库 _backup ) ;
var table = SqlHelperEx . DoQuery ( "select ProductCatalog_ID, Goods_ID, Employee_Name from {0} b " . FormatWith ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ) , TableNames . 数 据 库 _backup ) ;
if ( table . Rows . Count > 0 )
if ( table . Rows . Count > 0 )
{
{
foreach ( DataRow row in table . Rows )
foreach ( DataRow row in table . Rows )
{
{
var catalog = new ProCataGoods ( ) ;
var catalog = new ProCataGoods ( ) ;
catalog . ProductCatalog_ID = int . Parse ( row [ 0 ] . ToString ( ) ) ;
catalog . Goods_ID = int . Parse ( row [ 1 ] . ToString ( ) ) ;
catalog . ProductCatalog_ID = int . Parse ( row [ 0 ] . ToString ( ) ) ;
catalog . Goods_ID = int . Parse ( row [ 1 ] . ToString ( ) ) ;
catalog . Employee_Name = DataTypeUtil . ToStringEmptyIfNull ( row [ 2 ] ) ;
selectedList . Add ( catalog ) ;
selectedList . Add ( catalog ) ;
}
}
}
}
var selectedList2 = new List < ProductCatalog > ( ) ;
var selectedList2 = new List < ProductCatalog > ( ) ;
@ -379,8 +401,8 @@ namespace WeighBusiness.BL
foreach ( var catalogDetail in selectedList )
foreach ( var catalogDetail in selectedList )
{
{
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
string insertSql = InsertUtil . GetInsertSql ( TableNames . 客 户 端 产 品 分 类 配 制 存 货 ,
new string [ ] { "ProductCatalog_ID" , "Goods_ID" } ,
new string [ ] { catalogDetail . ProductCatalog_ID . ToString ( ) , catalogDetail . Goods_ID . ToString ( ) } ) ;
new string [ ] { "ProductCatalog_ID" , "Goods_ID" , "Employee_Name" } ,
new string [ ] { catalogDetail . ProductCatalog_ID . ToString ( ) , catalogDetail . Goods_ID . ToString ( ) , catalogDetail . Employee_Name ? ? string . Empty } ) ;
she . ExecuteNonQuery ( insertSql , out success ) ;
she . ExecuteNonQuery ( insertSql , out success ) ;
if ( ! success )
if ( ! success )
she . Rollback ( ) ;
she . Rollback ( ) ;
@ -431,6 +453,7 @@ namespace WeighBusiness.BL
public long CatalogDetail_ID { get ; set ; }
public long CatalogDetail_ID { get ; set ; }
public string Goods_Name { get ; set ; }
public string Goods_Name { get ; set ; }
public string Goods_Code { get ; set ; }
public string Goods_Code { get ; set ; }
public string Employee_Name { get ; set ; }
public string Goods_Spec { get ; set ; }
public string Goods_Spec { get ; set ; }
public long Goods_ID { get ; set ; }
public long Goods_ID { get ; set ; }
public string UnitConvertDirection { get ; set ; }
public string UnitConvertDirection { get ; set ; }