Ejemplo n.º 1
0
        private void btnSupplierFax_Click(object sender, EventArgs e)
        {
            if (dgvData.SelectedRows.Count > 0)
            {
                Hashtable       ht  = new Hashtable();
                DataTable       dt  = new DataTable();
                DataGridViewRow row = dgvData.SelectedRows[0];

                BllPurchaseOrderTable purchase = bPurchaseOrder.GetModel(CConvert.ToString(row.Cells["SLIP_NUMBER"].Value));
                BaseSupplierTable     supplier = bSupplier.GetModel(CConvert.ToString(row.Cells["SUPPLIER_CODE"].Value));
                if (purchase == null)
                {
                    purchase = new BllPurchaseOrderTable();
                }
                if (supplier == null)
                {
                    supplier = new BaseSupplierTable();
                }
                ht.Add("&SUPPLIER", supplier.NAME);
                ht.Add("&CONTACT_NAME", supplier.CONTACT_NAME);
                ht.Add("&MOBIL_NUMBER", supplier.MOBIL_NUMBER);
                ht.Add("&PHONE_NUMBER", supplier.PHONE_NUMBER);
                ht.Add("&FAX_NUMBER", supplier.FAX_NUMBER);
                ht.Add("&SLIP_NUMBER", purchase.SLIP_NUMBER);
                ht.Add("&SLIP_DATE", purchase.SLIP_DATE);
                ht.Add("&DUE_DATE", purchase.DUE_DATE);

                dt.Columns.Add("No");
                dt.Columns.Add("SPEC");
                dt.Columns.Add("NAME");
                dt.Columns.Add("UNIT_NAME");
                dt.Columns.Add("QUANTITY");
                dt.Columns.Add("PRICE");
                dt.Columns.Add("TOTAL_AMOUNT");
                dt.Columns.Add("APPLICATION");
                dt.Columns.Add("MEMO");

                DataRow rows  = null;
                int     i     = 0;
                string  name  = "";
                decimal TOTAL = 0;
                foreach (BllPurchaseOrderLineTable POLTable in purchase.Items)
                {
                    rows       = dt.NewRow();
                    rows["No"] = POLTable.LINE_NUMBER;
                    BaseProductTable product = bProduct.GetModel(POLTable.PRODUCT_CODE);
                    if (product != null)
                    {
                        rows["SPEC"] = product.CODE;
                        rows["NAME"] = product.NAME;
                        if (i == 0)
                        {
                            name = product.NAME;
                        }
                        if (bCommon.GetBaseMaster("UNIT", POLTable.UNIT_CODE) != null)
                        {
                            rows["UNIT_NAME"] = bCommon.GetBaseMaster("UNIT", POLTable.UNIT_CODE).Name;
                        }
                    }
                    rows["QUANTITY"]     = (int)POLTable.QUANTITY;
                    rows["PRICE"]        = POLTable.PRICE;
                    rows["TOTAL_AMOUNT"] = POLTable.AMOUNT_INCLUDED_TAX;
                    rows["MEMO"]         = purchase.MEMO;
                    dt.Rows.Add(rows);
                    TOTAL += POLTable.AMOUNT_INCLUDED_TAX;
                    i++;
                }
                ht.Add("&TOTAL", TOTAL);

                SaveFileDialog sf = new SaveFileDialog();
                sf.FileName = "HD_PURCHASED_PART_" + supplier.NAME + "_" + purchase.SLIP_DATE.ToString("yyyyMMddhhmmss") + ".xls";
                sf.Filter   = "(文件)|*.xls;*.xlsx";
                if (sf.ShowDialog(this) == DialogResult.OK)
                {
                    if (dt.Rows.Count > 0)
                    {
                        int ret = CExport.DataTableToExcel_SF(@"rpt\HD_PURCHASED_PART.xls", sf.FileName, dt, ht);
                        if (CConstant.EXPORT_FAILURE.Equals(ret))
                        {
                            MessageBox.Show("导出失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else if (CConstant.EXPORT_SUCCESS.Equals(ret))
                        {
                            MessageBox.Show("导出成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (CConstant.EXPORT_RUNNING.Equals(ret))
                        {
                            MessageBox.Show("文件正在运行,重新生成文件失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else if (CConstant.EXPORT_TEMPLETE_FILE_NOT_EXIST.Equals(ret))
                        {
                            MessageBox.Show("模版文件不存在。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show("明细信息不存在。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }