Пример #1
0
        public void insert(ArrayList purchaseOrderDetailsRecords)
        {
            if (purchaseOrderDetailsRecords.Count <= 0)
            {
                return;
            }
            else
            {
                try
                {
                    for (int i = 0; i < purchaseOrderDetailsRecords.Count; i++)
                    {
                        SaleOutOrderDetailsTable record = (SaleOutOrderDetailsTable)purchaseOrderDetailsRecords[i];

                        if (i == 0 && checkBillIsExist(record.billNumber))
                        {
                            // 根据单据编号,判断库中是否已经存在该单据 如果存在单据首先删除单据,然后再执行插入操作
                            delete(record.billNumber);
                        }

                        string insert = "INSERT INTO [dbo].[SALE_OUT_ORDER_DETAILS]([ROW_NUMBER],[MATERIEL_ID],[BILL_NUMBER]";
                        insert += ",[PRICE],[VALUE],[TRANSPORTATION_COST],[OTHER_COST])VALUES(";

                        insert += "'" + record.rowNumber + "',";
                        insert += record.materielID + ",";
                        insert += "'" + record.billNumber + "',";
                        insert += record.price + ",";
                        insert += record.value + ",";
                        insert += record.transportationCost + ",";
                        insert += record.otherCost;
                        insert += ")";

                        try
                        {
                            DatabaseAccessFactoryInstance.Instance.ExecuteCommand(FormMain.DB_NAME, insert);
                        }
                        catch (Exception error)
                        {
                            MessageBoxExtend.messageWarning(error.Message);
                            return;
                        }
                    }

                    load();
                }
                catch (Exception)
                {
                }
            }
        }
Пример #2
0
        public bool checkBillIsExist(string billNumber)
        {
            bool isRet = false;

            foreach (KeyValuePair <int, SaleOutOrderDetailsTable> index in m_tableDataList)
            {
                SaleOutOrderDetailsTable record = new SaleOutOrderDetailsTable();

                if (index.Value.billNumber == billNumber)
                {
                    isRet = true;
                    break;
                }
            }

            return(isRet);
        }
Пример #3
0
        public SortedDictionary <int, SaleOutOrderDetailsTable> getSaleOutOrderCountInfo(string startDate, string endDate, bool isAllBill = false)
        {
            SortedDictionary <int, SaleOutOrderDetailsTable> dataList = new SortedDictionary <int, SaleOutOrderDetailsTable>();
            string querySQL = "SELECT [MATERIEL_ID], SUM([PRICE]*[VALUE]+[TRANSPORTATION_COST]+[OTHER_COST]) AS TOTAL_MONEY ";

            querySQL += "FROM [SALE_OUT_ORDER_DETAILS] WHERE BILL_NUMBER IN(";

            querySQL += "SELECT BILL_NUMBER FROM [dbo].[SALE_OUT_ORDER] WHERE ";
            querySQL += "TRADING_DATE >= '" + startDate + "' AND TRADING_DATE <= '" + endDate + "'";

            if (!isAllBill)
            {
                querySQL += " AND IS_REVIEW = 1";
            }

            querySQL += ") GROUP BY [MATERIEL_ID]";
            querySQL += " ORDER BY TOTAL_MONEY DESC";

            using (DataTable dataTable = DatabaseAccessFactoryInstance.Instance.QueryDataTable(FormMain.DB_NAME, querySQL))
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    SaleOutOrderDetailsTable record = new SaleOutOrderDetailsTable();

                    record.materielID = DbDataConvert.ToInt32(row["MATERIEL_ID"]);

                    MaterielTable materiel = Materiel.getInctance().getMaterielInfoFromPkey(record.materielID);
                    record.materielName  = materiel.name;
                    record.materielModel = materiel.model;

                    record.totalMoney = DbDataConvert.ToDouble(row["TOTAL_MONEY"]);

                    dataList.Add(dataList.Count, record);
                }
            }
            return(dataList);
        }
Пример #4
0
        private void load()
        {
            string sql = "SELECT [PKEY],[ROW_NUMBER],[MATERIEL_ID],[BILL_NUMBER],[PRICE],[VALUE]";

            sql += ",[TRANSPORTATION_COST],[OTHER_COST] FROM [dbo].[SALE_OUT_ORDER_DETAILS] ORDER BY PKEY";

            m_tableDataList.Clear();

            using (DataTable dataTable = DatabaseAccessFactoryInstance.Instance.QueryDataTable(FormMain.DB_NAME, sql))
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    SaleOutOrderDetailsTable record = new SaleOutOrderDetailsTable();

                    record.pkey       = DbDataConvert.ToInt32(row["PKEY"]);
                    record.rowNumber  = DbDataConvert.ToString(row["ROW_NUMBER"]);
                    record.billNumber = DbDataConvert.ToString(row["BILL_NUMBER"]);

                    record.materielID = DbDataConvert.ToInt32(row["MATERIEL_ID"]);

                    // 根据物料ID得到物料相关信息
                    MaterielTable materiel = Materiel.getInctance().getMaterielInfoFromPkey(record.materielID);
                    record.materielName     = materiel.name;
                    record.materielModel    = materiel.model;
                    record.materielUnitSale = AuxiliaryMaterial.getInctance().getAuxiliaryMaterialNameFromPkey("BASE_UNIT_LIST", materiel.unitSale);

                    record.price              = DbDataConvert.ToDouble(row["PRICE"]);
                    record.value              = DbDataConvert.ToDouble(row["VALUE"]);
                    record.sumMoney           = record.price * record.value;
                    record.transportationCost = DbDataConvert.ToDouble(row["TRANSPORTATION_COST"]);
                    record.otherCost          = DbDataConvert.ToDouble(row["OTHER_COST"]);
                    record.totalMoney         = record.sumMoney + record.transportationCost + record.otherCost;

                    m_tableDataList.Add(m_tableDataList.Count, record);
                }
            }
        }
Пример #5
0
        private bool updateMaterielData(string billNumber)
        {
            bool isRet = true;

            SortedDictionary <int, SaleOutOrderDetailsTable> dataList =
                SaleOutOrderDetails.getInctance().getSaleOutInfoFromBillNumber(billNumber);

            if (!m_isRedBill)
            {
                // 首先检查物料库存余额是否大于本次出库单交易额,如果小于,则提示用户,但是审核失败
                foreach (KeyValuePair <int, SaleOutOrderDetailsTable> index in dataList)
                {
                    SaleOutOrderDetailsTable record = index.Value;

                    InitMaterielTable materielRecord = new InitMaterielTable();
                    materielRecord.materielID = record.materielID;
                    materielRecord.value      = record.value;

                    InitMaterielTable materielStorageData = InitMateriel.getInctance().getMaterielInfoFromMaterielID(record.materielID);

                    if (materielStorageData.value < materielRecord.value)
                    {
                        isRet = false;
                        MessageBoxExtend.messageWarning("物料:[" + materielRecord.materielID + "]库存数量小于当前交易数量,单据审核失败");
                        break;
                    }
                }
            }

            if (isRet)
            {
                foreach (KeyValuePair <int, SaleOutOrderDetailsTable> index in dataList)
                {
                    SaleOutOrderDetailsTable record = index.Value;

                    #region 更新库存汇总表(INIT_STORAGE_STOCK)

                    // 交易完毕后库存数量
                    double tradingStocksValue = record.value;

                    // 交易后库存数量等于当前仓库库存数减去本次交易数
                    InitMaterielTable materielStorageData = InitMateriel.getInctance().getMaterielInfoFromMaterielID(record.materielID);
                    if (m_isRedBill)
                    {
                        // 如果是销售退货,库存数量应该增加
                        tradingStocksValue = materielStorageData.value + tradingStocksValue;
                    }
                    else
                    {
                        tradingStocksValue = materielStorageData.value - tradingStocksValue;
                    }

                    InitMateriel.getInctance().materielOutStorage(record.materielID, tradingStocksValue);

                    #endregion

                    #region 更新存货明细账表(STORAGE_STOCK_DETAIL) 2012-1-16 00:56

                    StorageStockDetailTable storageStockDetailRecord = new StorageStockDetailTable();
                    storageStockDetailRecord.materielID  = record.materielID;
                    storageStockDetailRecord.tradingDate = DateTime.Now.ToString("yyyyMMdd");
                    storageStockDetailRecord.billNumber  = billNumber;
                    storageStockDetailRecord.thingsType  = "销售出库";
                    storageStockDetailRecord.isIn        = 0;

                    // 本次交易数量和单价
                    if (m_isRedBill)
                    {
                        storageStockDetailRecord.value = record.value * -1;
                    }
                    else
                    {
                        storageStockDetailRecord.value = record.value;
                    }
                    storageStockDetailRecord.price = record.price;

                    // 交易完毕后数量和单价
                    storageStockDetailRecord.storageValue = tradingStocksValue;
                    storageStockDetailRecord.storagePrice = materielStorageData.price;

                    StorageStockDetail.getInctance().insert(storageStockDetailRecord);
                    #endregion
                }
            }

            return(isRet);
        }