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 ;
namespace DeiNiu.wms.win
{
public partial class StockMaintainQueryForm : BasicRibbonForm
{
// lWmsGoods lgt = new lWmsGoods();
private string fieldName = WmsLocation . fields . locationId . ToString ( ) ;
private string fieldGoodType = WmsLocation . fields . whGoodsType . ToString ( ) ;
private string lastQuery = "" ;
private DataTable dtDiffs ;
private DataTable dtDetail ;
private int selectedRowIndex = - 1 ;
private string selectedGoodsId ;
private string selectedBatch ;
private int activeTabIndex = 0 ;
string queryStr = "" ;
public StockMaintainQueryForm ( )
{
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 ( )
{
setDatePiker ( dateEdit1 , dateEdit2 ) ;
layoutControlWaitting . Expanded = true ;
initialComboBoxes ( ) ;
initialPagerControls ( ) ;
initialDataGrid ( ) ;
initialQueryInput ( ) ;
setValidationRule ( ) ;
}
private void initialComboBoxes ( )
{
//initialComboBoxe(comboType, this.stkdiff);
comboType . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
comboType2 . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
comboResult . Properties . TextEditStyle = TextEditStyles . DisableTextEditor ;
this . comboType . SelectedIndex = 0 ;
this . comboType2 . SelectedIndex = 0 ;
this . comboResult . SelectedIndex = 0 ;
// initialComboBoxe(comboResult, this.maintainResult);
//initial comboboxedits with dic
Node [ ] nds = { } ;
DataRow [ ] drs = Park . getDictionary ( true ) . 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 2005 :
initialComboBoxs ( this . comPartQuery , drss ) ; //分区
initialComboBoxs ( this . comPartQ , drss ) ; //分区
break ;
}
}
}
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 ( )
{
2023-09-04 22:41:19 +08:00
textEditDays . Value = ( int ) ( 365 * WmsConstants . IN_STOCK_LEFT_VALID_FACTOR ) ;
2023-05-23 16:13:17 +08:00
}
private void initialDataGridColumns ( GridView gridview )
{
setupGridView ( gridview , true ) ;
// gridviewGoodsType.PopulateColumns();
gridview . Columns . Clear ( ) ;
// gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]);
GridColumn myCol0 = new GridColumn ( ) { Caption = "ID" , Visible = true , FieldName = "id" } ;
myCol0 . Visible = false ;
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 ( ) } ;
GridColumn myCol4 = new GridColumn ( ) { Caption = "规格" , Visible = true , FieldName = WmsGoods . exfields . spec . ToString ( ) } ;
GridColumn myCol5 = new GridColumn ( ) { Caption = "单位" , Visible = true , FieldName = WmsGoods . exfields . unit . ToString ( ) } ;
GridColumn myCol6 = new GridColumn ( ) { Caption = "大包装数量" , Visible = true , FieldName = WmsGoods . exfields . bigCount . ToString ( ) } ;
GridColumn myCol7 = new GridColumn ( ) { Caption = "剂型" , Visible = true , FieldName = WmsGoods . exfields . type . ToString ( ) } ;
GridColumn myCol8 = new GridColumn ( ) { Caption = "商品类型" , Visible = true , FieldName = WmsGoods . exfields . goodsTypeName . ToString ( ) } ;
/ * GridColumn myCol9 = new GridColumn ( ) { Caption = "大零" , Visible = true , FieldName = WmsGoods . fields . bulkMax . ToString ( ) } ;
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 = "batch" } ;
// GridColumn myCol13 = new GridColumn() { Caption = "拼音简码", Visible = true, FiemcldName ="pinYin" };
GridColumn myCol14 = new GridColumn ( ) { Caption = "货位" , Visible = true , FieldName = "locationId" } ;
GridColumn myCol20 = new GridColumn ( ) { Caption = "数量" , Visible = true , FieldName = "avCount" } ;
GridColumn myCol201 = new GridColumn ( ) { Caption = "保养数量" , Visible = true , FieldName = "mcount" } ;
GridColumn myCol2011 = new GridColumn ( ) { Caption = "异常数量" , Visible = true , FieldName = "issueCount" } ;
// GridColumn myCol21 = new GridColumn() { Caption = "养护类别", Visible = true, FieldName = "isDouChk" };
GridColumn myCol10 = new GridColumn ( ) { Caption = "生产日期" , Visible = true , FieldName = WmsStock . fields . productDate . ToString ( ) } ;
GridColumn myCol11 = new GridColumn ( ) { Caption = "有效期" , Visible = true , FieldName = WmsStock . fields . validDate . ToString ( ) } ;
GridColumn myCol111 = new GridColumn ( ) { Caption = "需养护日期" , Visible = true , FieldName = "nextMainTainDate" } ;
GridColumn myCol112 = new GridColumn ( ) { Caption = "养护结果" , Visible = true , FieldName = "issueType" } ;
GridColumn myCol1121 = new GridColumn ( ) { Caption = "养护内容" , Visible = true , FieldName = "details" } ;
GridColumn myCol1122 = new GridColumn ( ) { Caption = "养护人" , Visible = true , FieldName = "em_name" } ;
GridColumn myCol11223 = new GridColumn ( ) { Caption = "货位状态" , Visible = true , FieldName = "state" } ;
GridColumn myCol11224 = new GridColumn ( ) { Caption = "养护时间" , Visible = true , FieldName = "createtime" } ;
if ( activeTabIndex = = 0 )
{
gridview . Columns . Add ( myCol14 ) ;
gridview . Columns . Add ( myCol2 ) ;
gridview . Columns . Add ( myCol12 ) ;
gridview . Columns . Add ( myCol10 ) ;
gridview . Columns . Add ( myCol11 ) ;
gridview . Columns . Add ( myCol111 ) ;
// gridview.Columns.Add(myCol21);
gridview . Columns . Add ( myCol20 ) ;
gridview . Columns . Add ( myCol4 ) ;
// gridview.Columns.Add(myCol0);
gridview . Columns . Add ( myCol1 ) ;
gridview . Columns . Add ( myCol8 ) ;
gridview . Columns . Add ( myCol6 ) ;
gridview . Columns . Add ( myCol3 ) ;
}
else if ( activeTabIndex = = 1 )
{
gridview . Columns . Add ( myCol14 ) ;
gridview . Columns . Add ( myCol2 ) ;
gridview . Columns . Add ( myCol12 ) ;
gridview . Columns . Add ( myCol10 ) ;
gridview . Columns . Add ( myCol11 ) ;
// gridview.Columns.Add(myCol21);
gridview . Columns . Add ( myCol201 ) ;
gridview . Columns . Add ( myCol2011 ) ;
gridview . Columns . Add ( myCol112 ) ;
gridview . Columns . Add ( myCol1121 ) ;
gridview . Columns . Add ( myCol1122 ) ;
gridview . Columns . Add ( myCol11224 ) ;
gridview . Columns . Add ( myCol4 ) ;
// gridview.Columns.Add(myCol0);
gridview . Columns . Add ( myCol1 ) ;
gridview . Columns . Add ( myCol8 ) ;
gridview . Columns . Add ( myCol6 ) ;
gridview . Columns . Add ( myCol3 ) ;
}
else if ( activeTabIndex = = 2 | | activeTabIndex = = 3 )
{
gridview . Columns . Add ( myCol14 ) ;
gridview . Columns . Add ( myCol11223 ) ;
gridview . Columns . Add ( myCol2 ) ;
gridview . Columns . Add ( myCol12 ) ;
gridview . Columns . Add ( myCol10 ) ;
gridview . Columns . Add ( myCol11 ) ;
gridview . Columns . Add ( myCol20 ) ;
gridview . Columns . Add ( myCol4 ) ;
// gridview.Columns.Add(myCol0);
gridview . Columns . Add ( myCol1 ) ;
gridview . Columns . Add ( myCol8 ) ;
gridview . Columns . Add ( myCol6 ) ;
gridview . Columns . Add ( myCol3 ) ;
}
//to show bottom scroll bar
gridview . OptionsView . ColumnAutoWidth = false ;
gridview . BestFitColumns ( ) ;
// gridview.Focus();
}
#endregion
/// <summary>
/// loading data
/// </summary>
private int loadData ( )
{
//this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView;
showWaitForm ( ) ;
try
{
// this.splashScreenManager1.ShowWaitForm();
if ( activeTabIndex = = 0 ) //waiting list
{
queryStr = ( this . comboType . SelectedIndex = = 0 ? "" : string . Format ( "{0} =#'{1}';" , "isDouChk" , comboType . SelectedIndex = = 1 ? "N" : "Y" ) )
// + (this.txtGoodId.Text.Trim().Length == 0 ? "" : string.Format("{0} =#'{1}';", WmsGoods.fields.goodsId.ToString(), filtRiskChar( txtGoodId.Text.Trim())))
+ ( this . comPartQuery . SelectedIndex = = 0 ? "" : string . Format ( "{0} =#'{1}';" , WmsLocation . fields . part . ToString ( ) , ( ( Node ) this . comPartQuery . SelectedItem ) . ID ) )
+ ( this . txtGoodName . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . goodsName . ToString ( ) , filtRiskChar ( txtGoodName . Text . Trim ( ) ) ) )
+ ( this . txtpinyin . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . pinYin . ToString ( ) , filtRiskChar ( txtpinyin . Text . Trim ( ) ) ) ) ;
// + (this.textBatch.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '%{1}%';", WmsGoods.exfields.pinyin.ToString(), filtRiskChar(textBatch.Text.Trim())));
}
else if ( activeTabIndex = = 1 ) //history record
{
queryStr = ( this . comboType2 . SelectedIndex = = 0 ? "" : string . Format ( "{0} =#'{1}';" , "isDouChk" , comboType2 . SelectedIndex = = 1 ? "N" : "Y" ) )
// + (this.txtGoodId.Text.Trim().Length == 0 ? "" : string.Format("{0} =#'{1}';", WmsGoods.fields.goodsId.ToString(), filtRiskChar( txtGoodId.Text.Trim())))
+ ( string . Format ( "{0} >= # '{1}';" , "createtime" , this . dateEdit1 . DateTime ) ) + ( string . Format ( "{0} <= # '{1}';" , "createtime" , this . dateEdit2 . DateTime ) )
+ ( this . goodsName2 . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , WmsGoods . exfields . goodsName . ToString ( ) , filtRiskChar ( goodsName2 . Text . Trim ( ) ) ) )
+ ( this . locId . Text . Trim ( ) . Length = = 0 ? "" : string . Format ( "{0} like # '%{1}%';" , "locationId" , filtRiskChar ( locId . Text . Trim ( ) ) ) )
+ ( this . comPartQ . SelectedIndex = = 0 ? "" : string . Format ( "{0} =#'{1}';" , WmsLocation . fields . part . ToString ( ) , ( ( Node ) this . comPartQ . SelectedItem ) . ID ) )
+ ( this . comboResult . SelectedIndex = = 0 ? "" : string . Format ( "{0} =#'{1}';" , "issueType" , comboType . SelectedIndex = = 1 ? "0" : "3" ) ) ;
;
// + (this.textBatch.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '%{1}%';", WmsGoods.exfields.pinyin.ToString(), filtRiskChar(textBatch.Text.Trim())));
}
else if ( activeTabIndex = = 2 ) //near validdate
{
queryStr = "2" ;
// + (this.textBatch.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '%{1}%';", WmsGoods.exfields.pinyin.ToString(), filtRiskChar(textBatch.Text.Trim())));
}
else if ( activeTabIndex = = 3 )
{
queryStr = "3" ;
}
this . pager1 . PageCurrent = lastQuery . Equals ( queryStr ) ? this . pager1 . PageCurrent : 1 ; //根据查询条件的变化给pager赋值
pager1 . PageCurrent = pager1 . PageCurrent > 0 ? pager1 . PageCurrent : 1 ;
int start = ( pager1 . PageSize * ( pager1 . PageCurrent - 1 ) + 1 ) ;
int end = ( pager1 . PageSize * pager1 . PageCurrent ) ;
lastQuery = queryStr ;
DataSet ds = null ;
if ( activeTabIndex = = 0 )
{
ds = stkLocClient . getDataWaiting4Maintain ( queryStr , start , end ) ;
}
else if ( activeTabIndex = = 1 )
{
ds = stkLocClient . getDataMaintainRecords ( queryStr , start , end ) ;
}
else if ( activeTabIndex = = 2 )
{
2023-09-04 22:41:19 +08:00
ds = stkLocClient . getDataNearValid ( Convert . ToInt32 ( textEditDays . Value ) , start , end ) ;
2023-05-23 16:13:17 +08:00
}
else if ( activeTabIndex = = 3 )
{
ds = stkLocClient . getDataInvaild ( start , end ) ;
}
closeClient ( ) ;
dtDiffs = ds . Tables [ 0 ] ;
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;
// dtDiffs.PrimaryKey = new DataColumn[] { dtDiffs.Columns["goodsId"], dtDiffs.Columns["batch"] };
this . gridControl1 . DataSource = dtDiffs . DefaultView ;
// gridView1.OptionsView.ColumnAutoWidth = true;
initialDataGridColumns ( this . gridView1 ) ;
//update selected row index to the last updated one.
closeWaitForm ( ) ;
return cnt ; // lgt.getRowCount(query);
// return lgt.GetGoodType.QueryCount();
}
catch ( Exception er )
{
showErrorMsg ( er , er . Message ) ;
}
return 0 ;
}
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 ;
//show line number
this . gridView1 . IndicatorWidth = 40 ;
this . gridView1 . CustomDrawRowIndicator + = new DevExpress . XtraGrid . Views . Grid . RowIndicatorCustomDrawEventHandler ( gridView1_CustomDrawRowIndicator ) ;
gridView1 . CustomColumnDisplayText + = gridView1_CustomColumnDisplayText ;
}
//显示行的序号
private void gridView1_CustomDrawRowIndicator ( object sender , RowIndicatorCustomDrawEventArgs e )
{
if ( e . Info . IsRowIndicator & & e . RowHandle > = 0 )
{
e . Info . DisplayText = ( e . RowHandle + 1 ) . ToString ( ) ;
}
}
protected void query ( )
{
pager1 . Bind ( ) ;
}
private void queryGoods ( )
{
showWaitForm ( ) ;
try
{
query ( ) ; // loadData();
}
catch ( Exception e )
{
showErrorMsg ( 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
{
// lgt.update(wgoods);
//get updated data
query ( ) ;
}
catch ( Exception e )
{
showErrorMsg ( e . Message ) ;
}
finally
{
// WaitFormService.Close();
closeWaitForm ( ) ;
}
}
private void btnUpdateVol_Click ( object sender , EventArgs e )
{
DialogResult r = MessageBox . Show ( string . Format ( "确定要更新选中的{0}条商品容积信息吗?" , 1 , "确认修改" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ) ;
if ( r = = DialogResult . Yes )
{
}
}
private void btnUpdateGoodType_Click ( object sender , EventArgs e )
{
}
private void btnQuery_Click ( object sender , EventArgs e )
{
this . query ( ) ;
}
private void txtpinyin_KeyUp ( object sender , KeyEventArgs e )
{
if ( e . KeyCode = = Keys . Enter )
{
loadData ( ) ;
}
}
private void bbQuery_ItemClick ( object sender , ItemClickEventArgs e )
{
query ( ) ;
}
private void layoutControlGroup2_Shown ( object sender , EventArgs e )
{
pager1 . PageCount = 0 ;
pager1 . Bind ( false ) ;
if ( activeTabIndex > 0 )
{
gridControl1 . DataSource = null ;
}
activeTabIndex = 0 ;
}
private void layoutControlGroup3_Shown ( object sender , EventArgs e )
{
activeTabIndex = 1 ;
pager1 . PageCount = 0 ;
pager1 . Bind ( false ) ;
gridControl1 . DataSource = null ;
}
private void layoutControlGroup5_Shown ( object sender , EventArgs e )
{
pager1 . PageCount = 0 ;
pager1 . Bind ( false ) ;
activeTabIndex = 2 ;
gridControl1 . DataSource = null ;
}
private void layoutControlGroup6_Shown ( object sender , EventArgs e )
{
pager1 . PageCount = 0 ;
pager1 . Bind ( false ) ;
activeTabIndex = 3 ;
gridControl1 . DataSource = null ;
}
private void btnQuery_Click_1 ( object sender , EventArgs e )
{
query ( ) ;
}
private void gridView1_CustomColumnDisplayText ( object sender , DevExpress . XtraGrid . Views . Base . CustomColumnDisplayTextEventArgs e )
{
if ( e . Column . FieldName = = "state" )
{
if ( ! stockState . ContainsValue ( e . DisplayText ) )
{
int display = - 100 ;
string disTxt = e . DisplayText ;
try
{
2023-09-04 22:41:19 +08:00
display = Convert . ToInt32 ( e . DisplayText ) ;
2023-05-23 16:13:17 +08:00
e . DisplayText = stockState [ display ] ;
}
catch
{
return ;
}
}
} else if ( e . Column . FieldName = = "isDouChk" )
{
if ( e . DisplayText = = "Y" )
{
e . DisplayText = "重点养护" ;
}
else if ( e . DisplayText = = "N" )
{
e . DisplayText = "普通养护" ;
}
else {
return ;
}
/ * if ( ! mainTainType . ContainsValue ( e . DisplayText ) )
{
int display = - 100 ;
string disTxt = e . DisplayText ;
try
{
2023-09-04 22:41:19 +08:00
display = Convert . ToInt32 ( e . DisplayText ) ;
2023-05-23 16:13:17 +08:00
e . DisplayText = mainTainType [ display ] ;
}
catch
{
return ;
}
} * * /
}
else if ( e . Column . FieldName = = "issueType" )
{
if ( ! stockState . ContainsValue ( e . DisplayText ) )
{
int display = - 100 ;
string disTxt = e . DisplayText ;
try
{
2023-09-04 22:41:19 +08:00
display = Convert . ToInt32 ( e . DisplayText ) ;
2023-05-23 16:13:17 +08:00
e . DisplayText = stockState [ display ] ;
}
catch
{
return ;
}
}
}
}
private void bbiExport_ItemClick ( object sender , ItemClickEventArgs e )
{
exportExcel ( gridView1 ) ;
}
}
}