/// <summary> /// 自定义绘制单元格值。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gvResult_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (e.Column == this.gclRowNum) { e.DisplayText = Convert.ToString(e.RowHandle + 1); } else if (e.Column == this.gclCsDataGroup) { PalletState state = (PalletState)Convert.ToInt32(e.CellValue); e.DisplayText = CommonUtils.GetEnumValueDescription(state); } }
/// <summary> /// 导出明细数据到EXCEL。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbExportDetail_Click(object sender, EventArgs e) { StringBuilder sbPalletNo = new StringBuilder(); DataTable dt = this.gcPallet.DataSource as DataTable; foreach (DataRow dr in dt.Rows) { sbPalletNo.AppendFormat("{0},", dr[WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO]); } Hashtable htParams = new Hashtable(); DataSet dsParams = new DataSet(); htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO, sbPalletNo.ToString().TrimEnd(',')); DataTable dtParams = CommonUtils.ParseToDataTable(htParams); dtParams.TableName = TRANS_TABLES.TABLE_MAIN_DATA; dsParams.Tables.Add(dtParams); DataSet dsReturn = this._entity.QueryDetail(dsParams); if (!string.IsNullOrEmpty(this._entity.ErrorMsg)) { MessageService.ShowMessage(this._entity.ErrorMsg); return; } SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Excel文件(*.xls)|*.xls"; dlg.FilterIndex = 1; dlg.RestoreDirectory = true; List <string> lst = new List <string>(); if (dlg.ShowDialog() == DialogResult.OK) { DataTable dtReturn = dsReturn.Tables[0]; //StringBuilder sbFieldNames = new StringBuilder(); foreach (GridColumn gc in this.gvPallet.Columns) { if (dtReturn.Columns.Contains(gc.FieldName)) { dtReturn.Columns[gc.FieldName].Caption = gc.Caption; if (gc.FieldName == this.gcolPalletNo.FieldName) { lst.Insert(0, gc.FieldName); } else { lst.Add(gc.FieldName); } } } foreach (GridColumn gc in this.gvPalletDetail.Columns) { if (dtReturn.Columns.Contains(gc.FieldName)) { dtReturn.Columns[gc.FieldName].Caption = gc.Caption; if (gc.FieldName == this.gcolLotNumber.FieldName) { lst.Insert(1, gc.FieldName); } else { lst.Add(gc.FieldName); } } } for (int i = 0; i < dtReturn.Rows.Count; i++) { DataRow dr = dsReturn.Tables[0].Rows[i]; string grade = Convert.ToString(dr[WIP_CONSIGNMENT_FIELDS.FIELDS_GRADE]); dr[WIP_CONSIGNMENT_FIELDS.FIELDS_GRADE] = GetProductGradeDisplayText(grade); object val = dr[WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP]; PalletState state = (PalletState)Convert.ToInt32(val); dr[WIP_CONSIGNMENT_FIELDS.FIELDS_GRADE] = GetProductGradeDisplayText(grade); dr[WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP] = CommonUtils.GetEnumValueDescription(state); } //string fileNames = sbFieldNames.ToString().TrimEnd(','); Export.ExportToExcel(dlg.FileName, dtReturn.DefaultView.ToTable(false, lst.ToArray())); } }
/// <summary> /// 绑定托盘信息。 /// </summary> private void BindPalletInfo() { PalletQueryConditionModel model = this.Model; Hashtable htParams = new Hashtable(); DataSet dsParams = new DataSet(); //车间主键。 htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_ROOM_KEY, model.RoomKey); //批次号不为空 if (!string.IsNullOrEmpty(model.PalletNo1) && !string.IsNullOrEmpty(model.PalletNo)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO + "_START", model.PalletNo); htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO + "_END", model.PalletNo1); } //批次号不为空 else if (!string.IsNullOrEmpty(model.PalletNo)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_VIRTUAL_PALLET_NO, model.PalletNo); } //工单号不为空 if (!string.IsNullOrEmpty(model.WorkOrderNumber)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_WORKNUMBER, model.WorkOrderNumber); } //产品ID号不为空 if (!string.IsNullOrEmpty(model.ProId)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_PRO_ID, model.ProId); } //产品料号不为空 if (!string.IsNullOrEmpty(model.PartNumber)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_SAP_NO, model.PartNumber); } //状态不为空 if (!string.IsNullOrEmpty(model.StateFlag)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP, model.StateFlag); } //创建日期-起不为空 if (!string.IsNullOrEmpty(model.StartCreateDate)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_CREATE_TIME + "_START", model.StartCreateDate); } //创建日期-止不为空 if (!string.IsNullOrEmpty(model.EndCreateDate)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_CREATE_TIME + "_END", model.EndCreateDate); } //入库检日期-起不为空 if (!string.IsNullOrEmpty(model.StartCheckDate)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_CHECK_TIME + "_START", model.StartCheckDate); } //入库检日期-止不为空 if (!string.IsNullOrEmpty(model.EndCheckDate)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_CHECK_TIME + "_END", model.EndCheckDate); } //入库日期-起不为空 if (!string.IsNullOrEmpty(model.StartTowarehouseDate)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_TO_WH_TIME + "_START", model.StartTowarehouseDate); } //入库日期-止不为空 if (!string.IsNullOrEmpty(model.EndTowarehouseDate)) { htParams.Add(WIP_CONSIGNMENT_FIELDS.FIELDS_TO_WH_TIME + "_END", model.EndTowarehouseDate); } DataTable dtParams = CommonUtils.ParseToDataTable(htParams); dtParams.TableName = TRANS_TABLES.TABLE_MAIN_DATA; dsParams.Tables.Add(dtParams); //查询批次 PagingQueryConfig config = new PagingQueryConfig() { PageNo = pgnQueryResult.PageNo, PageSize = pgnQueryResult.PageSize }; DataSet dsReturn = _entity.Query(dsParams, ref config); pgnQueryResult.Pages = config.Pages; pgnQueryResult.Records = config.Records; if (!string.IsNullOrEmpty(_entity.ErrorMsg)) { MessageService.ShowMessage(_entity.ErrorMsg); return; } if (dsReturn.Tables.Count > 0) { dsReturn.Tables[0].Columns.Add("ROW_NUM", typeof(Decimal)); for (int i = 0; i < dsReturn.Tables[0].Rows.Count; i++) { DataRow dr = dsReturn.Tables[0].Rows[i]; dr["ROW_NUM"] = i + 1; string grade = Convert.ToString(dr[WIP_CONSIGNMENT_FIELDS.FIELDS_GRADE]); dr[WIP_CONSIGNMENT_FIELDS.FIELDS_GRADE] = GetProductGradeDisplayText(grade); object val = dr[WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP]; PalletState state = (PalletState)Convert.ToInt32(val); dr[WIP_CONSIGNMENT_FIELDS.FIELDS_GRADE] = GetProductGradeDisplayText(grade); dr[WIP_CONSIGNMENT_FIELDS.FIELDS_CS_DATA_GROUP] = CommonUtils.GetEnumValueDescription(state); } gcPallet.DataSource = dsReturn.Tables[0]; gcPallet.MainView = gvPallet; gvPallet.BestFitColumns(); } }