Ejemplo n.º 1
0
        private void LoadLedgerData()
        {
            if (DataPrepared)
            {
                return;
            }

            try
            {
                var headerSQLAdapter = new DamaiDataSetTableAdapters.HeaderTableAdapter();
                headerSQLAdapter.Fill(damaiDataSet.Header);
            }
            catch { MessageBox.Show("標頭資料讀取錯誤,你的資料庫版本可能不對"); }
            int count = damaiDataSet.Header.Count;

            if (count == 0)
            {
                MessageBox.Show("無資料!");
                Close();
                return;
            }
            var row = damaiDataSet.Header[count - 1];

            m_Revenue = new RevenueCalcBakery(row.DataDate, 0);
            AccList.NewAll();
            var expenseSQLAdapter       = new DamaiDataSetTableAdapters.ExpenseTableAdapter();
            var voucherSQLAdapter       = new DamaiDataSetTableAdapters.VoucherTableAdapter();
            var voucherDetailSQLAdapter = new DamaiDataSetTableAdapters.VoucherDetailTableAdapter();
            var bankDetailSQLAdapter    = new DamaiDataSetTableAdapters.BankDetailTableAdapter();
            var accVoucherSQLAdapter    = new DamaiDataSetTableAdapters.AccVoucherTableAdapter();
            var ingredientSQLAdapter    = new DamaiDataSetTableAdapters.IngredientTableAdapter();
            var bankAccountSQLAdapter   = new DamaiDataSetTableAdapters.BankAccountTableAdapter();
            var vendorSQLAdapter        = new DamaiDataSetTableAdapters.VendorTableAdapter();

            ingredientSQLAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);
            vendorSQLAdapter.Connection.ConnectionString     = DB.SqlConnectString(MyFunction.HardwareCfg);

            DamaiDataSet.AccountingTitleDataTable accTitleTable = damaiDataSet.AccountingTitle;
            try
            {
                bankAccountSQLAdapter.Fill(damaiDataSet.BankAccount);
                vendorSQLAdapter.Fill(damaiDataSet.Vendor);
                expenseSQLAdapter.Fill(damaiDataSet.Expense);          // expense檔案小,先全部讀進記憶體
                voucherSQLAdapter.Fill(damaiDataSet.Voucher);
                voucherDetailSQLAdapter.Fill(damaiDataSet.VoucherDetail);
                bankDetailSQLAdapter.Fill(damaiDataSet.BankDetail);
                accVoucherSQLAdapter.Fill(damaiDataSet.AccVoucher);
                ingredientSQLAdapter.Fill(damaiDataSet.Ingredient);
                foreach (var r in accTitleTable)
                {
                    AccTitle item = new AccTitle(r.TitleCode, r.Name);
                    if (r.IsInitialValueNull())
                    {
                        item.Money = 0;
                    }
                    else
                    {
                        item.Money = r.InitialValue;
                    }
                    if (r.TitleCode.Length == 0)
                    {
                        continue;
                    }
                    AccList.Add(item);
                }
                AccList1.CopyTableFrom(AccList);
                Setup.Load();
                m_Generator = new LedgerTableGenerator(labelMessage, Setup, damaiDataSet, new CalcRevenueDelegate(CalcRevenue));
            }

            catch (Exception ex)
            {
                MessageBox.Show("資料庫讀取錯誤! 原因:" + ex.Message);
                return;
            }
            DataPrepared = true;
        }
Ejemplo n.º 2
0
        private void FormLedger_Load(object sender, EventArgs e)
        {
            accountingTitleBindingSource.DataSource = m_DataSet;
            m_OrderSet = m_DataSet;
            try
            {
                headerAdapter.Fill(m_DataSet.Header);
            }
            catch { MessageBox.Show("標頭資料讀取錯誤,你的資料庫版本可能不對"); }
            int count = m_DataSet.Header.Count;

            if (count == 0)
            {
                MessageBox.Show("無資料!");
                Close();
                return;
            }
            var row = m_DataSet.Header[count - 1];

            m_Revenue = new RevenueCalcBakery(row.DataDate, 0);

            AccList.NewAll();
            var accTitleAdapter      = new DamaiDataSetTableAdapters.AccountingTitleTableAdapter();
            var bankAccountAdapter   = new DamaiDataSetTableAdapters.BankAccountTableAdapter();
            var expenseAdapter       = new DamaiDataSetTableAdapters.ExpenseTableAdapter();
            var voucherAdapter       = new DamaiDataSetTableAdapters.VoucherTableAdapter();
            var voucherDetailAdapter = new DamaiDataSetTableAdapters.VoucherDetailTableAdapter();
            var bankDetailAdapter    = new DamaiDataSetTableAdapters.BankDetailTableAdapter();
            var accVoucherAdapter    = new DamaiDataSetTableAdapters.AccVoucherTableAdapter();
            var vendorAdapter        = new DamaiDataSetTableAdapters.VendorTableAdapter();
            var ingredientAdapter    = new DamaiDataSetTableAdapters.IngredientTableAdapter();

            try
            {
                ingredientAdapter.Connection.ConnectionString = DB.SqlConnectString(MyFunction.HardwareCfg);
                accTitleAdapter.Connection.ConnectionString   = DB.SqlConnectString(MyFunction.HardwareCfg);
                vendorAdapter.Connection.ConnectionString     = DB.SqlConnectString(MyFunction.HardwareCfg);

                accTitleAdapter.Fill(m_DataSet.AccountingTitle);
                bankAccountAdapter.Fill(m_DataSet.BankAccount);
                expenseAdapter.Fill(m_DataSet.Expense);         // expense檔案小,先全部讀進記憶體
                voucherAdapter.Fill(m_DataSet.Voucher);
                voucherDetailAdapter.Fill(m_DataSet.VoucherDetail);
                bankDetailAdapter.Fill(m_DataSet.BankDetail);
                accVoucherAdapter.Fill(m_DataSet.AccVoucher);
                vendorAdapter.Fill(m_DataSet.Vendor);
                ingredientAdapter.Fill(m_DataSet.Ingredient);

                foreach (var r in m_DataSet.AccountingTitle)
                {
                    AccTitle item = new AccTitle(r.TitleCode, r.Name);
                    if (r.IsInitialValueNull())
                    {
                        item.Money = 0;
                    }
                    else
                    {
                        item.Money = r.InitialValue;
                    }
                    if (r.TitleCode.Length == 0)
                    {
                        continue;
                    }
                    AccList.Add(item);
                }
                AccList1.CopyTableFrom(AccList);

                Setup.Load();
                m_Generator = new LedgerTableGenerator(labelMessage, Setup, m_DataSet, new CalcRevenueDelegate(CalcRevenue));
                cLedgerTableDataGridView.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("資料庫讀取錯誤! 原因:" + ex.Message);
            }

            // 設置comboBoxAccTitle的初值為 <零用金>
            if (m_DataSet.BankAccount.Rows.Count > 1)
            {
                var bank = m_DataSet.BankAccount[0];
                if (bank.IsAccountTitleCodeNull())
                {
                    comboBoxAccTitle.SelectedIndex = 0;
                }
                else
                {
                    comboBoxAccTitle.SelectedValue = bank.AccountTitleCode;
                }
            }
            DontRefresh = false;     // Form剛Load不Refresh DataGridView
        }