2023-05-23 16:13:17 +08:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Text ;
using System.Linq ;
using System.Windows.Forms ;
using DevExpress.XtraBars ;
using DevExpress.XtraGrid.Views.Base ;
//using DeiNiu.wms.Logical;
using DeiNiu.wms.Data ;
using DevExpress.XtraGrid.Columns ;
using System.Threading ;
using DevExpress.XtraGrid.Views.Grid ;
using DevExpress.XtraEditors.DXErrorProvider ;
using DeiNiu.wms.Data.Model ;
using DevExpress.XtraEditors ;
using DevExpress.XtraEditors.Controls ;
using DeiNiu.Utils ;
using DeiNiu.wms.win.ServiceReferenceGoods ;
using System.ServiceModel ;
using WcfClientAuthentication ;
using DeiNiu.wms.win.ServiceReferenceLot ;
namespace DeiNiu.wms.win
{
public partial class GoodsForm : BasicRibbonForm
{
ServiceReferenceGoods . WcfWmsGoods wgoods = new ServiceReferenceGoods . WcfWmsGoods ( ) ;
// lWmsGoods lgt = new lWmsGoods();
private string fieldName = WmsLocation . fields . locationId . ToString ( ) ;
private string fieldGoodType = WmsLocation . fields . whGoodsType . ToString ( ) ;
private string lastQuery = "" ;
//private DataTable dt;
private int selectedRowIndex = - 1 ;
List < WmsGoods > selectedGoods ;
private bool isAdding = true ;
private Structs locs ;
private decimal length , width , height , weight , storeHigh , storeLow = 0 m ;
public GoodsForm ( )
{
InitializeComponent ( ) ;
2023-12-03 22:13:49 +08:00
try
{
initialControls ( ) ;
}
catch ( Exception er )
{
showErrorMsg ( er ) ;
}
2023-05-23 16:13:17 +08:00
// loadData();
}
#region initialControls
private void initialControls ( )
{
2023-12-03 22:13:49 +08:00
2023-05-23 16:13:17 +08:00
initialComboBoxes ( ) ;
initialPagerControls ( ) ;
initialDataGrid ( ) ;
initialQueryInput ( ) ;
setValidationRule ( ) ;
this . lcgSetup . Expanded = false ;
}
private void initialComboBoxes ( )
{
2023-09-04 22:41:19 +08:00
comSeedsQ . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
comSeeds . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
2023-11-21 19:18:23 +08:00
comZhitongQ . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
this . comBzhitong . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
2023-05-23 16:13:17 +08:00
//initial comboboxedits with dic
Node [ ] nds = { } ;
DataTable dt = Park . getDictionary ( false ) ;
if ( dt . Rows . Count = = 0 )
{
return ;
}
DataRow [ ] drs = dt . Select ( "flag >0" ) ;
foreach ( DataRow dr in drs )
{
int flag = Convert . ToInt32 ( dr [ "flag" ] . ToString ( ) ) ;
int parentId = Convert . ToInt32 ( dr [ "id" ] . ToString ( ) ) ;
DataRow [ ] drss = Park . getDictionary ( false ) . Select ( "parentId =" + parentId ) ;
switch ( flag )
{
case 1001 :
initialComboBoxs ( this . comGoodType , drss , false ) ; //商品类型
initialComboBoxs ( this . comboGoodsTypeQuery , drss ) ; //商品类型
break ;
2023-09-04 22:41:19 +08:00
case 2001 :
initialComboBoxs ( this . comWarehouse , drss , false ) ; //库房
initialComboBoxs ( this . comWarehouseQuery , drss ) ; //库房
break ;
2023-05-23 16:13:17 +08:00
case 2009 :
initialComboBoxs ( this . comboRepType , drss , false ) ; //补货策略
initialComboBoxs ( this . comboRepQuery , drss ) ; //补货策略
break ;
case 2014 :
initialComboBoxs ( this . comABC , drss , true ) ; //abc
initialComboBoxs ( this . comABCQ , drss ) ; //abc
break ;
}
}
Dictionary < int , string > lots = new Dictionary < int , string > ( ) ;
using ( LotServiceClient goodClient = new LotServiceClient ( "BasicHttpBinding_ILotService" ,
buildSvrAddress ( "LotService.svc" ) ) )
{
dt = goodClient . queryLots ( "" , 1 , 100 ) . Tables [ 0 ] ;
foreach ( DataRow dr in dt . Rows )
{
Lot lot = new Lot ( dr ) ;
lots . Add ( lot . ID , lot . lotName ) ;
}
}
initialComboBoxs ( comLotQ , lots , true ) ;
initialComboBoxs ( comLots , lots , true ) ;
}
private void setValidationRule ( )
{
// dxValidationProvider.SetValidationRule(comWarehouse, ValidationRules.notEmptyValidationRule);
//txtGoodType.Properties.MaxLength = 40;
//txtGoodDesc.Properties.MaxLength = 250;
//textEdit1.Properties.MaxLength = txtGoodType.Properties.MaxLength;
}
private void initialQueryInput ( )
{
}
private void initialDataGridColumns ( GridView gv )
{
setupGridView ( gridView1 , true ) ;
// gridviewGoodsType.PopulateColumns();
gv . Columns . Clear ( ) ;
// gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]);
GridColumn myCol0 = new GridColumn ( ) { Caption = "ID" , Visible = true , FieldName = "id" } ;
myCol0 . Visible = false ;
gv . Columns . Add ( myCol0 ) ;
// GridColumn colChk = new GridColumn() { Caption = CheckBoxField, Visible = true, FieldName = CheckBoxField };
GridColumn myCol1 = new GridColumn ( ) { Caption = "商品编码" , Visible = true , FieldName = WmsGoods . fields . goodsId . ToString ( ) } ;
GridColumn myCol2 = new GridColumn ( ) { Caption = "商品名称" , Visible = true , FieldName = WmsGoods . exfields . goodsName . ToString ( ) } ;
GridColumn myCol3 = new GridColumn ( ) { Caption = "厂家" , Visible = true , FieldName = WmsGoods . exfields . manufacturer . ToString ( ) } ;
2024-02-06 19:36:47 +08:00
GridColumn myCol4 = new GridColumn ( ) { Caption = "规格" , Visible = true , FieldName = WmsGoods . exfields . spec . ToString ( ) , MaxWidth = 220 } ;
GridColumn myCol5 = new GridColumn ( ) { Caption = "库存单位" , Visible = true , FieldName = WmsGoods . exfields . unit . ToString ( ) } ;
GridColumn myCol6 = new GridColumn ( ) { Caption = "包装数量" , Visible = true , FieldName = WmsGoods . exfields . bigCount . ToString ( ) } ;
2023-05-23 16:13:17 +08:00
GridColumn myCol7 = new GridColumn ( ) { Caption = "剂型" , Visible = true , FieldName = WmsGoods . exfields . type . ToString ( ) } ;
GridColumn myCol8 = new GridColumn ( ) { Caption = "商品类型" , Visible = true , FieldName = WmsGoods . exfields . goodsTypeName . ToString ( ) } ;
2024-02-06 19:36:47 +08:00
GridColumn myCol9 = new GridColumn ( ) { Caption = "零库库容" , Visible = true , FieldName = WmsGoods . fields . bulkMax . ToString ( ) } ;
GridColumn myCol91 = new GridColumn ( ) { Caption = "周转库容" , Visible = true , FieldName = WmsGoods . fields . full_max . ToString ( ) } ;
2023-05-23 16:13:17 +08:00
GridColumn myCol10 = new GridColumn ( ) { Caption = "小整" , Visible = true , FieldName = WmsGoods . fields . batchMax1 . ToString ( ) } ;
GridColumn myCol11 = new GridColumn ( ) { Caption = "大整" , Visible = true , FieldName = WmsGoods . fields . batchMax2 . ToString ( ) } ;
GridColumn myCol12 = new GridColumn ( ) { Caption = "国药准字" , Visible = true , FieldName = WmsGoods . exfields . regeditCode . ToString ( ) } ;
GridColumn myCol13 = new GridColumn ( ) { Caption = "拼音简码" , Visible = true , FieldName = "pinYin" } ;
GridColumn myCol14 = new GridColumn ( ) { Caption = "补货策略" , Visible = true , FieldName = WmsGoods . exfields . repTypeName . ToString ( ) } ;
GridColumn myCol15 = new GridColumn ( ) { Caption = "长mm" , Visible = true , FieldName = WmsGoods . fields . length . ToString ( ) } ;
GridColumn myCol16 = new GridColumn ( ) { Caption = "宽mm" , Visible = true , FieldName = WmsGoods . fields . width . ToString ( ) } ;
GridColumn myCol17 = new GridColumn ( ) { Caption = "高mm" , Visible = true , FieldName = WmsGoods . fields . height . ToString ( ) } ;
GridColumn myCol18 = new GridColumn ( ) { Caption = "重g" , Visible = true , FieldName = WmsGoods . fields . weight . ToString ( ) } ;
2024-02-06 19:36:47 +08:00
GridColumn myCol19 = new GridColumn ( ) { Caption = "ABC分区" , Visible = true , FieldName = "goodsABC" } ;
2023-05-23 16:13:17 +08:00
GridColumn myCol20 = new GridColumn ( ) { Caption = "低预警" , Visible = true , FieldName = WmsGoods . fields . lowStore . ToString ( ) } ;
GridColumn myCol21 = new GridColumn ( ) { Caption = "高预警" , Visible = true , FieldName = WmsGoods . fields . highStore . ToString ( ) } ;
GridColumn myCol22 = new GridColumn ( ) { Caption = "条码" , Visible = true , FieldName = "barCode" } ;
GridColumn myCol23 = new GridColumn ( ) { Caption = "货主" , Visible = true , FieldName = "ownerName" , MaxWidth = 120 } ;
2023-09-04 22:41:19 +08:00
GridColumn myCol24 = new GridColumn ( ) { Caption = "批次属性" , Visible = true , FieldName = "lotName" } ;
// GridColumn myCol24 = new GridColumn() { Caption = "商品批次属性", Visible = true, FieldName = "prodLotName" };
// GridColumn myCol25 = new GridColumn() { Caption = "货主批次属性", Visible = true, FieldName = "ownerLotName" };
2023-05-23 16:13:17 +08:00
GridColumn myCol26 = new GridColumn ( ) { Caption = "质保天数" , Visible = true , FieldName = "expiryDays" } ;
GridColumn myCol27 = new GridColumn ( ) { Caption = "价格" , Visible = true , FieldName = "price" } ;
GridColumn myCol28 = new GridColumn ( ) { Caption = "直通商品" , Visible = true , FieldName = "isZhitong" } ;
GridColumn myCol29 = new GridColumn ( ) { Caption = "收货验收" , Visible = true , FieldName = "isQc" } ;
2023-11-21 19:18:23 +08:00
GridColumn myCol30 = new GridColumn ( ) { Caption = "售卖单位" , Visible = true , FieldName = "minOperateUnit" } ;
GridColumn myCol301 = new GridColumn ( ) { Caption = "最少售卖" , Visible = true , FieldName = "minOperateCount" } ;
2023-05-23 16:13:17 +08:00
GridColumn myCol31 = new GridColumn ( ) { Caption = "温控" , Visible = true , FieldName = "tempRequired" } ;
GridColumn myCol32 = new GridColumn ( ) { Caption = "冷链温度" , Visible = true , FieldName = "temperature" } ;
2024-02-06 19:36:47 +08:00
GridColumn myCol33 = new GridColumn ( ) { Caption = "存储货区" , Visible = true , FieldName = "warehouse" } ;
2023-09-04 22:41:19 +08:00
GridColumn myCol34 = new GridColumn ( ) { Caption = "可取总分播" , Visible = true , FieldName = WmsGoods . fields . canSeedOut . ToString ( ) } ;
2023-11-21 19:18:23 +08:00
GridColumn myCol35 = new GridColumn ( ) { Caption = "可直通分拣" , Visible = true , FieldName = WmsGoods . fields . canZhitong . ToString ( ) } ;
2023-09-04 22:41:19 +08:00
2023-05-23 16:13:17 +08:00
if ( gv = = gridView2 )
{
GridColumn col1 = new GridColumn ( ) { Caption = "包装数量" , Visible = true , FieldName = "packingQty" } ;
GridColumn col2 = new GridColumn ( ) { Caption = "包装条码" , Visible = true , FieldName = "packBarcode" } ;
GridColumn col3 = new GridColumn ( ) { Caption = "单位" , Visible = true , FieldName = "packingUnit" } ;
gv . Columns . Add ( myCol2 ) ;
gv . Columns . Add ( col2 ) ;
gv . Columns . Add ( col1 ) ;
gv . Columns . Add ( col3 ) ;
}
else
{
gv . Columns . Add ( colChk ) ;
2024-02-06 19:36:47 +08:00
2023-05-23 16:13:17 +08:00
gv . Columns . Add ( myCol2 ) ;
2024-02-06 19:36:47 +08:00
gv . Columns . Add ( myCol4 ) ;
gv . Columns . Add ( myCol26 ) ;
2023-09-04 22:41:19 +08:00
gv . Columns . Add ( myCol33 ) ;
2024-02-06 19:36:47 +08:00
gv . Columns . Add ( myCol19 ) ;
gv . Columns . Add ( myCol6 ) ;
gv . Columns . Add ( myCol9 ) ;
gv . Columns . Add ( myCol91 ) ;
// gv.Columns.Add(myCol35);
gv . Columns . Add ( myCol5 ) ;
gv . Columns . Add ( myCol30 ) ;
gv . Columns . Add ( myCol301 ) ;
gv . Columns . Add ( myCol8 ) ;
2023-05-23 16:13:17 +08:00
gv . Columns . Add ( myCol22 ) ;
gv . Columns . Add ( myCol28 ) ;
2024-02-06 19:36:47 +08:00
//gv.Columns.Add(myCol29);
2023-05-23 16:13:17 +08:00
gv . Columns . Add ( myCol7 ) ;
gv . Columns . Add ( myCol12 ) ;
gv . Columns . Add ( myCol3 ) ;
gv . Columns . Add ( myCol1 ) ;
gv . Columns . Add ( myCol13 ) ;
2024-02-06 19:36:47 +08:00
gv . Columns . Add ( myCol14 ) ;
2023-05-23 16:13:17 +08:00
gv . Columns . Add ( myCol15 ) ;
gv . Columns . Add ( myCol16 ) ;
gv . Columns . Add ( myCol17 ) ;
gv . Columns . Add ( myCol18 ) ;
gv . Columns . Add ( myCol20 ) ;
gv . Columns . Add ( myCol21 ) ;
2023-09-04 22:41:19 +08:00
gv . Columns . Add ( myCol24 ) ;
2024-02-06 19:36:47 +08:00
gv . Columns . Add ( myCol34 ) ;
2023-05-23 16:13:17 +08:00
gv . Columns . Add ( myCol27 ) ;
gv . Columns . Add ( myCol31 ) ;
gv . Columns . Add ( myCol32 ) ;
//to show bottom scroll bar
2024-02-06 19:36:47 +08:00
gv . Columns . Add ( myCol10 ) ;
gv . Columns . Add ( myCol11 ) ;
2023-05-23 16:13:17 +08:00
}
gv . OptionsView . ColumnAutoWidth = false ;
gv . BestFitColumns ( ) ;
gv . Focus ( ) ;
//自动列宽
//gridView1.OptionsView.ColumnAutoWidth = false;
//this.gridView1.BestFitColumns();
//this.gridView1.Columns[2].MinWidth = 500;
//this.gridView1.Columns[1].BestFit();
//for (int I = 0; I < gridView1.Columns.Count; I++)
//{
// this.gridView1.Columns[I].BestFit()
//}
}
#endregion
/// <summary>
/// loading data
/// </summary>
private int loadData ( )
{
//this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView;
showWaitForm ( ) ;
try
{
//goodClient.syncGoods();
// closeClient();
// this.splashScreenManager1.ShowWaitForm();
string query = ( this . comboGoodsTypeQuery . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , WmsGoods . fields . goodsType . ToString ( ) , ( ( Node ) this . comboGoodsTypeQuery . SelectedItem ) . ID ) )
+ ( this . comboRepQuery . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , WmsGoods . fields . repType . ToString ( ) , ( ( Node ) this . comboRepQuery . SelectedItem ) . ID ) )
+ ( this . txtGoodId . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} =#'{1}';" , WmsGoods . fields . goodsId . ToString ( ) , filtRiskChar ( txtGoodId . Text . Trim ( ) ) ) )
+ ( this . txtRegcode . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . regeditCode . ToString ( ) , filtRiskChar ( txtRegcode . Text . Trim ( ) ) ) )
+ ( this . txtGoodName . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . goodsName . ToString ( ) , filtRiskChar ( txtGoodName . Text . Trim ( ) ) ) )
+ ( this . txtBarcode . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . barcode . ToString ( ) , filtRiskChar ( txtBarcode . Text . Trim ( ) ) ) )
+ ( this . txtType . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . type . ToString ( ) , filtRiskChar ( txtType . Text . Trim ( ) ) ) )
+ ( this . txtpinyin . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . pinYin . ToString ( ) , filtRiskChar ( txtpinyin . Text . Trim ( ) ) ) )
+ ( this . txtStockCondition . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . station . ToString ( ) , filtRiskChar ( txtStockCondition . Text . Trim ( ) ) ) )
+ ( this . txtManufacturer . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . manufacturer . ToString ( ) , filtRiskChar ( txtManufacturer . Text . Trim ( ) ) ) )
+ ( this . comABCQ . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , WmsGoods . fields . ABC . ToString ( ) , ( ( Node ) this . comABCQ . SelectedItem ) . ID ) )
+ ( this . comLotQ . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , "lotId" , ( ( Colitem ) comLotQ . SelectedItem ) . key ) )
2023-09-04 22:41:19 +08:00
+ ( this . comWarehouseQuery . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , WmsGoods . fields . part . ToString ( ) , ( ( Node ) this . comWarehouseQuery . SelectedItem ) . ID ) )
+ ( this . comSeedsQ . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , WmsGoods . fields . canSeedOut . ToString ( ) , comSeedsQ . SelectedIndex = = 1 ? 1 : 0 ) )
2023-11-21 19:18:23 +08:00
+ ( this . comZhitongQ . SelectedIndex < = 0 ? "" : string . Format ( "{0} = #{1};" , WmsGoods . fields . canZhitong . ToString ( ) , comZhitongQ . SelectedIndex = = 1 ? 1 : 0 ) )
2023-05-23 16:13:17 +08:00
;
this . pager1 . PageCurrent = lastQuery . Equals ( query ) ? this . pager1 . PageCurrent : 1 ; //根据查询条件的变化给pager赋值
int start = ( pager1 . PageSize * ( pager1 . PageCurrent - 1 ) + 1 ) ;
int end = ( pager1 . PageSize * pager1 . PageCurrent ) ;
lastQuery = query ;
DataSet ds = goodClient . Query ( query , start , end ) ;
closeClient ( ) ;
DtGv = ds . Tables [ 0 ] ;
addCheckField ( DtGv ) ; //add checkbox
int cnt = Convert . ToInt32 ( ds . Tables [ 1 ] . Rows [ 0 ] [ 0 ] . ToString ( ) ) ;
//dt = lgt.Query(query, start, end); //string.IsNullOrEmpty(query) ? lgt.GetGoodType.getAllData(start, end) : lgt.g;
DtGv . PrimaryKey = new DataColumn [ ] { DtGv . Columns [ "ID" ] } ;
this . gridControl1 . DataSource = DtGv . DefaultView ;
//update selected row index to the last updated one.
if ( goods . ID > 0 )
{
DataRow dr = DtGv . Rows . Find ( goods . ID ) ;
if ( dr ! = null )
{
selectedRowIndex = DtGv . Rows . IndexOf ( dr ) ;
}
if ( selectedRowIndex > 0 & & DtGv . Rows . Count > selectedRowIndex )
{
// gridView1.SelectRow(selectedRowIndex);
gridView1 . FocusedRowHandle = selectedRowIndex ;
// gridView1.MakeRowVisible(selectedRowIndex);
}
//gridView1.FocusedRowHandle = selectedRowIndex;
}
setCurrentRequestDetail ( ) ;
closeWaitForm ( ) ;
return cnt ; // lgt.getRowCount(query);
// return lgt.GetGoodType.QueryCount();
}
catch ( Exception er )
{
closeWaitForm ( ) ;
showErrorMsg ( er . Message ) ;
}
return 0 ;
}
private void setCurrentRequestDetail ( )
{
this . gridControl2 . DataSource = null ;
if ( ! getCurrentObject ( ) | | goods . ID = = 0 )
{
return ;
}
/// gridView1.FocusedRowHandle = selectedRowIndex;//
// gridView1.SelectRow(selectedRowIndex);
showWaitForm ( ) ;
try
{
DataTable dtPacking = goodClient . QueryPacking ( goods . goodsId ) ;
closeClient ( ) ;
this . gridControl2 . DataSource = dtPacking ;
initialDataGridColumns ( this . gridView2 ) ;
}
catch ( Exception e )
{
showErrorMsg ( e . Message ) ;
}
finally
{
closeClient ( ) ;
}
closeWaitForm ( ) ;
}
string lastSelected = "" ;
private bool getCurrentObject ( )
{
if ( selectedRowIndex < 0 | | selectedRowIndex > = DtGv . Rows . Count )
{
return false ;
}
// DataRow currentRow = dt.Rows[selectedRowIndex];
DataRowView dr = ( DataRowView ) ( GetGridViewFilteredAndSortedData ( gridView1 ) [ selectedRowIndex ] ) ;
goods = new WmsGoods ( dr . Row ) ;
lastSelected = goods = = null ? "" : goods . goodsId ;
return true ;
}
private void bindDetail ( )
{
}
private void setDataBack ( )
{
}
private bool validData ( )
{
bool isvalid = dxValidationProvider1 . Validate ( ) ;
// MessageBox.Show("goodtype is " + txtGoodType.Text +", is valid ? " + isvalid);
return isvalid ;
//String gdtype = txtGoodType.Text.Trim();
//if (gdtype.Length == 0)
//{
// dxValidationProvider.Validate();
// return false;
//}
//return true;
}
/// <summary>
/// 分页控件产生的事件
/// </summary>
private int pager_EventPaging ( DeiNiu . Controls . pager . EventPagingArg e )
{
selectedRowIndex = 0 ; //reset currentRowIndex
return loadData ( ) ;
}
private void initialPagerControls ( )
{
pager1 . MaximumSize = new Size ( 0 , 20 ) ;
pager1 . EventPaging + = new DeiNiu . Controls . pager . EventPagingHandler ( pager_EventPaging ) ;
#region DataGridView与Pager控件绑定
this . pager1 . PageCurrent = 1 ; //当前页为第一页
pager1 . PageSize = Utils . WmsConstants . PAGER_SIZE ; //每页行数
this . pager1 . Bind ( ) ; //绑定
#endregion
}
private void initialDataGrid ( )
{
gridView1 . OptionsSelection . MultiSelect = true ; //按shift / control 多选
this . gridView1 . OptionsBehavior . AutoPopulateColumns = false ;
this . gridView1 . FocusRectStyle = DevExpress . XtraGrid . Views . Grid . DrawFocusRectStyle . RowFocus ;
this . gridView1 . OptionsBehavior . Editable = false ;
this . gridView1 . OptionsSelection . EnableAppearanceFocusedCell = false ;
this . gridView1 . FocusedRowObjectChanged + = new DevExpress . XtraGrid . Views . Base . FocusedRowObjectChangedEventHandler ( this . gridView1_FocusedRowObjectChanged ) ;
this . gridView1 . DataSourceChanged + = new System . EventHandler ( this . gridView1_DataSourceChanged ) ;
// gridView1.CustomColumnDisplayText += gridView1_CustomColumnDisplayText;
//show line number
this . gridView1 . IndicatorWidth = 40 ;
this . gridView1 . CustomDrawRowIndicator + = new DevExpress . XtraGrid . Views . Grid . RowIndicatorCustomDrawEventHandler ( gridView1_CustomDrawRowIndicator ) ;
initialDataGridColumns ( this . gridView1 ) ;
GridCheckEdit ( gridView1 , CheckBoxField , 50 ) ;
}
//显示行的序号
private void gridView1_CustomDrawRowIndicator ( object sender , RowIndicatorCustomDrawEventArgs e )
{
if ( e . Info . IsRowIndicator & & e . RowHandle > = 0 )
{
e . Info . DisplayText = ( e . RowHandle + 1 ) . ToString ( ) ;
}
}
bool isCheckedIn = false ;
private void gridView1_FocusedRowObjectChanged ( object sender , FocusedRowObjectChangedEventArgs e )
{
if ( gridView1 . FocusedRowHandle < 0 | | gridView1 . FocusedRowHandle = = selectedRowIndex | | gridView1 . FocusedRowHandle = = 0 & & isCheckedIn )
{
isCheckedIn = gridView1 . FocusedRowHandle > 0 ;
if ( gridView1 . IsGroupRow ( e . RowHandle ) ) //set first row of group selected
{
selectedRowIndex = gridView1 . GetChildRowHandle ( e . RowHandle , 0 ) ;
setCurrentRequestDetail ( ) ;
}
if ( isCheckedIn )
{
isCheckedIn = false ;
}
return ;
}
selectedRowIndex = gridView1 . FocusedRowHandle ;
// showErrorMsg("selection:"+ selectedRowIndex);
setCurrentRequestDetail ( ) ;
}
private void clearInputs ( )
{
}
private void gridView1_CustomColumnDisplayText ( object sender , DevExpress . XtraGrid . Views . Base . CustomColumnDisplayTextEventArgs e )
{
int display = - 100 ;
if ( e . Column . FieldName = = "repType" )
{
if ( ! stockState . ContainsValue ( e . DisplayText ) )
{
try
{
display = Convert . ToInt16 ( e . DisplayText ) ;
e . DisplayText = stockState [ display ] ;
}
catch
{
return ;
}
}
} else
if ( e . Column . FieldName = = "isQc" | | e . Column . FieldName = = "isZhitong" )
{
try
{
display = Convert . ToInt16 ( e . DisplayText ) ;
if ( display = = 0 )
{
e . DisplayText = "否" ;
}
else
{
e . DisplayText = "是" ;
}
}
catch
{
return ;
}
}
}
private void gridView1_FocusedRowChanged ( object sender , FocusedRowChangedEventArgs e )
{
}
private void gridView1_DataSourceChanged ( object sender , EventArgs e )
{
if ( selectedRowIndex > 0 & & DtGv . Rows . Count > selectedRowIndex )
{
gridView1 . FocusedRowHandle = selectedRowIndex ;
gridView1 . MakeRowVisible ( selectedRowIndex ) ;
}
}
private void btnDelete_Click ( object sender , EventArgs e )
{
}
protected void query ( )
{
pager1 . Bind ( ) ;
}
private void queryGoods ( )
{
showWaitForm ( ) ;
try
{
query ( ) ; // loadData();
}
catch ( Exception e )
{
showErrorMsg ( e , e . Message ) ;
}
finally
{
// WaitFormService.Close();
closeWaitForm ( ) ;
bbQuery . Enabled = true ;
}
}
private void bbQuery_ItemClick_1 ( object sender , ItemClickEventArgs e )
{
this . bbQuery . Enabled = false ;
queryGoods ( ) ;
}
private void updateObjects ( List < WmsGoods > goods )
{
showWaitForm ( ) ;
//WaitFormService.Show(this);
try
{
List < WcfWmsGoods > wgoods = new List < WcfWmsGoods > ( ) ;
foreach ( WmsGoods wg in goods )
{
wgoods . Add ( getWcfObject ( wg ) ) ;
}
WcfWmsGoods [ ] wcfgoods = wgoods . ToArray ( ) ;
goodClient . update ( wcfgoods ) ;
closeClient ( ) ;
// lgt.update(wgoods);
//get updated data
query ( ) ;
}
catch ( Exception e )
{
showErrorMsg ( e , e . Message ) ;
}
finally
{
// WaitFormService.Close();
closeWaitForm ( ) ;
}
}
WmsGoods goods = new WmsGoods ( ) ;
private bool getCurrentObjects_old ( )
{
int [ ] selectedRows = gridView1 . GetSelectedRows ( ) ;
selectedGoods = new List < WmsGoods > ( ) ;
foreach ( int i in selectedRows )
{
goods = new WmsGoods ( DtGv . Rows [ i ] ) ;
selectedGoods . Add ( goods ) ;
}
if ( selectedRows . Length = = 0 )
{
showErrorMsg ( null , "请至少选择一个商品条目" ) ;
return false ;
}
return true ;
}
private bool getCurrentObjects ( )
{
selectedGoods = new List < WmsGoods > ( ) ;
foreach ( DataRow dr in DtGv . Rows )
{
string v = dr [ CheckBoxField ] . ToString ( ) ;
bool b = String . IsNullOrEmpty ( v ) ? false : Convert . ToBoolean ( v ) ;
if ( b )
{
goods = new WmsGoods ( dr ) ;
selectedGoods . Add ( goods ) ;
}
}
if ( selectedGoods . Count = = 0 )
{
showErrorMsg ( null , "请至少选择一个商品条目" ) ;
return false ;
}
return true ;
}
private void btnUpdateVol_Click ( object sender , EventArgs e )
{
if ( getCurrentObjects ( ) & & setVol ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品容积信息吗?" , selectedGoods . Count ) , "确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private bool setVol ( )
{
if ( ! validData ( ) )
{
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
DataRow currentRow = DtGv . Rows . Find ( good . ID ) ;
string bc = currentRow [ WmsGoods . exfields . bigCount . ToString ( ) ] . ToString ( ) ;
decimal bigcnt = 1 ;
if ( ! string . IsNullOrEmpty ( bc ) )
{
bigcnt = Convert . ToDecimal ( currentRow [ WmsGoods . exfields . bigCount . ToString ( ) ] . ToString ( ) ) ;
}
if ( txtBulkMax . Text . Length > 0 )
{
good . bulkMax = Convert . ToDecimal ( txtBulkMax . Text ) * bigcnt ;
}
if ( txtBatch1Max . Text . Length > 0 )
{
good . batchMax1 = Convert . ToDecimal ( this . txtBatch1Max . Text ) * bigcnt ;
}
if ( txtBatch2Max . Text . Length > 0 )
{
good . batchMax2 = Convert . ToDecimal ( this . txtBatch2Max . Text ) * bigcnt ;
}
// good.operater = Park.currentUser.GetEmployee.ID;
}
}
catch ( Exception er )
{
showErrorMsg ( er . Message ) ;
return false ;
}
return true ;
}
private void btnUpdateGoodType_Click ( object sender , EventArgs e )
{
if ( this . comGoodType . SelectedIndex = = - 1 )
{
showErrorMsg ( "请选择商品类型" ) ;
comGoodType . Focus ( ) ;
return ;
}
if ( getCurrentObjects ( ) & & setGoodType ( ) ) {
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品类型为 '{1}' 吗?" ,
selectedGoods . Count , ( ( Node ) this . comGoodType . SelectedItem ) . name ) ,
"确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private bool setGoodType ( )
{
if ( ! validData ( ) )
{
return false ;
}
if ( this . comGoodType . SelectedIndex = = - 1 )
{
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
good . goodsType = ( ( Node ) this . comGoodType . SelectedItem ) . ID ;
// good.operater = Park.currentUser.GetEmployee.ID;
}
}
catch ( Exception er )
{
showErrorMsg ( er . Message ) ;
return false ;
}
return true ;
}
2023-09-04 22:41:19 +08:00
private bool setGoodWh ( )
{
if ( ! validData ( ) )
{
return false ;
}
if ( this . comWarehouse . SelectedIndex = = - 1 )
{
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
good . part = ( ( Node ) this . comWarehouse . SelectedItem ) . ID ;
// good.operater = Park.currentUser.GetEmployee.ID;
}
}
catch ( Exception er )
{
showErrorMsg ( er . Message ) ;
return false ;
}
return true ;
}
2023-05-23 16:13:17 +08:00
private void bbSaveAll_ItemClick ( object sender , ItemClickEventArgs e )
{
saveAll ( ) ;
}
private void btnQuery_Click ( object sender , EventArgs e )
{
this . query ( ) ;
}
private void btnSaveAll_Click ( object sender , EventArgs e )
{
saveAll ( ) ;
}
private void saveAll ( )
{
try
{
2023-09-04 22:41:19 +08:00
if ( getCurrentObjects ( ) & & setVol ( ) & & setGoodType ( ) & & setRepType ( ) & & setSizeWeight ( ) & & setABC ( ) & & setStoreAlert ( ) & & setGoodWh ( ) & & setSeeds ( ) )
2023-05-23 16:13:17 +08:00
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品类型、容积、尺寸重量、补货等信息吗?" ,
selectedGoods . Count ) , "确认修改" ,
MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
catch ( Exception er )
{
showErrorMsg ( er . Message ) ;
}
}
private void txtpinyin_KeyUp ( object sender , KeyEventArgs e )
{
if ( e . KeyCode = = Keys . Enter )
{
loadData ( ) ;
}
}
WcfWmsGoods getWcfObject ( WmsGoods dbObj )
{
WcfWmsGoods wcfObj = new WcfWmsGoods ( ) ;
wcfObj . ID = dbObj . ID ;
wcfObj . goodsId = dbObj . goodsId ;
wcfObj . goodsType = dbObj . goodsType ;
wcfObj . ownerCode = dbObj . ownerCode ;
wcfObj . plotId = dbObj . plotId ;
wcfObj . part = dbObj . part ;
wcfObj . full_max = dbObj . full_max ;
wcfObj . bulkMax = dbObj . bulkMax ;
wcfObj . bulkMax1 = dbObj . bulkMax1 ;
wcfObj . batchMax1 = dbObj . batchMax1 ;
wcfObj . batchMax2 = dbObj . batchMax2 ;
wcfObj . batchMax3 = dbObj . batchMax3 ;
wcfObj . batchMax4 = dbObj . batchMax4 ;
wcfObj . length = dbObj . length ;
wcfObj . width = dbObj . width ;
wcfObj . height = dbObj . height ;
wcfObj . weight = dbObj . weight ;
wcfObj . validTermDays = dbObj . validTermDays ;
wcfObj . bigCount = dbObj . bigCount ;
wcfObj . repType = dbObj . repType ;
wcfObj . ABC = dbObj . ABC ;
wcfObj . lowStore = dbObj . lowStore ;
wcfObj . highStore = dbObj . highStore ;
wcfObj . operater = dbObj . operater ;
2023-09-04 22:41:19 +08:00
wcfObj . canSeedOut = dbObj . canSeedOut ;
2023-11-21 19:18:23 +08:00
wcfObj . canZhitong = dbObj . canZhitong ;
2023-05-23 16:13:17 +08:00
return wcfObj ;
}
/ *
wcfGoods getWcfGoods ( WmsGoods wg )
{
wcfGoods goods = new wcfGoods ( ) ;
goods . id = wg . ID ;
goods . batchMax1 = wg . batchMax1 ;
goods . batchMax2 = wg . batchMax2 ;
goods . batchMax3 = wg . batchMax3 ;
goods . batchMax4 = wg . batchMax4 ;
goods . bulkMax = wg . bulkMax ;
goods . bulkMax1 = wg . bulkMax1 ;
goods . goodsId = wg . goodsId ;
goods . goodsType = wg . goodsType ;
goods . length = wg . length ;
goods . width = wg . width ;
goods . height = wg . height ;
goods . weight = wg . weight ;
goods . repType = wg . repType ;
goods . bigCount = wg . bigCount ;
// goods.operater = getOperId();
goods . part = wg . part ;
goods . ABC = wg . ABC ;
goods . highStore = wg . highStore ;
goods . lowStore = wg . lowStore ;
// goods.plotId = wg.plotId;
return goods ;
}
* /
private void btnModifyRepType_Click ( object sender , EventArgs e )
{
if ( this . comboRepType . SelectedIndex = = - 1 )
{
showErrorMsg ( "请选择补货策略" ) ;
comboRepType . Focus ( ) ;
return ;
}
if ( getCurrentObjects ( ) & & setRepType ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条补货策略为 '{1}' 吗?" ,
selectedGoods . Count , ( ( Node ) this . comboRepType . SelectedItem ) . name ) ,
"确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private bool setRepType ( )
{
if ( ! validData ( ) )
{
return false ;
}
if ( this . comboRepType . SelectedIndex = = - 1 )
{
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
good . repType = ( ( Node ) this . comboRepType . SelectedItem ) . ID ;
// good.operater = Park.currentUser.GetEmployee.ID;
}
}
catch ( Exception er )
{
showErrorMsg ( er , er . Message ) ;
return false ;
}
return true ;
}
private bool setSizeWeight ( )
{
if ( ! validSize ( ) )
{
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
DataRow currentRow = DtGv . Rows . Find ( good . ID ) ;
good . weight = weight ;
good . height = height ;
good . width = width ;
good . length = length ;
}
}
catch ( Exception er )
{
showErrorMsg ( er . Message ) ;
return false ;
}
return true ;
}
private bool validSize ( )
{
try
{
height = Convert . ToDecimal ( txtHeight . Text . Trim ( ) ) ;
width = Convert . ToDecimal ( txtWidth . Text . Trim ( ) ) ;
length = Convert . ToDecimal ( txtLength . Text . Trim ( ) ) ;
weight = Convert . ToDecimal ( txtWeight . Text . Trim ( ) ) ;
return true ;
}
catch
{
showErrorMsg ( "尺寸或重量设置错误!" ) ;
return false ;
}
}
private void btnUpdateSize_Click ( object sender , EventArgs e )
{
if ( getCurrentObjects ( ) & & setSizeWeight ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品尺寸、重量信息吗?" , selectedGoods . Count ) , "确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private void syncGoods ( )
{
showWaitForm ( "正在同步商品信息" ) ;
try
{
//同步商品信息
//lWmsGoods lg = new lWmsGoods();
//lg.getWmsGoods.syncGoods();
goodClient . syncGoods ( ) ;
goodClient . Close ( ) ;
closeWaitForm ( ) ;
}
catch ( Exception e )
{
LogHelper . WriteLog ( this . GetType ( ) , e ) ;
// showErrorMsg(e.Message);
closeWaitForm ( ) ;
}
}
private void bbiSync_ItemClick ( object sender , ItemClickEventArgs e )
{
syncGoods ( ) ;
}
private void barButtonItem1_ItemClick ( object sender , ItemClickEventArgs e )
{
exportExcel ( gridView1 ) ;
}
bool setABC ( )
{
if ( this . comABC . SelectedIndex = = - 1 )
{
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
2024-02-06 19:36:47 +08:00
good . ABC = this . comABC . SelectedIndex = = 0 ? 0 : ( ( Node ) this . comABC . SelectedItem ) . ID ;
2023-05-23 16:13:17 +08:00
}
}
catch ( Exception er )
{
showErrorMsg ( er , er . Message ) ;
return false ;
}
return true ;
}
2023-11-21 19:18:23 +08:00
bool setZhitong ( )
{
try
{
foreach ( WmsGoods good in selectedGoods )
{
good . canZhitong = comBzhitong . SelectedIndex = = 0 ;
}
}
catch ( Exception er )
{
showErrorMsg ( er , er . Message ) ;
return false ;
}
return true ;
}
2023-09-04 22:41:19 +08:00
private void btnWhUpdate_Click ( object sender , EventArgs e )
{
if ( this . comWarehouse . SelectedIndex = = - 1 )
{
showErrorMsg ( "请选择存储区域" ) ;
comWarehouse . Focus ( ) ;
return ;
}
if ( getCurrentObjects ( ) & & setGoodWh ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品存储区域类型为 '{1}' 吗?" ,
selectedGoods . Count , ( ( Node ) this . comWarehouse . SelectedItem ) . name ) ,
"确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private void btnSeeds_Click ( object sender , EventArgs e )
{
if ( getCurrentObjects ( ) & & setSeeds ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条 取总拣货为 '{1}' 吗?" ,
selectedGoods . Count , comSeeds . Text ) ,
"确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private bool setSeeds ( )
{
try
{
foreach ( WmsGoods good in selectedGoods )
{
good . canSeedOut = comSeeds . SelectedIndex = = 0 ;
}
}
catch ( Exception er )
{
showErrorMsg ( er , er . Message ) ;
return false ;
}
return true ;
}
2023-11-21 19:18:23 +08:00
private void comBzhitong_SelectedIndexChanged ( object sender , EventArgs e )
{
}
private void btnZhitong_Click ( object sender , EventArgs e )
{
if ( getCurrentObjects ( ) & & setZhitong ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条 直通拣货 为 '{1}' 吗?" ,
selectedGoods . Count , comBzhitong . Text ) ,
"确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
2023-05-23 16:13:17 +08:00
private void btnSaveABC_Click ( object sender , EventArgs e )
{
if ( this . comABC . SelectedIndex = = 0 )
{
2024-02-06 19:36:47 +08:00
// showErrorMsg("请选择ABC列表内容");
// comABC.Focus();
// return;
2023-05-23 16:13:17 +08:00
}
if ( getCurrentObjects ( ) & & setABC ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条ABC为 '{1}' 吗?" ,
2024-02-06 19:36:47 +08:00
selectedGoods . Count , this . comABC . SelectedIndex = = 0 ? "无" : ( ( Node ) this . comABC . SelectedItem ) . name ) ,
2023-05-23 16:13:17 +08:00
"确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private void btnStore_Click ( object sender , EventArgs e )
{
if ( getCurrentObjects ( ) & & setStoreAlert ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品库存预警信息吗?" , selectedGoods . Count ) , "确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private bool setStoreAlert ( )
{
try
{
storeHigh = Convert . ToDecimal ( this . txtHighStore . Text . Trim ( ) ) ;
storeLow = Convert . ToDecimal ( this . txtLowStore . Text . Trim ( ) ) ;
if ( storeLow > storeHigh )
{
showErrorMsg ( "低预警库存数量不能大于高预警库存数量" ) ;
return false ;
}
}
catch
{
showErrorMsg ( "库存预警数量设置错误!" ) ;
return false ;
}
try
{
foreach ( WmsGoods good in selectedGoods )
{
DataRow currentRow = DtGv . Rows . Find ( good . ID ) ;
good . lowStore = storeLow ;
good . highStore = storeHigh ;
}
}
catch ( Exception er )
{
showErrorMsg ( er . Message ) ;
return false ;
}
return true ;
}
private void btnSaveLots_Click ( object sender , EventArgs e )
{
if ( getCurrentObjects ( ) & & setLots ( ) )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品批次规则信息吗?" , selectedGoods . Count ) , "确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( r = = DialogResult . Yes )
{
updateObjects ( selectedGoods ) ;
}
}
}
private bool setLots ( )
{
try
{
// if (comLots.SelectedIndex > 0)
{
foreach ( WmsGoods good in selectedGoods )
{
// DataRow currentRow = DtGv.Rows.Find(good.ID);
good . plotId = ( ( Colitem ) comLots . SelectedItem ) . key ;
}
}
}
catch
{
showErrorMsg ( " 批次规则设置错误!" ) ;
return false ;
}
return true ;
}
}
}