private void btnAddProductionProcess_Click(object sender, EventArgs e) { FrmMasterSearch frm = new FrmMasterSearch("PRODUCTION_PROCESS", ""); if (frm.ShowDialog(this) == DialogResult.OK) { string strWhere = " CODE = " + "'" + frm.BaseMasterTable.Code + "'"; DataSet ds = BProductionProcess.GetList(strWhere); string departmentcode = ds.Tables[0].Rows[0]["DEPARTMENT_CODE"].ToString().Trim(); string departmentname = ds.Tables[0].Rows[0]["DEPARTMENT_NAME"].ToString().Trim(); decimal productioncycle = CConvert.ToDecimal(ds.Tables[0].Rows[0]["PRODUCTION_CYCLE"].ToString().Trim()); if (dgvData.Rows.Count > 0) { int dgvrow = dgvData.Rows.Count - 1; DateTime StartDate = CConvert.ToDateTime(dgvData.Rows[dgvrow].Cells["END_DATE"].Value.ToString()); DateTime EndDate = StartDate.AddDays(CConvert.ToDouble(productioncycle) + 0D); object[] rows = { "", frm.BaseMasterTable.Code, frm.BaseMasterTable.Name, departmentcode, departmentname, StartDate, EndDate, "", productioncycle }; dgvData.Rows.Add(rows); } else { DateTime EndDate = CConvert.ToDateTime(txtSlipDateFrom.Text).AddDays(CConvert.ToDouble(productioncycle) + 0D); object[] rows = { "", frm.BaseMasterTable.Code, frm.BaseMasterTable.Name, departmentcode, departmentname, txtSlipDateFrom.Text, EndDate, "", productioncycle }; dgvData.Rows.Add(rows); } } frm.Dispose(); }
private void btnDown_Click(object sender, EventArgs e) { if (dgvData.SelectedRows.Count <= 0) { MessageBox.Show("请先选择一行记录。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DataGridViewRow dgvr = dgvData.SelectedRows[0]; int index = dgvr.Index; if (index == dgvData.Rows.Count - 1) { MessageBox.Show("选中行己经是最后一行了。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DataGridViewRow newDgvr = (DataGridViewRow)dgvr.Clone(); for (int i = 0; i < dgvr.Cells.Count; i++) { newDgvr.Cells[i].Value = dgvr.Cells[i].Value; } dgvData.Rows.RemoveAt(index); dgvData.Rows.Insert(index + 1, newDgvr); dgvData.Rows[index + 1].Selected = true; int j = 0; foreach (DataGridViewRow dr in dgvData.Rows) { string strWhere = " CODE = " + "'" + dr.Cells["PRODUCTION_PROCESS_CODE"].Value.ToString() + "'"; DataSet ds = BProductionProcess.GetList(strWhere); decimal productioncycle = CConvert.ToDecimal(ds.Tables[0].Rows[0]["PRODUCTION_CYCLE"].ToString().Trim()); if (j != 0) { dr.Cells["START_DATE"].Value = CConvert.ToDateTime(dgvData.Rows[j - 1].Cells["END_DATE"].Value.ToString()); dr.Cells["END_DATE"].Value = CConvert.ToDateTime(dgvData.Rows[j].Cells["START_DATE"].Value.ToString()).AddDays(CConvert.ToDouble(productioncycle) + 0D); j++; } else { dr.Cells["START_DATE"].Value = txtSlipDateFrom.Text; dr.Cells["END_DATE"].Value = CConvert.ToDateTime(txtSlipDateFrom.Text).AddDays(CConvert.ToDouble(productioncycle) + 0D); j++; } } }
private void dgvData_CellValidated(object sender, DataGridViewCellEventArgs e) { DataGridViewRow dr = dgvData.Rows[e.RowIndex]; if (e.ColumnIndex == dgvData.Columns["START_DATE"].Index) { if (dr.Cells["START_DATE"].Value != null) { if (!r.IsMatch(dr.Cells["START_DATE"].Value.ToString().Trim())) { MessageBox.Show("请输入正确的日期。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dgvData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; } } } else if (e.ColumnIndex == dgvData.Columns["END_DATE"].Index) { if (dr.Cells["END_DATE"].Value != null) { if (!r.IsMatch(dr.Cells["END_DATE"].Value.ToString().Trim())) { MessageBox.Show("请输入正确的日期。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); dgvData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; } } } else if (e.ColumnIndex == dgvData.Columns["PRODUCTION_CYCLE"].Index) { int j = 0; foreach (DataGridViewRow dr1 in dgvData.Rows) { string strWhere = " CODE = " + "'" + dr.Cells["PRODUCTION_PROCESS_CODE"].Value.ToString() + "'"; DataSet ds = BProductionProcess.GetList(strWhere); decimal productioncycle = CConvert.ToDecimal(ds.Tables[0].Rows[0]["PRODUCTION_CYCLE"].ToString().Trim()); if (j != 0) { dr1.Cells["START_DATE"].Value = CConvert.ToDateTime(dgvData.Rows[j - 1].Cells["END_DATE"].Value.ToString()).AddDays(1); dr1.Cells["END_DATE"].Value = CConvert.ToDateTime(dgvData.Rows[j].Cells["START_DATE"].Value.ToString()).AddDays(CConvert.ToDouble(dgvData.Rows[j].Cells["PRODUCTION_CYCLE"].Value) + 0D); j++; } else { dr1.Cells["START_DATE"].Value = txtSlipDateFrom.Text; dr1.Cells["END_DATE"].Value = CConvert.ToDateTime(txtSlipDateFrom.Text).AddDays(CConvert.ToDouble(dgvData.Rows[0].Cells["PRODUCTION_CYCLE"].Value) + 0D); j++; } } } }
/// <summary> /// 导出 /// </summary> private void btnExport_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtCompanyCode.Text)) { MessageBox.Show("请选择公司。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(txtFilePath.Text)) { MessageBox.Show("请选择保存路径。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } BaseCompanyTable companyTable = bCompany.GetModel(txtCompanyCode.Text.Trim()); BllQuotationTable quotationTable = bQuotation.GetModel(_slipNumber); BaseCustomerTable customerTable = bCustomer.GetModel(quotationTable.CUSTOMER_CODE); report.Preview = previewControl1; DataTable dt = new DataTable(); dt.TableName = "ds"; dt.Columns.Add("i", System.Type.GetType("System.Decimal")); dt.Columns.Add("SPEC", System.Type.GetType("System.String")); dt.Columns.Add("QUANTITY", System.Type.GetType("System.Decimal")); dt.Columns.Add("PRICE", System.Type.GetType("System.Decimal")); dt.Columns.Add("DISCOUNT", System.Type.GetType("System.Decimal")); dt.Columns.Add("AMOUNT", System.Type.GetType("System.Decimal")); dt.Columns.Add("MATERIAL", System.Type.GetType("System.String")); dt.Columns.Add("MEMO", System.Type.GetType("System.String")); dt.Columns.Add("DESCRIPTION", System.Type.GetType("System.String")); dt.Columns.Add("DESCRIPTION1", System.Type.GetType("System.String")); int j = 1; foreach (BllQuotationLineTable lineModel in quotationTable.Items) { if (lineModel.PRICE_DISCOUNT.ToString().Equals("0.00")) { object[] rows = { j++, lineModel.SPEC, lineModel.QUANTITY, lineModel.PRICE, null, lineModel.AMOUNT, lineModel.METERIAL, lineModel.MEMO, lineModel.DESCRIPTION, lineModel.DESCRIPTION1 }; dt.Rows.Add(rows); } else { object[] rows = { j++, lineModel.SPEC, lineModel.QUANTITY, lineModel.PRICE, 0 - lineModel.PRICE_DISCOUNT, lineModel.AMOUNT, lineModel.METERIAL, lineModel.MEMO, lineModel.DESCRIPTION, lineModel.DESCRIPTION1 }; dt.Rows.Add(rows); } } DataSet ds = new DataSet(); ds.Tables.Add(dt); string fileName = ""; string amountName = ""; if (CConstant.LANGUAGE_CN.Equals(cboLanguage.SelectedValue)) { fileName = @"Reports\Quotation_CN.frx"; amountName = NumberConvert.NumberToChinese(CConvert.ToDouble(quotationTable.AMOUNT_INCLUDED_TAX)); } else if (CConstant.LANGUAGE_EN.Equals(cboLanguage.SelectedValue)) { fileName = @"Reports\Quotation_EN.frx"; amountName = NumberConvert.NumberToEnglish(CConvert.ToString(quotationTable.AMOUNT_INCLUDED_TAX), false); } int COUNT = 0; try { if (File.Exists(fileName)) { report.Load(fileName); report.SetParameterValue("CompanyName", companyTable.NAME); report.SetParameterValue("EnglishCompanyName", companyTable.NAME_ENGLISH); report.SetParameterValue("CompanyTel", companyTable.PHONE_NUMBER); report.SetParameterValue("CompanyFax", companyTable.FAX_NUMBER); if (fileName.Equals(@"Reports\Quotation_CN.frx")) { report.SetParameterValue("CompanyAddress", companyTable.ADDRESS_FIRST); } else { report.SetParameterValue("CompanyAddress", companyTable.ADDRESS_MIDDLE); } report.SetParameterValue("CompanyUrl", companyTable.URL); report.SetParameterValue("CompanyEmail", companyTable.EMAIL); report.SetParameterValue("SlipNumber", _slipNumber + "R" + quotationTable.VER); report.SetParameterValue("Currency", quotationTable.CURRENCY_NAME); report.SetParameterValue("CustomerName", customerTable.NAME); foreach (DataRow dr in ds.Tables[0].Rows) { if (dr["DISCOUNT"].ToString() != "") { COUNT++; } } if (COUNT > 0) { if (fileName.Equals(@"Reports\Quotation_CN.frx")) { report.SetParameterValue("DISCOUNT", "折扣"); } else { report.SetParameterValue("DISCOUNT", "Discount"); } } if (!customerTable.PHONE_NUMBER.ToString().Equals("")) { if (fileName.Equals(@"Reports\Quotation_CN.frx")) { report.SetParameterValue("CustomerTel", "电话:" + customerTable.PHONE_NUMBER); } else { report.SetParameterValue("CustomerTel", "Tel:" + customerTable.PHONE_NUMBER); } } if (!customerTable.FAX_NUMBER.ToString().Equals("")) { if (fileName.Equals(@"Reports\Quotation_CN.frx")) { report.SetParameterValue("CustomerFax", "传真:" + customerTable.FAX_NUMBER); } else { report.SetParameterValue("CustomerFax", "Fax:" + customerTable.FAX_NUMBER); } } if (!customerTable.ADDRESS_FIRST.ToString().Equals("")) { if (fileName.Equals(@"Reports\Quotation_CN.frx")) { report.SetParameterValue("CustomerAddress", "地址:" + customerTable.ADDRESS_FIRST); } else { report.SetParameterValue("CustomerAddress", "Address:" + customerTable.ADDRESS_FIRST); } } report.SetParameterValue("EnquiryMethod", quotationTable.ENQUIRY_METHOD); report.SetParameterValue("EnquiryDate", CConvert.ToDateTime(quotationTable.ENQUIRY_DATE).ToString("yyyy/MM/dd")); report.SetParameterValue("DeliveryPeriod", quotationTable.DELIVERY_PERIOD); report.SetParameterValue("DeliveryTerms", quotationTable.DELIVERY_TERMS); report.SetParameterValue("PaymentTerms", quotationTable.PAYMENT_TERMS); if (quotationTable.DISCOUNT_RATE > 0) { report.SetParameterValue("DiscountRate", "-" + quotationTable.DISCOUNT_RATE + "%"); report.SetParameterValue("DiscountAmount", quotationTable.AMOUNT_INCLUDED_TAX); } report.SetParameterValue("AmountName", amountName); report.SetParameterValue("ToCustomerMemo", quotationTable.TO_CUSTOMER_MEMO); if (companyTable.COMPANY_PICTURE != null) { MemoryStream ms = new MemoryStream((byte[])companyTable.COMPANY_PICTURE); Image image = Image.FromStream(ms); ((FastReport.PictureObject)report.FindObject("CompanyPicture")).Image = image; } if (companyTable.LOGO != null) { MemoryStream ms1 = new MemoryStream((byte[])companyTable.LOGO); Image image1 = Image.FromStream(ms1); ((FastReport.PictureObject)report.FindObject("Logo")).Image = image1; } report.RegisterData(ds); report.Prepare(); if (fileName.Equals(@"Reports\Quotation_CN.frx")) { report.Export(new FastReport.Export.Pdf.PDFExport(), this.txtFilePath.Text + "\\Quotation_CN" + _slipNumber + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"); } else { report.Export(new FastReport.Export.Pdf.PDFExport(), this.txtFilePath.Text + "\\Quotation_EN" + _slipNumber + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"); } MessageBox.Show("导出成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { Logger.Error("", ex); } }