///// <summary> ///// 导出表格数据 ///// </summary> //private void print() //{ // //导出到execl // try // { // DevExpress.XtraGrid.Views.Grid.GridView gvExport = this.gvWipConsigment; // SaveFileDialog saveExcelDialog = new SaveFileDialog(); // string fieldpath = string.Empty, fileNameExt = string.Empty; // saveExcelDialog.Filter = "excel文件(*.xls)|*.xls"; // saveExcelDialog.DefaultExt = "xls"; // saveExcelDialog.InitialDirectory = Directory.GetCurrentDirectory(); // saveExcelDialog.RestoreDirectory = true; // if (DialogResult.OK == saveExcelDialog.ShowDialog()) // { // int rowscount = gvExport.RowCount; // int colscount = gvExport.Columns.Count; // if (rowscount > 65536) // { // MessageBox.Show("数据记录数太多(最多不能超过65536条),不能保存", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // //列数不可以大于255 // if (colscount > 255) // { // MessageBox.Show("数据记录行数太多,不能保存", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // fieldpath = saveExcelDialog.FileName; // fileNameExt = fieldpath.Substring(fieldpath.LastIndexOf("\\") + 1); // //验证以fileNameString命名的文件是否存在,如果存在删除它 // FileInfo file = new FileInfo(fieldpath); // if (file.Exists) // { // try // { // file.Delete(); // } // catch (Exception error) // { // MessageBox.Show(error.Message, "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } // } // Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application(); // Microsoft.Office.Interop.Excel.Workbook objWorkbook = objExcel.Workbooks.Add(Missing.Value); // Microsoft.Office.Interop.Excel.Worksheet objsheet = (Microsoft.Office.Interop.Excel.Worksheet)objWorkbook.ActiveSheet; // try // { // //设置EXCEL不可见 // objExcel.Visible = false; // //向Excel中写入表格的表头 // int displayColumnsCount = 1; // for (int i = 0; i < gvExport.Columns.Count; i++) // { // if (gvExport.Columns[i].Visible == true) // { // string tmp = gvExport.Columns[i].Caption; // //objExcel.Cells[1, displayColumnsCount] = tmp; // objsheet.Cells[1, displayColumnsCount] = tmp; // displayColumnsCount++; // } // } // System.Windows.Forms.ProgressBar tempProgressBar = new System.Windows.Forms.ProgressBar(); // //设置进度条 // tempProgressBar.Refresh(); // tempProgressBar.Visible = true; // tempProgressBar.Minimum = 1; // tempProgressBar.Maximum = gvExport.RowCount; // tempProgressBar.Step = 1; // //向Excel中逐行逐列写入表格中的数据 // for (int row = 0; row < gvExport.RowCount; row++) // { // tempProgressBar.PerformStep(); // displayColumnsCount = 1; // for (int col = 0; col < colscount; col++) // { // if (gvExport.Columns[col].Visible == true) // { // objsheet.Cells[row + 2, displayColumnsCount] = gvExport.GetRowCellValue(row, gvExport.Columns[col].FieldName).ToString().Trim(); // displayColumnsCount++; // } // } // } // //隐藏进度条 // tempProgressBar.Visible = false; // //保存文件 // objWorkbook.SaveAs(fieldpath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, // Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, Missing.Value, Missing.Value, Missing.Value, // Missing.Value, Missing.Value); // } // catch (Exception error) // { // MessageBox.Show(error.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } // finally // { // //关闭Excel应用 // if (objWorkbook != null) objWorkbook.Close(Missing.Value, Missing.Value, Missing.Value); // if (objExcel.Workbooks != null) objExcel.Workbooks.Close(); // if (objExcel != null) objExcel.Quit(); // objsheet = null; // objWorkbook = null; // objExcel = null; // } // MessageBox.Show(fieldpath + "\n\n导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // } // catch (Exception ex) // { // MessageBox.Show(ex.Message, "错误提示"); // } //} /// <summary> /// 入库检返到包装事件。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tbnBackPackage_Click(object sender, EventArgs e) { if (!InitPackageData()) { this.txtPalletNo.Select(); this.txtPalletNo.SelectAll(); return; } if (MessageService.AskQuestionSpecifyNoButton(string.Format("是否将托盘{0}返回到包装重新包装?", this.txtPalletNo.Text), "询问")) { RejectPackageData(); } }
private void btSubmit_Click(object sender, EventArgs e) { //if (THreadGet) //{ // MessageService.ShowMessage("数据接收中......"); // return; //} string isHold = "false"; DataTable saveTable = _edcData.BuildTable(EDC_COLLECTION_DATA_FIELDS.DATABASE_TABLE_NAME); int saveRowCount = 0; for (int i = 1; i < tablePanel.RowCount; i++) { LabelControl lblCtrl = (LabelControl)tablePanel.Controls.Find("lblParam" + i.ToString("00"), true)[0]; string paramKey = lblCtrl.Tag.ToString(); for (int j = 1; j <= Convert.ToInt32(dsParam.Tables[0].Rows[i - 1][EDC_POINT_PARAMS_FIELDS.FIELD_PARAM_COUNT]); j++) { TextEdit textEdit = tablePanel.Controls.Find("txtBox" + i.ToString() + j.ToString(), true)[0] as TextEdit; if (textEdit.Tag.ToString().Substring(0, 1) == _edcData.DataType) { if (textEdit.Tag.ToString().Substring(1, 1) != "R" && textEdit.Text != string.Empty) { string validFlag = string.Empty; if (textEdit.BackColor == Color.Red) { validFlag = "1"; isHold = "true"; } else { validFlag = "0"; } string result = CheckUpdateOrInsert(paramKey, j.ToString(), textEdit.Text); switch (result) { case "no": break; case "new": saveTable.Rows.Add(saveRowCount); saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_SP_SAMP_SEQ] = "1"; saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_SP_UNIT_SEQ] = j.ToString(); saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_PARAM_KEY] = paramKey; saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_PARAM_VALUE] = textEdit.Text; saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_EDC_INS_KEY] = edcInsKey; saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_COL_KEY] = string.Empty; saveTable.Rows[saveRowCount][EDC_COLLECTION_DATA_FIELDS.FIELD_VALID_FLAG] = validFlag; saveTable.Rows[saveRowCount][COMMON_FIELDS.FIELD_COMMON_OPERATION_ACTION] = "New"; saveRowCount++; break; case "update": break; default: break; } } } } } LotEDCEntity edcEntity = new LotEDCEntity(); DataSet dsSave = new DataSet(); if (saveTable.Rows.Count > 0) { dsSave.Tables.Add(saveTable); } string question = string.Empty; if (isHold == "false") { question = "确定要提交数据吗?"; } else { question = "数据超出范围,批次将被锁定。确定要保存数据吗?"; } if (MessageService.AskQuestionSpecifyNoButton(question)) { this.btSubmit.Enabled = false; int RCount = GetRecord(); edcEntity.Operator = _edcData.StaffNumber; edcEntity.SaveEDCPause(dsSave, RCount, lotKey, edcInsKey, isHold); if (edcEntity.ErrorMsg == "") { BindInitialData(); _edcData.UpdateSHRDataToSqlServer(shrTable_Q); MessageService.ShowMessage("保存成功。"); } else { MessageService.ShowError(edcEntity.ErrorMsg); } } }