ldj/winform/基础资料/DeskSetup.cs

844 lines
28 KiB
C#

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.utils.print;
//using DeiNiu.wms.win.ServiceReferenceInRequest;
//using DeiNiu.wms.win.ServiceReferenceInRequestLocal;
//using DeiNiu.wms.win.ServiceReferenceLot;
using DeiNiu.wms.win.ServiceReferenceOwner;
using DeiNiu.wms.win.ServiceReferenceLot;
using DeiNiu.wms.win.PlateService;
namespace DeiNiu.wms.win
{
public partial class DeskSetup : BasicRibbonForm
{
WmsPlateClient client
{
get
{
return new WmsPlateClient("BasicHttpBinding_IWmsPlate",
buildSvrAddress("WmsPlateService.svc"));
}
}
WmsOutDesk currentDesk;
private string fieldName = WmsLocation.fields.locationId.ToString();
private string fieldGoodType = WmsLocation.fields.whGoodsType.ToString();
private string lastQuery = "";
private DataTable dt;
private DataTable dtAtt;
// DataTable dtIndetail;
private int selectedRowIndex = -1;
// WcfLotAtt currentAtt;
private bool isShowingInRequest = true;
public DeskSetup()
{
InitializeComponent();
initialControls();
// loadData();
}
#region initialControls
private void initialControls()
{
initialComboBoxes();
initialPagerControls();
initialDataGrid();
initialQueryInput();
setValidationRule();
}
Dictionary<int, string> dicType = new Dictionary<int, string>();
Dictionary<int, string> dicStatus = new Dictionary<int, string>();
private void initialComboBoxes()
{
dicType = Util.convertEnumToDic(typeof(enumDeskType));
initialComboBoxs(comType, dicType, false);
dicStatus = Util.convertEnumToDic(typeof(enumDeskState));
initialComboBoxs(comStatus, dicStatus, false);
}
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 gridView)
{
setupGridView(gridView, false);
//setupGridView(gridView2, false,false);
//setupGridView(gridView3, false,false);
// gridviewGoodsType.PopulateColumns();
gridView.Columns.Clear();
// gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]);
GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" };
myCol0.Visible = false;
gridView.Columns.Add(myCol0);
if (gridView == gridView1)
{
GridColumn myCol1 = new GridColumn() { Caption = "复核台编号", Visible = true, FieldName = WmsOutDesk.fields.color.ToString()};
GridColumn myCol2 = new GridColumn() { Caption = "颜色标识", Visible = true, FieldName = DeiNiu.wms.Data.Model.WmsOutDesk.fields.deskName.ToString() };
GridColumn myCol3 = new GridColumn() { Caption = "状态", Visible = true, FieldName = WmsOutDesk.fields.state.ToString(),MinWidth= 50 };
GridColumn myCol4 = new GridColumn() { Caption = "最大播种数量", Visible = true, FieldName = WmsOutDesk.fields.seedsCount.ToString() };
GridColumn myCol5 = new GridColumn() { Caption = "类型", Visible = true, FieldName = WmsOutDesk.fields.deskType.ToString(), MinWidth = 50 };
GridColumn myCol6 = new GridColumn() { Caption = "畅通", Visible = true, FieldName = WmsOutDesk.fields.available.ToString(), MinWidth = 50 };
GridColumn myCol7 = new GridColumn() { Caption = "最小播种数量", Visible = true, FieldName = WmsOutDesk.fields.seedsMinCount.ToString(), MinWidth = 50 };
gridView.Columns.Add(myCol1);
gridView.Columns.Add(myCol2);
gridView.Columns.Add(myCol5);
gridView1.Columns.Add(myCol3);
gridView.Columns.Add(myCol4);
gridView.Columns.Add(myCol7);
gridView.Columns.Add(myCol6);
}
// this.gridView1.Columns.Add(myCol4);
//to show bottom scroll bar
gridView.OptionsView.ColumnAutoWidth = false;
gridView.BestFitColumns();
// gridView.Focus();
//if (gridView1 == gridView)
//{
// this.gridView1.Focus(); ;
//}
// initialGridView2Columns();
// gridControl2.DataSource = null;
}
private void initialGridView2Columns(GridView gridview)
{
setupGridView(gridview, false, true, false);
gridview.FocusRectStyle = DrawFocusRectStyle.None;
// gridviewGoodsType.PopulateColumns();
gridview.Columns.Clear();
// gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]);
GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" };
myCol0.Visible = false;
gridview.Columns.Add(myCol0);
GridColumn myCol1 = new GridColumn() { Caption = "属性名称", Visible = true, FieldName = LotAtt.fields.attName.ToString() };
GridColumn myCol2 = new GridColumn() { Caption = "属性类型", Visible = true, FieldName = LotAtt.fields.attType.ToString() };
GridColumn myCol3 = new GridColumn() { Caption = "列表", Visible = true, FieldName = LotAtt.fields.isList.ToString() };
GridColumn myCol4 = new GridColumn() { Caption = "列表FLAG", Visible = true, FieldName = LotAtt.fields.listId.ToString() };
GridColumn myCol5 = new GridColumn() { Caption = "创建人", Visible = true, FieldName = LotAtt.fields.operater.ToString() };
GridColumn myCol6 = new GridColumn() { Caption = "创建时间", Visible = true, FieldName = "createtime" };
GridColumn myCol7 = new GridColumn() { Caption = "可选项", Visible = true, FieldName = LotAtt.fields.isOptional.ToString() };
if (gridview == gridView2)
{
gridview.Columns.Add(myCol1);
gridview.Columns.Add(myCol2);
gridview.Columns.Add(myCol3);
gridview.Columns.Add(myCol4);
gridview.Columns.Add(myCol5);
gridview.Columns.Add(myCol7);
gridview.Columns.Add(myCol6);
}
//to show bottom scroll bar
gridview.OptionsView.ColumnAutoWidth = false;
gridview.BestFitColumns();
// gridView2.Focus();
}
#endregion
private void initialRequestOrders()
{
showWaitForm();
try{
//ownerClient.getInRequests();
// getInValidOrders();
}
//catch (DeiNiuTimeOutException te)
//{
//
//}
catch(Exception e){
showErrorMsg(e.Message);
}
finally{
closeWaitForm();
}
}
/// <summary>
/// loading data
/// </summary>
private int loadData()
{
//this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView;
showWaitForm();
try
{
// this.splashScreenManager1.ShowWaitForm();
string query = "";
;
bool isQueryNotChanged = lastQuery.Equals(query);
this.pager1.PageCurrent = isQueryNotChanged ? this.pager1.PageCurrent : 1; //根据查询条件的变化给pager赋值
int start = (pager1.PageSize * (pager1.PageCurrent - 1) + 1);
int end = (pager1.PageSize * pager1.PageCurrent);
lastQuery = query;
DataSet ds = client.queryDesk(query, start, end);// lgt.Query(query, start, end);
client.Close();
dt = 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;
dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
bool firstLoad = !isQueryNotChanged || this.gridControl1.DataSource == null;
this.gridControl1.DataSource = dt.DefaultView;
initialDataGridColumns(gridView1);
//update selected row index to the last updated one.
if (currentDesk != null)
{
selectedRowIndex = -1;
DataRow dr = dt.Rows.Find(currentDesk. ID);
if (dr != null)
{
selectedRowIndex = dt.Rows.IndexOf(dr);
}
if (selectedRowIndex >= 0 && dt.Rows.Count > selectedRowIndex)
{
// gridView1.SelectRow(selectedRowIndex);
gridView1.FocusedRowHandle = selectedRowIndex;
// gridView1.MakeRowVisible(selectedRowIndex);
}
//gridView1.FocusedRowHandle = selectedRowIndex;
}else
// if (firstLoad)
{
selectedRowIndex = 0;
gridView1.FocusedRowHandle = 0;
gridView1.SelectRow(0);
}
setCurrentRequestDetail();
closeWaitForm();
return cnt;
}
catch (Exception e)
{
showErrorMsg(e,e.Message);
}
closeWaitForm();
return 0;// lgt.getRowCount(query);
// return lgt.GetGoodType.QueryCount();
}
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 = -1; //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
}
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_DataSourceChanged(object sender, EventArgs e)
{
if (selectedRowIndex >= 0 && dt.Rows.Count > selectedRowIndex)
{
gridView1.FocusedRowHandle = selectedRowIndex;
gridView1.MakeRowVisible(selectedRowIndex);
}
}
private void gridView2_DataSourceChanged(object sender, EventArgs e)
{
if (!isShowingInRequest)
{
return;
}
}
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(goods);
//get updated data
query();
}
catch (Exception e)
{
showErrorMsg(e.Message);
}
finally
{
// WaitFormService.Close();
closeWaitForm();
}
}
int lastSelectedId =0;
private bool getCurrentObject()
{
if (selectedRowIndex <0 || selectedRowIndex >= dt.Rows.Count)
{
return false;
}
// DataRow currentRow = dt.Rows[selectedRowIndex];
DataRowView dr = (DataRowView)(GetGridViewFilteredAndSortedData(gridView1)[selectedRowIndex]);
lastSelectedId = currentDesk == null ? 0: currentDesk.ID;
currentDesk = (new WmsOutDesk(dr.Row));
this.gridControl2.DataSource = null;
// btnAddOwner.Enabled = true;
return true;
}
private void btnQuery_Click(object sender, EventArgs e)
{
queryGoods();
}
private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
{
if (gridView1.FocusedRowHandle <0 || gridView1.FocusedRowHandle == selectedRowIndex)
{
return;
}
selectedRowIndex = gridView1.FocusedRowHandle;
// showErrorMsg("selection:"+ selectedRowIndex);
setCurrentRequestDetail();
}
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.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.CellFocus;
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);
//show line number
this.gridView1.IndicatorWidth = 40;
this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView_CustomDrawRowIndicator);
this.gridView2.IndicatorWidth = 40;
this.gridView2.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView_CustomDrawRowIndicator);
gridView1.CustomColumnDisplayText += gridView2_CustomColumnDisplayText;
gridView2.CustomDrawCell += gridView_CustomDrawCell;
gridView2.RowCellStyle += gridView_RowCellStyle;
gridView1.RowCellStyle += gridView_RowCellStyle;
//this.gridView2.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(this.gridView2_FocusedRowObjectChanged);
gridView1.CustomColumnDisplayText += gridView2_CustomColumnDisplayText;
gridView1.CustomDrawCell += gridView_CustomDrawCell;
}
private void gridView2_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
// if (sender == gridView2)
{
if (e.Column.FieldName == WmsOutDesk.fields.deskType.ToString())
{
if (!stockInLocationStatus.ContainsValue(e.DisplayText))
{
int display = -100;
string disTxt = e.DisplayText;
try
{
display = Convert.ToInt16(e.DisplayText);
if (sender == gridView1)
{
e.DisplayText = this.dicType[display];
}
}
catch
{
return;
}
}
// e.DisplayText = stockInLocationStatus.ContainsKey(display) ? stockInLocationStatus[display] : display+"";
}
else if (e.Column.FieldName == WmsOutDesk.fields.state.ToString())
{
if (!stockInLocationStatus.ContainsValue(e.DisplayText))
{
int display = -100;
string disTxt = e.DisplayText;
try
{
display = Convert.ToInt16(e.DisplayText);
if (sender == gridView1)
{
e.DisplayText = this.dicStatus[display];
}
}
catch
{
return;
}
}
else if (e.Column.FieldName == WmsOutDesk.fields.available.ToString())
{
if (!stockInLocationStatus.ContainsValue(e.DisplayText))
{
int display = -100;
string disTxt = e.DisplayText;
try
{
display = Convert.ToInt16(e.DisplayText);
if (sender == gridView1)
{
e.DisplayText = display==0?"拥堵":"畅通";
}
}
catch
{
return;
}
}
// e.DisplayText = stockInLocationStatus.ContainsKey(display) ? stockInLocationStatus[display] : display+"";
}
}
}
}
void gridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
//var currentView = sender as GridView;
//if (currentView != null && e.RowHandle == currentView.FocusedRowHandle) return;
Rectangle r = e.Bounds;
if (e.Column.FieldName == WmsOutDesk.fields.deskType.ToString() && e.CellValue !=null)
{
string a = e.CellValue.ToString();
string b = e.DisplayText;
if (b.Equals("待收货"))
{
e.Appearance.ForeColor = Color.Red;
e.Appearance.DrawString(e.Cache, e.DisplayText, r);
e.Handled = true;
}
else if(b.Equals("已收货"))
{
e.Appearance.ForeColor = Color.Gray;
e.Appearance.DrawString(e.Cache, e.DisplayText, r);
e.Handled = true;
}
}
}
void gridView_RowCellStyle(object sender,DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
var currentView = sender as GridView;
if( currentView == null){return;}
if (!currentView.GetDataRow(e.RowHandle).Table.Columns.Contains("wms_state"))
{
return;
}
string state = currentView.GetDataRow(e.RowHandle)["wms_state"].ToString().Trim();
if (state == "0")
{
return;
}
bool isFocused = e.RowHandle == currentView.FocusedRowHandle;
DevExpress.Utils.AppearanceDefault rowStyle = null;
DevExpress.Utils.AppearanceDefault appBlueRed =
new DevExpress.Utils.AppearanceDefault (Color.White, Color.Red, Color.Empty, Color.Blue, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
DevExpress.Utils.AppearanceDefault appYB =
new DevExpress.Utils.AppearanceDefault(Color.White, Color.Red, Color.Green);
DevExpress.Utils.AppearanceDefault alertFocus = new DevExpress.Utils.AppearanceDefault(Color.White, Color.Red, Color.Green, Color.Yellow);
DevExpress.Utils.AppearanceDefault alert = new DevExpress.Utils.AppearanceDefault(Color.Red, Color.White );
DevExpress.Utils.AppearanceDefault passedFocus = new DevExpress.Utils.AppearanceDefault(Color.White, Color.Gray);
DevExpress.Utils.AppearanceDefault passed = new DevExpress.Utils.AppearanceDefault(Color.Gray, Color.White);
if (state == "2" )
{
rowStyle = isFocused ? passedFocus : passed;
}
else if (state == "1")
{
rowStyle = isFocused ? alertFocus : alert;
}
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, rowStyle);
/*
if (sender == this.gridView2)
{
if (this.gridView2.GetDataRow(e.RowHandle)["state"].ToString().Trim() == "2")
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, alert);
}
}else if(sender == this.gridView1){
if ( state == "2")
{
if (currentView != null && e.RowHandle == currentView.FocusedRowHandle)
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, alertFocus);
}
else
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, alert);
}
}
else if (state == "1")
{
DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, passed);
}
}
*/
}
private void setCurrentRequestDetail()
{
if (!getCurrentObject() || currentDesk == null)
{
return;
}
/// gridView1.FocusedRowHandle = selectedRowIndex;//
// gridView1.SelectRow(selectedRowIndex);
foreach (Colitem item in comType.Properties.Items)
{
if (currentDesk.deskType == item.key)
{
comType.SelectedItem = item;
break;
}
}
foreach (Colitem item in comStatus.Properties.Items)
{
if (currentDesk.state == item.key)
{
comStatus.SelectedItem = item;
break;
}
}
txtSeedsCnt.Text = currentDesk.seedsCount+"";
txtMin.Text = currentDesk.seedsMinCount + "";
}
private void GoodsInForm_FormClosing(object sender, FormClosingEventArgs e)
{
//closeClient();
}
protected new void gridview_GotFocus(object sender, EventArgs e)
{
if (sender == gridView1)
{
//grid4Valid.ForeColor = Color.Blue;
// gridView4Valid.OptionsSelection.EnableAppearanceHideSelection = true;
if (!isShowingInRequest)
{
this.setCurrentRequestDetail();
}
switchGridViewRowSelection(gridView1, true);
}
else
{
switchGridViewRowSelection((GridView)sender, true);
}
}
bool validOwner( )
{
try
{
Convert.ToInt16(txtSeedsCnt.Text);
}
catch
{
showErrorMsg("请正确输入可播种订单最大数量");
txtSeedsCnt.Focus();
return false;
}
try
{
Convert.ToInt16(txtMin.Text);
}
catch
{
showErrorMsg("请正确输入可播种订单最小数量");
txtMin.Focus();
return false;
}
return true;
}
private void btnUpdateLot_Click(object sender, EventArgs e)
{
if (!validOwner())
{
return;
}
currentDesk.seedsCount = Convert.ToInt16(txtSeedsCnt.Text);
currentDesk .operater = LoginInfo.UserId;
currentDesk.deskType = ((Colitem)comType.SelectedItem).key;
currentDesk.state = ((Colitem)comStatus.SelectedItem).key;
currentDesk.seedsMinCount = Convert.ToInt16(txtMin.Text);
try
{
client.updateDesk(currentDesk.ID, currentDesk.deskType,
currentDesk.state, currentDesk.seedsCount, currentDesk.seedsMinCount);
client.Close();
}
catch (Exception er)
{
showErrorMsg( er.Message);
}
query();
}
private void btquery_Click(object sender, EventArgs e)
{
queryGoods();
}
}
}