using OfficeOpenXml; using Sunny.UI; using sunui.forms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.UI.WebControls; using System.Windows.Forms; using WMS.EnumDefine; using WMS.Untils; using WMS.yunneiWCS; using WZ.Useful.Commons; namespace WMS.UI.SynthesizeQuery { public partial class FrmPVC : UIPage { WMS.yunneiWCS.VproductStock param = new yunneiWCS.VproductStock(); WMS.yunneiWCS.paging page = new yunneiWCS.paging(); int PagesSize = 20;//每页显示多少条 List allData = new List(); private bool _IsAscOrderBy = false; public FrmPVC() { InitializeComponent(); dataGridView1.AutoGenerateColumns = false; FormHelper.DataGridViewSelfAdaptionWidth(this.dataGridView1); this.toolStripComboBox1.SelectedIndex = 1; } private void btnFind_Click(object sender, EventArgs e) { #region 判断有没有输入筛选条件 uiTextBox_positionName param.positionName = uiTextBox_positionName.Text.Trim() != "" ? uiTextBox_positionName.Text.Trim() : "";//库位名称 param.materialName = uiComboBox_materialName.Text.Trim() != "" ? uiComboBox_materialName.Text.Trim() : "";//物料名称 param.materialCode = uiComboBox_materialCode.Text.Trim() != "" ? uiComboBox_materialCode.Text.Trim() : "";//物料编码 param.containerCode = uiTextBox_containerCode.Text.Trim() != "" ? uiTextBox_containerCode.Text.Trim() : "";//托盘号 param.version = uiComboBox_version.Text.Trim() != "" ? uiComboBox_version.Text.Trim() : "";//机型 param.supplier = uiTextBox_supplier.Text.Trim() != "" ? uiTextBox_supplier.Text.Trim() : "";//供应商 page.serialNumber = uiTextBox_serialNumber.Text.Trim() != "" ? uiTextBox_serialNumber.Text.Trim() : "";//流水号 param.positionType = uiCheckBox_surplus.Checked == true ? (byte)PositionType.余料回库 : (byte)0; #endregion findData(); } /// 查找 /// /// private void findData() { try { //处理时间 page.startDateTime = this.uiDatetimePicker_start.Value; page.endDateTime = this.uiDatetimePicker_end.Value; page.IsAscOrderBy = _IsAscOrderBy; var res = FLogin.wcsWcf.findProductStock(page, param); if (res.status == 200) { if (res.dateAll == null) { ShowWarningTip(res.msg); dataGridView1.DataSource = null; return; } allData = res.dateAll.ToList(); toolStripLabel_dateTotal.Text = "总行数:" + res.totalNum + "条 "; toolStripLabel_quantity.Text = "物料总数:" + res.quantity + "件"; dataGridView1.DataSource = res.date; this.toolStripLabel5.Text = "/" + res.total; if (res.total == 1) { toolStripLabel2.Enabled = false; toolStripTextBox1.Enabled = false; toolStripLabel1.Enabled = false; toolStripLabel4.Enabled = false; toolStripLabel3.Enabled = false; } else { toolStripLabel3.Enabled = true; toolStripLabel2.Enabled = true; toolStripTextBox1.Enabled = true; toolStripLabel4.Enabled = page.pagenum == 1 ? false : true; } } else { toolStripLabel_dateTotal.Text = "总行数:0条 "; toolStripLabel_quantity.Text = "物料总数:0件"; dataGridView1.DataSource = null; ShowWarningTip("获取数据为空 - 警告"); } } catch (Exception ex) { dataGridView1.DataSource = null; ShowWarningTip("查询出错了 - 警告"); WZ.Useful.Commons.LogTextHelper.WriteLine("FrmPVC", "btnFind_Click", ex.ToString()); } } /// /// 加载下拉数据 /// private void LoadSelectData() { var fr = FLogin.wcsWcf.GetSelectList("version"); var versionList = fr.resData; this.uiComboBox_version.Items.Clear(); this.uiComboBox_version.Items.AddRange(versionList); //物料编码 var fr_materialCode = FLogin.wcsWcf.GetSelectList("materialCode"); var materialCodeList = fr_materialCode.resData; this.uiComboBox_materialCode.Items.Clear(); this.uiComboBox_materialCode.Items.AddRange(materialCodeList); //物料名称 var fr_materialName = FLogin.wcsWcf.GetSelectList("materialName"); var materialNameList = fr_materialName.resData; this.uiComboBox_materialName.Items.Clear(); this.uiComboBox_materialName.Items.AddRange(materialNameList); } private void FrmPVC_Load(object sender, EventArgs e) { this.LoadSelectData(); this.dataGridView1.AutoGenerateColumns = false; this.dataGridView1.Columns["createTime"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss"; this.dataGridView1.Columns["updateTime"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss"; uiDatetimePicker_start.Value = default(DateTime); uiDatetimePicker_end.Value = default(DateTime); uiDatetimePicker_start.Text = "起始日期"; uiDatetimePicker_end.Text = "截止日期"; page.pagenum = 1; page.pagesize = PagesSize; btnFind_Click(null, null); this.dataGridView1.ReadOnly = true; } /// 筛选数据清空 /// /// /// /// private void button1_Click(object sender, EventArgs e) { #region 判断有没有输入筛选条件 param.positionName = uiTextBox_positionName.Text = ""; param.materialName = uiComboBox_materialName.Text = ""; param.materialCode = uiComboBox_materialCode.Text = ""; param.containerCode = uiTextBox_containerCode.Text = ""; param.version = uiComboBox_version.Text = ""; param.supplier = uiTextBox_supplier.Text = ""; page.serialNumber = uiTextBox_serialNumber.Text = "";//清空流水号 uiCheckBox_surplus.Checked = false; param.positionType = (byte)PositionType.空库位; page.pagenum = 1; uiDatetimePicker_start.Value = default(DateTime); uiDatetimePicker_end.Value = default(DateTime); uiDatetimePicker_start.Text = "起始日期"; uiDatetimePicker_end.Text = "截止日期"; #endregion findData(); } /// 查看流水号 /// /// /// /// private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView1.Columns[e.ColumnIndex].Name == "operation") { int i = dataGridView1.CurrentRow.Index; string ss = dataGridView1.Rows[i].Cells["positionName"].Value.ToString(); string _materialCode = dataGridView1.Rows[i].Cells["materialCode"].Value.ToString(); if (_materialCode == "GT-KTP" || _materialCode == "GG-KTP") { ShowErrorTip("物料是空托盘,没有明细!"); return; } FrmPVClist listView = new FrmPVClist(ss, 1); listView.ShowDialog(); } else if (dataGridView1.Columns[e.ColumnIndex].Name == "delete") { int i = dataGridView1.CurrentRow.Index; string ss = dataGridView1.Rows[i].Cells["positionName"].Value.ToString(); DialogResult dr = MessageBox.Show("确认要删除库存吗", "删除库存确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { var res = FLogin.wcsWcf.deleteProduct(ss, FLogin.user.UserName); if (res.result) { ShowSuccessTip("删除库存成功!"); btnFind_Click(null, null); return; } else { ShowErrorTip("删除库存失败!" + res.resMsg); return; } } } else if (dataGridView1.Columns[e.ColumnIndex].Name == "out_store") {//出库 int i = dataGridView1.CurrentRow.Index; string positionName = dataGridView1.Rows[i].Cells["positionName"].Value.ToString(); if (positionName.IndexOf('-') < 0) { ShowErrorTip("必须是立体库库位才能操作!"); return; } if (positionName == "2-39-1" || positionName == "1-39-1" || positionName == "2-0-1" || positionName == "1-0-1") { ShowErrorTip("必须是立体库库位才能操作!"); return; } string _materialCode = dataGridView1.Rows[i].Cells["materialCode"].Value.ToString(); string _materialName = dataGridView1.Rows[i].Cells["materialName"].Value.ToString(); FrmHandOutStore frm = new FrmHandOutStore(positionName, _materialCode, _materialName); frm.ShowDialog(); btnFind_Click(null, null); } } catch (Exception ex) { } } /// 第一页 /// /// /// /// private void toolStripLabel4_Click(object sender, EventArgs e) { try { page.pagenum = 1; findData(); toolStripLabel4.Enabled = false; toolStripLabel3.Enabled = true; toolStripTextBox1.Text = "1"; toolStripTextBox1.Enabled = true; toolStripLabel1.Enabled = false; toolStripLabel2.Enabled = true; } catch (Exception) { } } /// 上一页 /// /// /// /// private void toolStripLabel1_Click(object sender, EventArgs e) { try { int numPapg = 0; int.TryParse(toolStripTextBox1.Text.Trim(), out numPapg); numPapg--; toolStripTextBox1.Text = numPapg.ToString(); int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); if (numPapg <= sizetatol) { page.pagenum = numPapg; findData(); toolStripLabel2.Enabled = true; toolStripLabel3.Enabled = true; if (numPapg == 1) { toolStripLabel1.Enabled = false; } } else { toolStripTextBox1.Text = "1"; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请输入数字,并大于1且不大于总页数"); ms.Show(); } } catch (Exception) { } } /// 下一页 /// /// /// /// private void toolStripLabel2_Click(object sender, EventArgs e) { try { int numPapg = 0; int.TryParse(toolStripTextBox1.Text.Trim(), out numPapg); numPapg++; toolStripTextBox1.Text = numPapg.ToString(); int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); toolStripLabel4.Enabled = true; if (numPapg <= sizetatol) { page.pagenum = numPapg; findData(); toolStripLabel1.Enabled = true; if (numPapg == sizetatol) { toolStripLabel2.Enabled = false; } } else { toolStripTextBox1.Text = "1"; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请输入数字,并大于1且不大于总页数"); ms.Show(); } } catch (Exception) { } } /// 最后一页 /// /// /// /// private void toolStripLabel3_Click(object sender, EventArgs e) { try { int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); page.pagenum = sizetatol; findData(); toolStripLabel3.Enabled = false; toolStripLabel4.Enabled = true; toolStripTextBox1.Text = sizetatol.ToString(); toolStripTextBox1.Enabled = true; toolStripLabel1.Enabled = true; toolStripLabel2.Enabled = false; } catch (Exception) { } } /// 输入第几页 /// /// /// /// private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { int numPapg = 0; int.TryParse(toolStripTextBox1.Text.Trim(), out numPapg); int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); if (numPapg > 0 && numPapg <= sizetatol) { page.pagenum = numPapg; findData(); if (numPapg == 1) { toolStripLabel1.Enabled = false; toolStripLabel4.Enabled = false; toolStripLabel3.Enabled = true; toolStripLabel2.Enabled = true; } if (numPapg == sizetatol) { toolStripLabel1.Enabled = true; toolStripLabel4.Enabled = true; toolStripLabel3.Enabled = false; toolStripLabel2.Enabled = false; } } else { toolStripTextBox1.Text = "1"; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请输入数字,并不大于总页数"); ms.Show(); } } } catch (Exception) { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "出错了"); ms.Show(); } } /// 每页数量发生改变时 /// /// /// /// private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { page.pagesize = (toolStripComboBox1.SelectedIndex + 1) * 10; page.pagenum = 1; findData(); toolStripTextBox1.Text = "1"; } catch (Exception) { } } /// 增加序号 /// /// /// /// private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { SolidBrush b = new SolidBrush(this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor); e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4); } private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { DataGridView dgv = (DataGridView)sender; try { switch (dgv.Columns[e.ColumnIndex].Name) { case "islock": if ((bool)e.Value == true) { e.CellStyle.BackColor = Color.FromArgb(255, 140, 105); e.CellStyle.ForeColor = Color.FromArgb(255, 255, 255); } e.Value = (bool)e.Value == true ? "锁定" : "未锁定"; break; case "positionType": int value = Convert.ToInt32(e.Value); int typeValue = (int)PositionType.余料回库; if (value == typeValue) { e.CellStyle.BackColor = Color.FromArgb(238, 180, 34); e.CellStyle.ForeColor = Color.FromArgb(255, 255, 255); e.Value = "是"; } else { e.Value = "否"; } break; default: break; } } catch (Exception) { } } /// 余料回库赛选 /// /// /// /// private void uiCheckBox_surplus_CheckedChanged(object sender, EventArgs e) { param.positionType = uiCheckBox_surplus.Checked == true ? (byte)PositionType.余料回库 : (byte)0; btnFind_Click(null, null); } /// 开始时间改变 /// /// /// /// private void uiDatetimePicker_start_ValueChanged(object sender, DateTime value) { //if (uiDatetimePicker_start.Value != startDateTime) //{ // page.startDateTime = uiDatetimePicker_start.Value; //} //else //{ // page.startDateTime = new DateTime(); //} } /// 结束时间改变 /// /// /// /// private void uiDatetimePicker_end_ValueChanged(object sender, DateTime value) { //if (uiDatetimePicker_end.Value != endDateTime) //{ // page.endDateTime = uiDatetimePicker_end.Value; //} //else //{ // page.startDateTime = new DateTime(); //} } /// 导出数据 /// /// /// /// private void uiSymbolButton5_Click(object sender, EventArgs e) { try { if (allData.Count > 0) { string path = @"D:\exprotdata\库存数据" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".xlsx"; FileInfo copyFile = new FileInfo(path); if (!Directory.Exists(Path.GetDirectoryName(path))) Directory.CreateDirectory(Path.GetDirectoryName(path)); using (ExcelPackage package = new ExcelPackage(copyFile)) { //获取模板内容 #region MyRegion ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("出入库统计"); #region 设置表头 worksheet.Cells["A1:E1"].Merge = true; worksheet.Cells[1, 1].Value = "立库库存数据 " + toolStripLabel_dateTotal.Text + toolStripLabel_quantity.Text; worksheet.Cells[2, 1].Value = "库位名称"; worksheet.Cells[2, 2].Value = "物料编码"; worksheet.Cells[2, 3].Value = "物料名称"; worksheet.Cells[2, 4].Value = "机型"; worksheet.Cells[2, 5].Value = "供应商"; worksheet.Cells[2, 6].Value = "数量"; worksheet.Cells[2, 7].Value = "托盘号"; worksheet.Cells[2, 8].Value = "创建时间"; worksheet.Cells[2, 9].Value = "是否余料"; worksheet.Cells[2, 10].Value = "是否锁定"; #endregion if (allData.Count > 0) { for (int i = 0; i < allData.Count; i++) { worksheet.Cells[i + 3, 1].Value = allData[i].positionName; worksheet.Cells[i + 3, 2].Value = allData[i].materialCode; worksheet.Cells[i + 3, 3].Value = allData[i].materialName; worksheet.Cells[i + 3, 4].Value = allData[i].version; worksheet.Cells[i + 3, 5].Value = allData[i].supplier; worksheet.Cells[i + 3, 6].Value = allData[i].quantity; worksheet.Cells[i + 3, 7].Value = allData[i].containerCode; worksheet.Cells[i + 3, 8].Value = allData[i].createTime; worksheet.Cells[i + 3, 9].Value = allData[i].positionType == (byte)PositionType.余料回库 ? "是" : "否"; worksheet.Cells[i + 3, 10].Value = allData[i].isLock == true ? "是" : "否"; } } #endregion package.Save();//保存 } System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(path)); ShowSuccessTip("库存数据导出- 成功"); } else { ShowErrorTip("数据为空不能导出- 错误"); } } catch (Exception) { } } private void uiComboBox_version_SelectedIndexChanged(object sender, EventArgs e) { btnFind_Click(null, null); } private void uiComboBox_materialCode_SelectedIndexChanged(object sender, EventArgs e) { btnFind_Click(null, null); } private void uiComboBox_materialName_SelectedIndexChanged(object sender, EventArgs e) { btnFind_Click(null, null); } private void uiCheckBox_OrderBy_CheckedChanged(object sender, EventArgs e) { if (this.uiCheckBox_OrderBy.Checked) {//正序,就是时间最早的排在最上面 _IsAscOrderBy = true; } else {//倒序 _IsAscOrderBy = false; } btnFind_Click(null, null); } } }