/// <summary> /// 采购清单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPurchaseList_Click(object sender, EventArgs e) { string slipNumbers = ""; foreach (DataGridViewRow dr in dgvData.Rows) { if (CConvert.ToBoolean(dr.Cells["CHK"].Value)) { slipNumbers = CConvert.ToString(dr.Cells["SLIP_NUMBER"].Value) + ","; } } if (slipNumbers.Length > 0) { slipNumbers = slipNumbers.Substring(0, slipNumbers.Length - 1); } else { MessageBox.Show("请先选择订单。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog sf = new SaveFileDialog(); sf.FileName = "HD_PURCHASE_PLAN_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; sf.Filter = "(文件)|*.xls;*.xlsx"; if (sf.ShowDialog(this) == DialogResult.OK) { } }
/// <summary> /// 绑定TreeView /// </summary> private void Bind_Tv(DataTable currentRoles) { DataTable dt = CCacheData.Function.Copy(); dt.Columns.Add("checked", Type.GetType("System.Boolean")); //数据处理 foreach (DataRow dr in dt.Rows) { dr["checked"] = false; foreach (DataRow row in currentRoles.Rows) { if (CConvert.ToString(dr["function_code"]) == CConvert.ToString(row["function_code"])) { dr["checked"] = true; break; } } } //绑定 TreeNode pNode = null; TreeNode cNode = null; string pCode = ""; foreach (DataRow dr in dt.Rows) { if (pCode != CConvert.ToString(dr["code"])) { if (pCode == "") { pNode = new TreeNode(); } else { pNode.ExpandAll(); tvFunction.Nodes.Add(pNode); pNode = new TreeNode(); } pCode = CConvert.ToString(dr["code"]); pNode.Tag = pCode; pNode.Text = CConvert.ToString(dr["name"]); pNode.Checked = CConvert.ToBoolean(dr["checked"]); } cNode = new TreeNode(); cNode.Tag = CConvert.ToString(dr["function_code"]); cNode.Text = CConvert.ToString(dr["title"]) + " " + CConvert.ToString(dr["memo"]); cNode.Checked = CConvert.ToBoolean(dr["checked"]); if (pNode.Checked) { pNode.Checked = CConvert.ToBoolean(dr["checked"]); } pNode.Nodes.Add(cNode); } if (pNode != null) { pNode.ExpandAll(); tvFunction.Nodes.Add(pNode); } }
/// <summary> /// 生产物料清单 /// </summary> private void btnPrint_Click(object sender, EventArgs e) { string slipNumbers = ""; foreach (DataGridViewRow dr in dgvData.Rows) { if (CConvert.ToBoolean(dr.Cells["CHK"].Value)) { slipNumbers += "'" + CConvert.ToString(dr.Cells["SLIP_NUMBER"].Value) + "',"; } } if (slipNumbers.Length > 0) { slipNumbers = slipNumbers.Substring(0, slipNumbers.Length - 1); } else { MessageBox.Show("请先选择订单。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog sf = new SaveFileDialog(); sf.FileName = "HD_BOM_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; sf.Filter = "(文件)|*.xls;*.xlsx"; if (sf.ShowDialog(this) == DialogResult.OK) { DataTable dt = bProduce.GetBomList(slipNumbers).Tables[0]; int i = 1; _bomDt.Rows.Clear(); DataRow dr = null; foreach (DataRow row in dt.Rows) { dr = _bomDt.NewRow(); dr["序号"] = i++; dr["规格/参数"] = row["CODE"]; dr["名称"] = row["NAME"]; dr["数量"] = CConvert.ToDecimal(row["QUANTITY"]); dr["备注"] = ""; _bomDt.Rows.Add(dr); } CExport.DataTableToExcel_BOM(sf.FileName, _bomDt); MessageBox.Show("导出完成。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private string GetSelectSlipNumbers() { string slipNumbers = ""; //订单编号的取得 foreach (DataGridViewRow dr in dgvData.Rows) { if (CConvert.ToBoolean(dr.Cells["CHK"].Value)) { slipNumbers += "'" + CConvert.ToString(dr.Cells["SLIP_NUMBER"].Value) + "',"; } } if (slipNumbers.Length > 0) { slipNumbers = slipNumbers.Substring(0, slipNumbers.Length - 1); } else { MessageBox.Show("请先选择订单。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(slipNumbers); }
private void dgvData_CellClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex == dgvData.Columns["BTN_DELETE"].Index) { if (MessageBox.Show("确定要删除当前行吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK) { if (dgvData.Rows.Count != 1) { dgvData.Rows.Remove(dgvData.Rows[e.RowIndex]); } else { dgvData.Rows.Remove(dgvData.Rows[e.RowIndex]); dgvData.Rows.Add(1); } CalculateAmount(); } } else if (e.ColumnIndex == dgvData.Columns["BTN_CODE"].Index) { FrmMasterSearch frm = new FrmMasterSearch("SLIP_TYPE", ""); if (frm.ShowDialog(this) == DialogResult.OK) { if (frm.BaseMasterTable != null) { dgvData.Rows[e.RowIndex].Cells["CODE"].Value = frm.BaseMasterTable.Code; dgvData.Rows[e.RowIndex].Cells["NAME"].Value = frm.BaseMasterTable.Name; dgvData.Rows[e.RowIndex].Cells["METERIAL"].Value = "铸钢(ZG270-500)"; dgvData.Rows[e.RowIndex].Cells["SPEC"].Selected = true; NewRow(); } } frm.Dispose(); } else if (e.ColumnIndex == dgvData.Columns["BTN_METERIAL"].Index) { FrmMasterSearch frm = new FrmMasterSearch("MATERIAL", ""); if (frm.ShowDialog(this) == DialogResult.OK) { if (frm.BaseMasterTable != null) { //dgvData.Rows[e.RowIndex].Cells["CODE"].Value = frm.BaseMasterTable.Code; dgvData.Rows[e.RowIndex].Cells["METERIAL"].Value = frm.BaseMasterTable.Name; NewRow(); } } frm.Dispose(); } else if (e.ColumnIndex == dgvData.Columns["BTN_PARTS_CODE"].Index) { bool b = CConvert.ToBoolean(this.dgvData.Rows[e.RowIndex].Cells["checkboxflag"].Value); if (b) { string str = dgvData.Rows[e.RowIndex].Cells["CODE"].Value.ToString(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("SLIP_TYPE_CODE = '{0}'", str); FrmMasterSearch frm = new FrmMasterSearch("SLIP_TYPE_COMPOSITION_PRODUCTS_VIEW", sb.ToString()); if (frm.ShowDialog(this) == DialogResult.OK) { if (frm.BaseMasterTable != null) { dgvData.Rows[e.RowIndex].Cells["COMPOSITION_PRODUCTS_CODE"].Value = frm.BaseMasterTable.Code; dgvData.Rows[e.RowIndex].Cells["COMPOSITION_PRODUCTS_NAME"].Value = frm.BaseMasterTable.Name; if (dgvData.Rows.Count > 1) { if (dgvData.Rows[e.RowIndex].Cells["COMPOSITION_PRODUCTS_NAME"].Value.ToString() != "") { dgvData.Rows[e.RowIndex].Cells["SPEC"].Value = dgvData.Rows[e.RowIndex - 1].Cells["SPEC"].Value; dgvData.Rows[e.RowIndex].Cells["DESCRIPTION"].Value = dgvData.Rows[e.RowIndex - 1].Cells["DESCRIPTION"].Value; } } NewRow(); } } frm.Dispose(); } } } catch { } }
/// <summary> /// 自动采购 /// </summary> private void btnAutoPurchase_Click(object sender, EventArgs e) { string slipNumbers = ""; //订单编号的取得 foreach (DataGridViewRow dr in dgvData.Rows) { if (CConvert.ToBoolean(dr.Cells["CHK"].Value)) { slipNumbers += "'" + CConvert.ToString(dr.Cells["SLIP_NUMBER"].Value) + "',"; } } if (slipNumbers.Length > 0) { slipNumbers = slipNumbers.Substring(0, slipNumbers.Length - 1); } else { MessageBox.Show("请先选择订单。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //采购清单的取得 DataTable poDt = bPurchaseOrder.GetAutoPurchaseList(slipNumbers, rdoNetPurchase.Checked).Tables[0]; //数据的整理 List <BllPurchaseOrderTable> poList = new List <BllPurchaseOrderTable>(); BllPurchaseOrderTable poTable = null; BllPurchaseOrderLineTable polTable = null; DateTime currentTime = DateTime.Now; decimal total = 0; int i = 1; string currentSupplier = ""; foreach (DataRow row in poDt.Rows) { if ("".Equals(currentSupplier) || !currentSupplier.Equals(row["BASIC_SUPPLIER"])) { if (!"".Equals(currentSupplier)) { poTable.TOTAL_AMOUNT = total; poList.Add(poTable); total = 0; i = 1; } poTable = new BllPurchaseOrderTable(); poTable.SLIP_TYPE = CConstant.PURCHASE_NEED; poTable.SLIP_DATE = currentTime; poTable.DUE_DATE = currentTime.AddDays(CConstant.DEFAULT_LEAD_TIME); poTable.SUPPLIER_CODE = CConvert.ToString(row["BASIC_SUPPLIER"]); poTable.ORDER_SLIP_NUMBER = ""; poTable.SUPPLIER_ORDER_NUMBER = ""; poTable.CURRENCY_CODE = CConstant.DEFAULT_CURRENCY_CODE; poTable.TAX_RATE = CConstant.DEFAULT_RATE; poTable.RECEIPT_WAREHOUSE_CODE = CConstant.DEFAULT_WAREHOUSE_CODE; poTable.STATUS_FLAG = CConstant.INIT; poTable.CREATE_USER = _userInfo.CODE; poTable.LAST_UPDATE_USER = _userInfo.CODE; poTable.COMPANY_CODE = _userInfo.COMPANY_CODE; } currentSupplier = CConvert.ToString(row["BASIC_SUPPLIER"]); polTable = new BllPurchaseOrderLineTable(); polTable.LINE_NUMBER = i++; polTable.PRODUCT_CODE = CConvert.ToString(row["PRODUCT_CODE"]); polTable.QUANTITY = CConvert.ToDecimal(row["QUANTITY"]); polTable.UNIT_CODE = CConvert.ToString(row["BASIC_UNIT_CODE"]); polTable.PRICE = CConvert.ToDecimal(row["PURCHASE_PRICE"]); polTable.AMOUNT_WITHOUT_TAX = polTable.QUANTITY * polTable.PRICE; polTable.TAX_AMOUNT = CConvert.ToDecimal(poTable.TAX_RATE) * polTable.AMOUNT_WITHOUT_TAX; polTable.AMOUNT_INCLUDED_TAX = polTable.AMOUNT_WITHOUT_TAX + polTable.TAX_AMOUNT; polTable.STATUS_FLAG = CConstant.INIT; total += polTable.AMOUNT_INCLUDED_TAX; poTable.TOTAL_AMOUNT = total; poTable.AddItem(polTable); } if (poTable != null) { poList.Add(poTable); } //订单分组采购清单的取得,用于记录本次采购的原材料数量 DataTable historyDt = bPurchaseOrder.GetAutoPurchaseList(slipNumbers).Tables[0]; List <BllOrderLineProductPartsTable> olppList = new List <BllOrderLineProductPartsTable>(); BllOrderLineProductPartsTable olppTable = null; foreach (DataRow dr in historyDt.Rows) { olppTable = new BllOrderLineProductPartsTable(); olppTable.ORDER_SLIP_NUMBER = CConvert.ToString(dr["SLIP_NUMBER"]); olppTable.PRODUCT_CODE = CConvert.ToString(dr["PRODUCT_CODE"]); olppTable.QUANTITY = CConvert.ToDecimal(dr["QUANTITY"]); olppTable.STATUS_FLAG = CConstant.INIT; olppTable.CREATE_USER = _userInfo.CODE; olppTable.LAST_UPDATE_USER = _userInfo.CODE; olppList.Add(olppTable); } //数据保存 try { if (bPurchaseOrder.AutoPurchase(poList, olppList, slipNumbers) > 0) { MessageBox.Show("自动采购成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); btnSearch_Click(null, EventArgs.Empty); } else { MessageBox.Show("自动采购失败,请重试或与管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("自动采购失败,请重试或与管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); Logger.Error("自动采购失败。", ex); } }