Exemple #1
0
        private void txtOrderNumber_Leave(object sender, EventArgs e)
        {
            string order = txtOrderNumber.Text.Trim();

            if (!string.IsNullOrEmpty(order))
            {
                BOrderHeader bOrderHeader = new BOrderHeader();
                if (!bOrderHeader.Exists(order))
                {
                    MessageBox.Show("销售订单编号不存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtOrderNumber.Text = "";
                    txtOrderNumber.Focus();
                }
            }
        }
Exemple #2
0
        private void btnPurcahse_Click(object sender, EventArgs e)
        {
            if (dgvData.SelectedRows.Count > 0)
            {
                Hashtable       ht  = null;
                DataTable       dt  = null;
                DataGridViewRow row = dgvData.SelectedRows[0];

                BaseCompanyTable      company   = new BCompany().GetModel(_userInfo.COMPANY_CODE);
                BllPurchaseOrderTable purchase  = bPurchaseOrder.GetModel(CConvert.ToString(row.Cells["SLIP_NUMBER"].Value));
                BllOrderHeaderTable   order     = new BOrderHeader().GetModel(purchase.ORDER_SLIP_NUMBER);
                BaseWarehouseTable    warehouse = new BWarehouse().GetModel(purchase.RECEIPT_WAREHOUSE_CODE);

                if (company == null)
                {
                    company = new BaseCompanyTable();
                }

                if (warehouse == null)
                {
                    warehouse = new BaseWarehouseTable();
                }

                if (purchase == null)
                {
                    purchase = new BllPurchaseOrderTable();
                }
                BaseSupplierTable supplier = new BSupplier().GetModel(purchase.SUPPLIER_CODE);
                if (supplier.TYPE == 2)
                {
                    #region 国内
                    ht = new Hashtable();
                    ht.Add("&COMPANY_NAME", company.NAME);
                    ht.Add("&ADDRESS", company.ADDRESS_FIRST + company.ADDRESS_MIDDLE + company.ADDRESS_LAST);
                    if (string.IsNullOrEmpty(company.PHONE_NUMBER.ToString()))
                    {
                        ht.Add("&PHONE", "TEL                 " + "FAX" + company.FAX_NUMBER);
                    }
                    else
                    {
                        ht.Add("&PHONE", "TEL" + company.PHONE_NUMBER.ToString() + "FAX" + company.FAX_NUMBER);
                    }
                    ht.Add("&SLIP_NUMBER", purchase.SLIP_NUMBER);
                    ht.Add("&SLIP_DATE", purchase.SLIP_DATE.ToString("yyyy年MM月dd日"));
                    ht.Add("&SUPPLIER", "厂商名称:" + supplier.NAME);
                    //
                    ht.Add("&NAME", company.NAME);
                    ht.Add("&DUE_DATE", "1.交货日期:" + CConvert.ToDateTime(purchase.DUE_DATE).ToShortDateString());
                    ht.Add("&PACKING_METHOD", "2.包装方式:" + purchase.PACKING_METHOD);
                    ht.Add("&WAREHOUSE_NAME", "3.交货地址:" + warehouse.ADDRESS_FIRST + warehouse.ADDRESS_MIDDLE + warehouse.ADDRESS_LAST);
                    ht.Add("&PAYMENT_CONDITION", "4.支付方式:" + purchase.PAYMENT_CONDITION);

                    dt = new DataTable();
                    dt.Columns.Add("NO");
                    dt.Columns.Add("MODEL_NUMBER");
                    dt.Columns.Add("PRODUCT_NAME");
                    dt.Columns.Add("SPEC");
                    dt.Columns.Add("QUANTITY");
                    dt.Columns.Add("PRICE");
                    dt.Columns.Add("AMOUNT_WITHOUT_TAX");
                    //dt.Columns.Add("AMOUNT_INCLUDED_TAX");
                    dt.Columns.Add("DUE_DATE");

                    decimal amount    = 0;
                    decimal taxAmount = 0;
                    DataRow rows      = null;
                    foreach (BllPurchaseOrderLineTable OLModel in purchase.Items)
                    {
                        rows       = dt.NewRow();
                        rows["NO"] = OLModel.LINE_NUMBER;

                        if (OLModel.PRODUCT_CODE.Length >= 4 && OLModel.PRODUCT_CODE.Substring(0, 4) == "9999")
                        {
                            rows["PRODUCT_NAME"] = OLModel.PRODUCT_NAME;
                            rows["SPEC"]         = OLModel.PRODUCT_SPEC;
                            rows["MODEL_NUMBER"] = "";
                        }
                        else
                        {
                            BaseProductTable product = new BProduct().GetModel(OLModel.PRODUCT_CODE);
                            if (product != null)
                            {
                                rows["PRODUCT_NAME"] = product.NAME;
                                rows["SPEC"]         = product.SPEC;
                                rows["MODEL_NUMBER"] = product.MODEL_NUMBER;
                            }
                        }
                        rows["QUANTITY"]           = OLModel.QUANTITY;
                        rows["PRICE"]              = OLModel.PRICE;
                        rows["AMOUNT_WITHOUT_TAX"] = Convert.ToDouble(CConvert.ToDecimal(rows["QUANTITY"]) * CConvert.ToDecimal(rows["PRICE"])).ToString("0.00");
                        //rows["AMOUNT_INCLUDED_TAX"] = OLModel.AMOUNT_INCLUDED_TAX;
                        rows["DUE_DATE"] = CConvert.ToDateTime(purchase.DUE_DATE).ToString("yyyy/MM/dd");
                        amount          += OLModel.AMOUNT_WITHOUT_TAX;
                        taxAmount       += OLModel.TAX_AMOUNT;
                        dt.Rows.Add(rows);
                    }

                    ht.Add("&AMOUNT", amount);
                    ht.Add("&TAX_AMOUNT", taxAmount);
                    ht.Add("&TOTAL_AMOUNT", amount + taxAmount);

                    SaveFileDialog sf = new SaveFileDialog();
                    sf.FileName = "LZ_PURCHASE_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    sf.Filter   = "(文件)|*.xls;*.xlsx";

                    if (sf.ShowDialog(this) == DialogResult.OK)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            int ret = CommonExport.ExportPurchase(@"rpt\purchase.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);
                        }
                    }
                    #endregion
                }
                else
                {
                    decimal AMOUNT_WITHOUT_TAX = 0;
                    decimal ORDER_AMOUNT       = 0;
                    #region 国外
                    ht = new Hashtable();
                    ht.Add("&SUPPLIER_NAME", supplier.NAME);
                    ht.Add("&CONTACT_NAME", supplier.CONTACT_NAME);
                    ht.Add("&PHONE", supplier.PHONE_NUMBER);
                    ht.Add("&FAX", supplier.FAX_NUMBER);
                    // ht.Add("&ORDER_NUMBER", purchase.ORDER_SLIP_NUMBER);
                    ht.Add("&SLIP_NUMBER", purchase.SLIP_NUMBER);
                    ht.Add("&SUPPLIER_ORDER_CODE", purchase.SUPPLIER_ORDER_NUMBER);
                    ht.Add("&PURCHASE_QUOTATION_NUMBER", purchase.PURCHASE_QUOTATION_NUMBER);
                    if (order != null)
                    {
                        ht.Add("&CUSTOMER_PO_NUMBER", order.CUSTOMER_PO_NUMBER);
                        string customerCode = "";
                        //if (!string.IsNullOrEmpty(order.CUSTOMER_NAME))
                        //{
                        //    customerCode = order.CUSTOMER_CODE;
                        //    ht.Add("&CUSTOMER_NAME", order.CUSTOMER_NAME);
                        //}
                        //else
                        //{
                        customerCode = order.ENDER_CUSTOMER_CODE;
                        ht.Add("&CUSTOMER_NAME", order.ENDER_CUSTOMER_NAME);
                        //}

                        ht.Add("&DELIVERY_DATE", order.DUE_DATE);
                        ht.Add("&SERIAL_NUMBER", order.SERIAL_NUMBER);
                        ht.Add("&AIRCRAFT", order.SERIAL_TYPE);
                        BaseCustomerTable customer = new BCustomer().GetModel(customerCode);
                        ht.Add("&CUSTOMER_CONTACT_NAME", customer.CONTACT_NAME);
                        ht.Add("&CUSTOMER_PHONE", customer.PHONE_NUMBER);

                        //ht.Add("&ORDER_AMOUNT", order.AMOUNT_INCLUDED_TAX);
                    }
                    else
                    {
                        ht.Add("&CUSTOMER_PO_NUMBER", "");
                        ht.Add("&DELIVERY_DATE", "");
                        ht.Add("&SERIAL_NUMBER", "");
                        //ht.Add("&ORDER_AMOUNT", "");
                        ht.Add("&AIRCRAFT", "");
                        ht.Add("&CUSTOMER_NAME", company.NAME_SHORT);
                        ht.Add("&CUSTOMER_CONTACT_NAME", "");
                        ht.Add("&CUSTOMER_PHONE", company.PHONE_NUMBER);
                    }

                    ht.Add("&MEMO", purchase.MEMO);
                    ht.Add("&TOTAL_AMOUNT", purchase.TOTAL_AMOUNT);
                    ht.Add("&PAYMENT", purchase.PAYMENT_CONDITION);
                    ht.Add("&SLIP_DATE", purchase.SLIP_DATE);
                    ht.Add("&DUE_DATE", purchase.DUE_DATE);

                    dt = new DataTable();
                    dt.Columns.Add("NO");
                    dt.Columns.Add("PRODUCT_CODE");
                    dt.Columns.Add("X_1", Type.GetType("System.String"));
                    dt.Columns.Add("PRODUCT_NAME");
                    dt.Columns.Add("X_2", Type.GetType("System.String"));
                    dt.Columns.Add("MODEL_NUMBER");
                    dt.Columns.Add("X_3", Type.GetType("System.String"));
                    dt.Columns.Add("QUANTITY");
                    dt.Columns.Add("PRICE");
                    dt.Columns.Add("AMOUNT_WITHOUT_TAX");

                    DataRow rows = null;
                    foreach (BllPurchaseOrderLineTable OLModel in purchase.Items)
                    {
                        AMOUNT_WITHOUT_TAX += OLModel.AMOUNT_INCLUDED_TAX;
                        if (order != null)
                        {
                            foreach (BllOrderLineTable line in order.Items)
                            {
                                if (line.PRODUCT_CODE == OLModel.PRODUCT_CODE)
                                {
                                    ORDER_AMOUNT += CConvert.ToDecimal(line.AMOUNT);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            ORDER_AMOUNT += 0;
                        }

                        rows                 = dt.NewRow();
                        rows["NO"]           = OLModel.LINE_NUMBER;
                        rows["PRODUCT_CODE"] = OLModel.PRODUCT_CODE;
                        if (OLModel.PRODUCT_CODE.Length >= 4 && OLModel.PRODUCT_CODE.Substring(0, 4) == "9999")
                        {
                            rows["PRODUCT_NAME"] = OLModel.PRODUCT_NAME;
                            rows["MODEL_NUMBER"] = OLModel.PRODUCT_SPEC;
                        }
                        else
                        {
                            BaseProductTable product = new BProduct().GetModel(OLModel.PRODUCT_CODE);
                            if (product != null)
                            {
                                if (!string.IsNullOrEmpty(product.NAME_JP))
                                {
                                    rows["PRODUCT_NAME"] = product.NAME_JP;
                                }
                                else
                                {
                                    rows["PRODUCT_NAME"] = product.NAME;
                                }
                                rows["MODEL_NUMBER"] = product.SPEC + " " + product.MODEL_NUMBER;
                            }
                        }
                        rows["QUANTITY"]           = OLModel.QUANTITY;
                        rows["PRICE"]              = OLModel.PRICE;
                        rows["AMOUNT_WITHOUT_TAX"] = OLModel.AMOUNT_INCLUDED_TAX;
                        dt.Rows.Add(rows);
                    }
                    ht.Add("&AMOUNT_WITHOUT_TAX", AMOUNT_WITHOUT_TAX);
                    ht.Add("&ORDER_AMOUNT", ORDER_AMOUNT);

                    SaveFileDialog sf = new SaveFileDialog();
                    sf.FileName = "LZ_PURCHASE_OVERSEAS_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    sf.Filter   = "(文件)|*.xls;*.xlsx";

                    if (sf.ShowDialog(this) == DialogResult.OK)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            int ret = CommonExport.ExportPurchaseOverseas(@"rpt\purchase_overseas.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);
                        }
                    }
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("请选择一行!");
            }
        }