Ejemplo n.º 1
0
        /// <summary>
        /// 获得当前选中的数据
        /// </summary>
        private bool GetCurrentSelectedTable()
        {
            bool b = false;

            if (dgvData.SelectedRows.Count > 0)
            {
                try
                {
                    string slipNumber = dgvData.SelectedRows[0].Cells["SLIP_NUMBER"].Value.ToString();

                    _currentPurchaseOrderTable = bPurchaseOrder.GetModel(slipNumber);

                    if (_currentPurchaseOrderTable != null)
                    {
                        b = true;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("采购订单查询选择数据错误:", ex);
                }
            }
            else
            {
                MessageBox.Show("请先选择一行。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(b);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        private void dgvData_CellValidated(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridViewRow dr = dgvData.Rows[e.RowIndex];
                if (e.ColumnIndex == dgvData.Columns["PURCHASE_ORDER_SLIP_NUMBER"].Index)
                {
                    string purchaseOrderSlipNumber = CConvert.ToString(dr.Cells["PURCHASE_ORDER_SLIP_NUMBER"].Value).Trim();
                    string no = CConvert.ToString(dr.Cells["NO"].Value).Trim();
                    if (purchaseOrderSlipNumber != "")
                    {
                        BllPurchaseOrderTable purchaseOrderTable = bPurchaseOrder.GetModel(purchaseOrderSlipNumber);
                        if (purchaseOrderTable != null)
                        {
                            if (!IsExist(purchaseOrderSlipNumber, no))
                            {
                                dr.Cells["PURCHASE_ORDER_SLIP_NUMBER"].Value = purchaseOrderTable.SLIP_NUMBER;
                                dr.Cells["PURCHASE_ORDER_SLIP_DATE"].Value   = CConvert.ToDateTime(purchaseOrderTable.SLIP_DATE).ToString("yyyy-MM-dd");
                                dr.Cells["TOTAL_AMOUNT"].Value = purchaseOrderTable.TOTAL_AMOUNT;
                                dr.Cells["ARR_AMOUNT"].Value   = bDepositArr.GetArrAmount(purchaseOrderTable.SLIP_NUMBER);
                            }
                        }
                        else
                        {
                            MessageBox.Show("订单编号不存在。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            dr.Cells["PURCHASE_ORDER_SLIP_NUMBER"].Value = "";
                            dr.Cells["PURCHASE_ORDER_SLIP_DATE"].Value   = "";
                            dr.Cells["TOTAL_AMOUNT"].Value = "";
                            dr.Cells["ARR_AMOUNT"].Value   = "0";
                            dr.Cells["AMOUNT"].Value       = "";
                        }
                    }
                }
                else if (e.ColumnIndex == dgvData.Columns["AMOUNT"].Index)
                {
                    string amount = CConvert.ToString(dr.Cells["AMOUNT"].Value);

                    if (amount == "")
                    {
                        dr.Cells["AMOUNT"].Value = 0;
                    }
                    else
                    {
                        dr.Cells["AMOUNT"].Value = CConvert.ToDecimal(amount);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CellValidated error!", ex);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 详细确认
 /// </summary>
 private void btnOperate_Click(object sender, EventArgs e)
 {
     if (GetCurrentSelectedTable())
     {
         if (CConstant.PURCHASE_ORDER_SEARCH.Equals(CTag))
         {
             FrmPurchaseOrderEntry frm = new FrmPurchaseOrderEntry();
             frm.UserTable = _userInfo;
             frm.CTag      = CConstant.PURCHASE_ORDER_SEARCH;
             frm.CurrentPurchaseOrderTable = _currentPurchaseOrderTable;
             frm.ShowDialog(this);
             frm.Dispose();
             _currentPurchaseOrderTable = null;
         }
         else if (CConstant.PURCHASE_ORDER_MASTER_SEARCH.Equals(CTag))
         {
             this.DialogResult = DialogResult.OK;
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 修改
 /// </summary>
 private void btnModify_Click(object sender, EventArgs e)
 {
     if (GetCurrentSelectedTable())
     {
         getReceipt(_currentPurchaseOrderTable.SLIP_NUMBER);
         if (Receipt == CConstant.UN_RECEIPT)
         {
             FrmPurchaseOrderEntry frm = new FrmPurchaseOrderEntry();
             frm.UserTable = _userInfo;
             frm.CTag      = CConstant.PURCHASE_ORDER_MODIFY;
             frm.CurrentPurchaseOrderTable = _currentPurchaseOrderTable;
             if (DialogResult.OK == frm.ShowDialog(this))
             {
                 BindData(this.pgControl.GetCurrentPage());
             }
             frm.Dispose();
             _currentPurchaseOrderTable = null;
         }
         else
         {
             MessageBox.Show("明细已入库,不能修改!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public int Update(BllPurchaseOrderTable model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(BllPurchaseOrderTable model)
 {
     return(dal.Add(model));
 }
Ejemplo n.º 7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!CheckHeaderInput())
            {
                return;
            }

            if (!CheckLineInput())
            {
                return;
            }

            BllPurchaseOrderTable     POTable = new BllPurchaseOrderTable();
            BllPurchaseOrderLineTable OLTable = null;

            //订单类型
            POTable.SLIP_TYPE = cboPurchaseSlipType.SelectedValue.ToString();
            //订单编号
            POTable.SLIP_NUMBER = txtPurchaseSlipNumber.Text.Trim();
            //类型编号
            POTable.ORDER_SLIP_NUMBER = txtOrderNumber.Text.Trim();
            //供应商编号
            POTable.SUPPLIER_CODE = txtSupplierCode.Text.Trim();
            //报价单号
            POTable.SUPPLIER_ORDER_NUMBER = txtSupplierOrderCode.Text.Trim();
            //入库仓库
            POTable.RECEIPT_WAREHOUSE_CODE = txtWarehouseCode.Text.Trim();
            //采购订单日期
            POTable.SLIP_DATE = CConvert.ToDateTime(entryDate.Value.ToString("yyyy-MM-dd"));
            //交货期限
            POTable.DUE_DATE = CConvert.ToDateTime(dueDate.Value.ToString("yyyy-MM-dd"));
            //税率
            POTable.TAX_RATE = CConvert.ToDecimal(cboTax.Text.Replace("%", "")) / 100;
            //通货
            POTable.CURRENCY_CODE = "01";
            //包装方式
            //POTable.PACKING_METHOD = txtPackingMethod.Text.Trim();
            //付款方式
            POTable.PAYMENT_CONDITION = txtPayment.Text.Trim();
            //备注
            POTable.MEMO = txtMemo.Text.Trim();
            //状态
            POTable.STATUS_FLAG = CConstant.PURCHASE_NEW;
            //创建人
            POTable.CREATE_USER = UserTable.CODE;
            //最后更新人
            POTable.LAST_UPDATE_USER = UserTable.CODE;
            //公司
            POTable.COMPANY_CODE = UserTable.COMPANY_CODE;
            //总金额
            POTable.TOTAL_AMOUNT = CConvert.ToDecimal(txtAmountIncludedTax.Text.Trim());
            //明细的整理
            foreach (DataGridViewRow row in dgvData.Rows)
            {
                OLTable                     = new BllPurchaseOrderLineTable();
                OLTable.SLIP_NUMBER         = POTable.SLIP_NUMBER;
                OLTable.LINE_NUMBER         = row.Index + 1;
                OLTable.PRODUCT_CODE        = row.Cells["PRODUCT_CODE"].Value.ToString();
                OLTable.QUANTITY            = CConvert.ToDecimal(row.Cells["QUANTITY"].Value.ToString());
                OLTable.UNIT_CODE           = row.Cells["UNIT_CODE"].Value.ToString();
                OLTable.PRICE               = CConvert.ToDecimal(row.Cells["PRICE"].Value.ToString());
                OLTable.AMOUNT_WITHOUT_TAX  = CConvert.ToDecimal(row.Cells["AMOUNT"].Value.ToString());
                OLTable.AMOUNT_INCLUDED_TAX = CConvert.ToDecimal(row.Cells["AMOUNT_INCLUDED_TAX"].Value.ToString());
                OLTable.TAX_AMOUNT          = OLTable.AMOUNT_INCLUDED_TAX - OLTable.AMOUNT_WITHOUT_TAX;
                OLTable.STATUS_FLAG         = CConstant.PURCHASE_NEW;
                POTable.AddItem(OLTable);
            }

            int result = 0;

            try
            {
                if (_currentPurchaseOrderTable != null)
                {
                    result = bPurchaseOrder.Update(POTable);
                }
                else
                {
                    result = bPurchaseOrder.Add(POTable);
                }

                if (result <= 0)
                {
                    MessageBox.Show("订单保存失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("订单保存成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (CConstant.PURCHASE_ORDER_NEW.Equals(CTag))
                    {
                        initPage();
                    }
                    else
                    {
                        _dialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("订单保存失败,系统错误,请与管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Logger.Error("订单保存失败!", ex);
            }
        }
Ejemplo n.º 8
0
        private void btnInquirySheet_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);

                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_INQUIRY_" + supplier.NAME + "_" + purchase.SLIP_DATE.ToString("yyyyMMdd") + ".xls";
                sf.Filter   = "(文件)|*.xls;*.xlsx";
                if (sf.ShowDialog(this) == DialogResult.OK)
                {
                    if (dt.Rows.Count > 0)
                    {
                        int ret = CExport.DataTableToExcel_IS(@"rpt\HD_INQUIRY.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);
                    }
                }
            }
        }
Ejemplo n.º 9
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("请选择一行!");
            }
        }
Ejemplo n.º 10
0
        /// <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);
            }
        }