using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using DeiNiu.Utils; using DeiNiu.wms.win.utils.print; using DevExpress.XtraBars; using DevExpress.XtraEditors.Controls; //using DeiNiu.wms.Logical; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Grid; using DeiNiu.wms.Data.Model; namespace DeiNiu.wms.win { public partial class DeskCustomer : BasicRibbonForm { // lWmsDeskCustomer lwmsDc = new lWmsDeskCustomer(); WmsDeskCustomer deskCust = new WmsDeskCustomer(); ServiceCustomer.WcfWmsDeskCustomer wcfDesk = new ServiceCustomer.WcfWmsDeskCustomer(); // private string fieldName = Wmslocation.fields.locationId.ToString(); private string lastQuery = ""; private DataTable dt; private int selectedRowIndex = -1; private bool isAdding = true; // private LocStructs locs; // private List selectedLocations; private List selectedIds; public DeskCustomer() { InitializeComponent(); initialControls(); // loadData(); } #region initialControls private void initialControls() { initialComboBoxes(); initialPagerControls(); initialDataGrid(); initialQueryInput(); swithOperationType(); setValidationRule(); this.lcgSetup.Expanded = false; } private void initialComboBoxes() { //initial combobox of port this.comport.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; ComboBoxItemCollection coll = comport.Properties.Items; coll.BeginUpdate(); try { for (int i = 1; i <= 20; i++) { coll.Add(i); } } finally { coll.EndUpdate(); } comport.SelectedIndex = 0; this.comPortQuery.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; ComboBoxItemCollection col2 = comPortQuery.Properties.Items; col2.BeginUpdate(); col2.Add("全部"); try { for (int i = 1; i <= 20; i++) { col2.Add(i); } } finally { col2.EndUpdate(); } comPortQuery.SelectedIndex = 0; //initial comboboxedits with dic // Node[] nds = { }; } private void setValidationRule() { // dxValidationProvider1.SetValidationRule(comWarehouseQuery, ValidationRules.notEmptyValidationRule); //txtGoodType.Properties.MaxLength = 40; //txtGoodDesc.Properties.MaxLength = 250; //textEdit1.Properties.MaxLength = txtGoodType.Properties.MaxLength; } private void initialQueryInput() { } 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 = 800;//每页行数 this.pager1.Bind();//绑定 #endregion } private void initialDataGrid() { 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); //show line number this.gridView1.IndicatorWidth = 40; this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView1_CustomDrawRowIndicator); gridView1.CustomColumnDisplayText += gridView_CustomColumnDisplayText; } //显示行的序号 private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } private void initialDataGridColumns() { setupGridView(gridView1, true); // gridviewGoodsType.PopulateColumns(); gridView1.Columns.Clear(); // gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]); GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" }; myCol0.Visible = false; this.gridView1.Columns.Add(myCol0); GridColumn myCol1 = new GridColumn() { Caption = "分播台ID", Visible = true, FieldName = "deskId", MaxWidth = 80 }; // GridColumn myCol3 = new GridColumn() { Caption = "长", Visible = true, FieldName = Wmslocation.fields.length.ToString(), MaxWidth = 80 }; //GridColumn myCol4 = new GridColumn() { Caption = "宽", Visible = true, FieldName = Wmslocation.fields.width.ToString(), MaxWidth = 80 }; // GridColumn myCol5 = new GridColumn() { Caption = "高", Visible = true, FieldName = Wmslocation.fields.height.ToString(), MaxWidth = 80 }; // GridColumn myCol12 = new GridColumn() { Caption = "重", Visible = true, FieldName = Wmslocation.fields.weight.ToString(), MaxWidth = 80 }; // GridColumn myCol2 = new GridColumn() { Caption = "货物类别", Visible = true, FieldName = Wmslocation.fields.goodsType.ToString() + "Name" }; // GridColumn myCol6 = new GridColumn() { Caption = "库房分类", Visible = true, FieldName = Wmslocation.fields.whType.ToString()}; GridColumn myCol7 = new GridColumn() { Caption = "店铺", Visible = true, FieldName = WmsDeskCustomer.fields.custName.ToString(), MaxWidth = 300 }; GridColumn myCol8 = new GridColumn() { Caption = "灯ID", Visible = true, FieldName = WmsDeskCustomer.fields.custid.ToString(), MaxWidth = 50 }; GridColumn myCol9 = new GridColumn() { Caption = "线路", Visible = true, FieldName = WmsDeskCustomer.fields.partionName.ToString(), MaxWidth = 100 }; GridColumn myCol10 = new GridColumn() { Caption = "配货序号", Visible = true, FieldName = WmsDeskCustomer.fields.portNo.ToString(), MaxWidth = 80 }; GridColumn myCol11 = new GridColumn() { Caption = "分区", Visible = true, FieldName = WmsDeskCustomer.fields.partion.ToString(), MaxWidth = 50 }; GridColumn myCol13 = new GridColumn() { Caption = "备注", Visible = true, FieldName = WmsDeskCustomer.fields.mem.ToString() }; // GridColumn myCol14 = new GridColumn() { Caption = "线路", Visible = true, FieldName = WmsDeskCustomer.fields.partionName.ToString(), MaxWidth = 80 }; this.gridView1.Columns.Add(myCol11); this.gridView1.Columns.Add(myCol1); this.gridView1.Columns.Add(myCol9); this.gridView1.Columns.Add(myCol7); this.gridView1.Columns.Add(myCol8); this.gridView1.Columns.Add(myCol10); this.gridView1.Columns.Add(myCol13); gridView1.BestFitColumns(); //gridView1.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 /// /// loading data /// private int loadData() { //this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView; try { clearInputs(); showWaitForm(); string query = ""; query = this.txtCustNameQ.Text.Trim().Length > 0 ? string.Format("{0} like #'%{1}%';", WmsDeskCustomer.fields.custName.ToString(), filtRiskChar(txtCustNameQ.Text)) : ""; query += (this.txtDeskIdQ.Text.Trim().Length == 0 ? "" : string.Format("{0} =#'{1}';", WmsDeskCustomer.fields.deskId.ToString(), filtRiskChar(txtDeskIdQ.Text))); query += (this.txtPortNoQ1.Text.Trim().Length == 0 ? "" : string.Format("{0} >=#'{1}';", WmsDeskCustomer.fields.portNo.ToString(), filtRiskChar(txtPortNoQ1.Text))); query += (this.txtPortQ2.Text.Trim().Length == 0 ? "" : string.Format("{0} <=#'{1}';", WmsDeskCustomer.fields.portNo.ToString(), filtRiskChar(txtPortQ2.Text))); 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 = custClient.queryDesks(query, start, end); closeClient(); 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"] }; this.gridControl1.DataSource = dt.DefaultView; initialDataGridColumns(); //update selected row index to the last updated one. if (this.deskCust.ID > 0) { DataRow dr = dt.Rows.Find(deskCust.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; } gridView1.FocusedRowHandle = 0; getCurrentObject(); closeWaitForm(); return cnt;// lgt.getRowCount(query); // return lgt.GetGoodType.QueryCount(); } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } return 0; } /// /// 分页控件产生的事件 /// private int pager_EventPaging(DeiNiu.Controls.pager.EventPagingArg e) { selectedRowIndex = 0; //reset currentRowIndex return loadData(); } private void gridView_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { } private void bindDetail() { } private bool setDataBack() { try { deskCust.partion = Convert.ToInt16(this.txtPartion.Text); } catch { this.txtPartion.SelectAll(); txtPartion.Focus(); return false; } try { deskCust.deskId = Convert.ToInt16(this.txtDeska.Text); } catch { this.txtDeska.SelectAll(); txtDeska.Focus(); return false; } try { deskCust.portNo = Convert.ToInt16(this.txtPorta.Text); } catch { this.txtPorta.SelectAll(); txtPorta.Focus(); return false; } try { deskCust.custid = Convert.ToInt16(this.txtLightIda.Text); } catch { this.txtLightIda.SelectAll(); txtLightIda.Focus(); return false; } deskCust.mem = this.txtMem.Text; deskCust.partionName = this.txtLine.Text; // deskCust.deskName = ""; deskCust.custName = this.txtCustName.Text; wcfDesk = WcfWmsDeskCustomer(deskCust); return (deskCust.partion > 0 && deskCust.deskId > 0 && deskCust.portNo > 0 && deskCust.custid > 0 && !string.IsNullOrEmpty(deskCust.custName)); } 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; } ServiceCustomer.WcfWmsDeskCustomer WcfWmsDeskCustomer(WmsDeskCustomer dbObj) { #region get data from dbobj ServiceCustomer.WcfWmsDeskCustomer wcfDesk = new ServiceCustomer.WcfWmsDeskCustomer(); wcfDesk.id = dbObj.ID; wcfDesk.partion = dbObj.partion; wcfDesk.deskId = dbObj.deskId; wcfDesk.custid = dbObj.custid; wcfDesk. custName = dbObj.custName; wcfDesk.partionName = dbObj.partionName; wcfDesk.mem = dbObj.mem; wcfDesk.portNo = dbObj.portNo; wcfDesk.operater = dbObj.operater; return wcfDesk; #endregion } private void btnSave_Click(object sender, EventArgs e) { if (!getCurrentObject()) { return; } } private void updateLocations() { showWaitForm(); //WaitFormService.Show(this); try { //update the goodtype setDataBack(); // lgt.GetGoodType.Update(); //get updated data query();// loadData(); } catch (Exception e) { showErrorMsg(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); // btnSave.Enabled = true; } } private void gridView1_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) { clearInputs(); int a = gridView1.FocusedRowHandle; if (a < 0 || gridView1.GetSelectedRows().Length == 0) { // return; } int selectedHandle; //selectedRowIndex = this.gridView1.GetSelectedRows()[0]; ////MessageBox.Show(this.gridView1.GetRowCellValue(selectedHandle, "id").ToString()); if (selectedRowIndex < 0) { return; } if (getCurrentObject()) { this.txtDeska.Text = deskCust.deskId + ""; this.txtPorta.Text = deskCust.portNo + ""; this.txtLightIda.Text = deskCust.custid + ""; this.txtCustName.Text = deskCust.custName; this.txtLine.Text = deskCust.partionName; this.txtMem.Text = deskCust.mem; this.txtPartion.Text = deskCust.partion + ""; } } private void clearInputs() { this.txtLine.Text = this.txtMem.Text = this.txtPartion.Text = this.txtDeska.Text = ""; this.txtPorta.Text = ""; this.txtLightIda.Text = ""; this.txtCustName.Text = ""; } private bool getCurrentObject() { selectedRowIndex = gridView1.FocusedRowHandle; if (selectedRowIndex < 0 || dt.Rows.Count <= selectedRowIndex) { // MessageBox.Show("请在列表里选择数据"); return false; } // DataRow currentRow = dt.Rows[selectedRowIndex]; DataRowView dr = (DataRowView)(GetGridViewFilteredAndSortedData(gridView1)[selectedRowIndex]); // deskCust.getModel(dr.Row); deskCust = new WmsDeskCustomer(dr.Row); return true; } private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) { } private void gridView1_DataSourceChanged(object sender, EventArgs e) { if (selectedRowIndex > 0 && dt.Rows.Count > selectedRowIndex) { gridView1.FocusedRowHandle = selectedRowIndex; gridView1.MakeRowVisible(selectedRowIndex); } } private void btnDelete_Click(object sender, EventArgs e) { //if (!getCurrentObject()) //{ // return; //} //MessageBoxButtons messButton = MessageBoxButtons.OKCancel; //DialogResult dr = MessageBox.Show(String.Format("确定要删除 {0} 吗?",lgt.GetGoodType.goodsName), "删除记录", messButton); //if (dr == DialogResult.OK) //{ // lgt.GetGoodType.Delete() ; // lgt.Initialize(); // query();//loadData(); //} } protected void query() { pager1.Bind(); } private void startQuery() { showWaitForm(); try { query();// loadData(); } catch (Exception e) { MessageBox.Show(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); btnQuery.Enabled = true; } } private void txtQuery_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { query(); } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { swithOperationType(); } private void swithOperationType() { /* isAdding = tabControl1.SelectedIndex == 0; if (isAdding) { clearInputs(); } else { gridView1_FocusedRowObjectChanged(null, null); } btnNew.Enabled = isAdding; btnSave.Enabled = !isAdding; btnDelete.Enabled = !isAdding; }*/ } private void bbQuery_ItemClick(object sender, ItemClickEventArgs e) { //Thread th = new Thread(new ThreadStart(this.queryGoodType)); //th.Start(); startQuery(); } private void bbCreateLocations_ItemClick(object sender, ItemClickEventArgs e) { startLocations(); } void startLocations() { //Thread th = new Thread(new ThreadStart(this.newLocations)); //th.Start(); newLocations(); } bool isNewLocationQuery = false; private void newLocations() { showWaitForm(); try { // setLocs(); // lwmsLoc.addLocations(locs); // lgt.addLocations(locs); isNewLocationQuery = true; query();// loadData(); isNewLocationQuery = false; // initialize and clear object and inputs, prepare for adding more. // lgt.initialize(); // clearInputs(); } catch (Exception e) { showErrorMsg(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); } } private void btnQuery_Click(object sender, EventArgs e) { this.btnQuery.Enabled = false; startQuery(); } private void btnCreate_Click(object sender, EventArgs e) { startLocations(); } private void DeskCustomer_FormClosing(object sender, FormClosingEventArgs e) { // client.Close(); } private bool getCurrentObjects() { int[] selectedRows = gridView1.GetSelectedRows(); // selectedLocations = new List(); selectedIds = new List(); foreach (int i in selectedRows) { DataRow currentRow = dt.Rows[i]; selectedIds.Add(Convert.ToInt32(currentRow["ID"].ToString())); } if (selectedRows.Length == 0) { showErrorMsg("请至少选择一条数据"); return false; } DialogResult r = MessageBox.Show(string.Format("确定要更新选中的{0}条货位信息吗?", selectedRows.Length), "确认修改", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); return r == DialogResult.Yes; } private void lcgSetup_Showing(object sender, EventArgs e) { } private void lcgQuery_CustomButtonChecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { } private void lcgSetup_CustomButtonChecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { } private void lcgQuery_CustomButtonUnchecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { try { // lcgSetup.Expanded = false; } catch (Exception er) { showErrorMsg(er.Message); } } private void lcgSetup_CustomButtonUnchecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { try { // lcgQuery.Expanded = false; } catch (Exception er) { showErrorMsg(er.Message); } } private void bbiExport_ItemClick(object sender, ItemClickEventArgs e) { exportExcel( gridView1); } private void bbiImport_ItemClick(object sender, ItemClickEventArgs e) { deskMap = new Dictionary(); clearDeskCustmer(); importExcel(); query(); } private void clearDeskCustmer() { // custClient.trunckData(); } Dictionary custMap; int custId = 0; private int getCustId(String custName) { String key = custName; if (custMap == null) { custMap = new Dictionary(); } if (custMap.ContainsKey(key)) { return custMap[key]; } else { custId++; custMap[key] = custId; return custId; } } Dictionary deskMap; private int getCustId(int deskId) { if (deskMap == null) { deskMap = new Dictionary(); } if (deskMap.ContainsKey(deskId)) { deskMap[deskId]++; } else { deskMap[deskId] = 1; } return deskMap[deskId]; } protected override void FillDataToDs(DataRow dr) //string itemid, string itemplu, string itemName) { int custId = 0; int deskId = 0; string custName = string.Empty; string deskName = string.Empty; string portNo = string.Empty; string lightId = string.Empty; string mem = string.Empty; int partion = 0; if (dr["分播台ID"].ToString().Trim() != string.Empty) deskId = Convert.ToInt16(dr["分播台ID"].ToString().Trim()); if (dr["店铺"].ToString().Trim() != string.Empty) custName = dr["店铺"].ToString().Trim(); if (dr["线路"].ToString().Trim() != string.Empty) deskName = dr["线路"].ToString().Trim(); if (dr["灯ID"].ToString().Trim() != string.Empty) lightId = dr["灯ID"].ToString().Trim(); if (dr["配货序号"].ToString().Trim() != string.Empty) portNo = dr["配货序号"].ToString().Trim(); if (dr["备注"].ToString().Trim() != string.Empty) mem = dr["备注"].ToString().Trim(); if (dr["分区"].ToString().Trim() != string.Empty) partion = Convert.ToInt16(dr["分区"].ToString().Trim()); // custId = getCustId(custName); // custId = getCustId(deskId); try { custId = Convert.ToInt16(lightId); if (custId > 0 && deskId > 0 && custName != string.Empty) { WmsDeskCustomer dc = new WmsDeskCustomer(); dc.custid = custId; dc.deskId = deskId; dc.partionName = deskName; dc.custName = custName; dc.portNo = Convert.ToInt16(portNo); dc.mem = mem; dc.partion = partion; custClient.add(WcfWmsDeskCustomer(dc)); closeClient(); } } catch { } } private void btnPortsetup_Click(object sender, EventArgs e) { if (!validPorts()) { return; } this.btnPortsetup.Enabled = false; showWaitForm(); setupPorts(); this.btnPortsetup.Enabled = true; query(); } private void setupPorts() { if (validPorts()) { // int cnt = lwmsDc.setupPort(deskId, portNo, startId, endId); closeWaitForm(); // showInfoMsg("共更新了 " + cnt + " 条记录"); } closeWaitForm(); } int deskId, portNo, startId, endId; private bool validPorts() { try { deskId = Convert.ToInt32(this.txtDeskId.Text.Trim()); portNo = Convert.ToInt32(this.txtPortNo.Text.Trim()); startId = Convert.ToInt32(this.txtLightStartId.Text.Trim()); endId = Convert.ToInt32(this.txtLightEndId.Text.Trim()); } catch { showErrorMsg("请检查输入的数字是否正确"); return false; } return endId == 0 && startId == 0 || endId > startId; } private void btnImport_Click(object sender, EventArgs e) { DialogResult r = MessageBox.Show(string.Format("确定重新导入门店信息吗?"), "确认导入", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (r == DialogResult.No) { return; } deskMap = new Dictionary(); importExcel(); query(); } protected override void clearOldData() { clearDeskCustmer(); } private void btnExport_Click(object sender, EventArgs e) { exportExcel( gridView1,"门店列表"); } private void simpleButton1_Click_1(object sender, EventArgs e) { query(); // loadData(); } private void btnUpdate_Click(object sender, EventArgs e) { if (!getCurrentObject()) { MessageBox.Show("请在列表里选择数据"); return; } try { if (setDataBack()) { showWaitForm(); if (custClient.update(wcfDesk) > 0) { MessageBox.Show(deskCust.custName + "更新成功!"); query(); closeWaitForm(); } else { closeWaitForm(); MessageBox.Show("更新失败"); } closeClient(); } } catch (Exception er) { closeWaitForm(); closeClient(); showErrorMsg(er.Message); } } private void btnAdd_Click(object sender, EventArgs e) { try { if (setDataBack()) { // deskCust showWaitForm(); if (custClient.add(wcfDesk) > 0) { MessageBox.Show(deskCust.custName + "新增成功!"); query(); closeWaitForm(); } else { closeWaitForm(); MessageBox.Show("新增失败"); } closeClient(); } } catch (Exception er) { closeWaitForm(); closeClient(); showErrorMsg(er.Message); } } private void btnDeleta_Click(object sender, EventArgs e) { if (!getCurrentObject()) { MessageBox.Show("请在列表里选择数据"); return; } DialogResult r = MessageBox.Show(string.Format("确定删除分播台 {0} ,店铺 {1} 吗?", deskCust.deskId, deskCust.custName), "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (r == DialogResult.No) { return; } showWaitForm(); try { if (custClient.delete(deskCust.ID) > 0) { closeWaitForm(); MessageBox.Show("删除成功"); query(); } else { MessageBox.Show("删除失败"); } closeWaitForm(); closeClient(); } catch (Exception er) { closeWaitForm(); closeClient(); showErrorMsg(er.Message); } } } }