Exemplo n.º 1
0
    private bool insertVoucher()
    {
        FinancialDSTableAdapters.InsertVoucherTableAdapter           vch   = new FinancialDSTableAdapters.InsertVoucherTableAdapter();
        FinancialDSTableAdapters.tbl_Ledger_EntriesTableAdapter      led   = new FinancialDSTableAdapters.tbl_Ledger_EntriesTableAdapter();
        FinancialDSTableAdapters.tempTransaction_EntriesTableAdapter temp  = new FinancialDSTableAdapters.tempTransaction_EntriesTableAdapter();
        FinancialDSTableAdapters.tbl_VoucherTypesTableAdapter        vType = new FinancialDSTableAdapters.tbl_VoucherTypesTableAdapter();


        FinancialDS.tempTransaction_EntriesDataTable entries = temp.GetTempTransactionsByEntryKey(MySessionManager.TempTranKey);
        if (entries.Count > 0)
        {
            DateTime vchDate = DateTime.Now;
            try
            {
                CultureInfo ukCulture = new CultureInfo("en-GB");
                vchDate = DateTime.Parse(txtDate.Text, ukCulture);
            }
            catch (Exception ex) { }
            string VchType        = MySessionManager.VchTypeName;
            string vchNarration   = txtNarration.Value;
            string vchNumber      = "";
            int    vchIsPostDated = 0;
            int    vchIsOptional  = 0;
            FinancialDS.tbl_VoucherTypesDataTable vtypes = vType.GetVoucherTypeByName(VchType);
            if (vtypes.Count > 0)
            {
                try
                {
                    vchNumber = vtypes[0].datPrefix + " " + vtypes[0].datSuffix;
                    int     newid     = Convert.ToInt32(vch.InsertVoucher(vchDate, VchType, vchNumber, vchNarration, vchIsPostDated, vchIsOptional, 0, DateTime.Now, DateTime.Now, Convert.ToInt32(MySessionManager.CurrentUser.UserID), 0)[0].vchNewID);
                    decimal totAmount = 0;
                    foreach (FinancialDS.tempTransaction_EntriesRow entry in entries)
                    {
                        led.InsertLedgerEntry(entry.datAccountType, entry.datAccountID, Convert.ToDecimal(entry.datAmount), 0, newid, "On Account", entry.datPaymentMode, "", "", "", "", "", "", "", "", "");
                        totAmount += entry.datAmount;
                    }

                    led.InsertLedgerEntry(vtypes[0].datCreditAccountTypes, Convert.ToInt32(ListofCreditAccounts.SelectedValue), Convert.ToDecimal(totAmount), 1, newid, "On Account", entries[0].datPaymentMode, "", "", "", "", "", "", "", "", "");
                    return(true);
                }
                catch (Exception ex) { return(false); }
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
    private bool insertVoucher()
    {
        FinancialDSTableAdapters.InsertVoucherTableAdapter vch = new FinancialDSTableAdapters.InsertVoucherTableAdapter();
        FinancialDSTableAdapters.tbl_Ledger_EntriesTableAdapter led = new FinancialDSTableAdapters.tbl_Ledger_EntriesTableAdapter();
        FinancialDSTableAdapters.tempTransaction_EntriesTableAdapter temp = new FinancialDSTableAdapters.tempTransaction_EntriesTableAdapter();
        FinancialDSTableAdapters.tbl_VoucherTypesTableAdapter vType = new FinancialDSTableAdapters.tbl_VoucherTypesTableAdapter();


        FinancialDS.tempTransaction_EntriesDataTable entries = temp.GetTempTransactionsByEntryKey(MySessionManager.TempTranKey);
        if (entries.Count > 0)
        {
            DateTime vchDate = DateTime.Now;
            try
            {
                CultureInfo ukCulture = new CultureInfo("en-GB");
                vchDate = DateTime.Parse(txtDate.Text, ukCulture);
            }
            catch (Exception ex) { }
            string VchType = MySessionManager.VchTypeName;
            string vchNarration = txtNarration.Value;
            string vchNumber = "";
            int vchIsPostDated = 0;
            int vchIsOptional = 0;
            FinancialDS.tbl_VoucherTypesDataTable vtypes = vType.GetVoucherTypeByName(VchType);
            if (vtypes.Count > 0)
            {
                try
                {
                    vchNumber = vtypes[0].datPrefix + " " + vtypes[0].datSuffix;
                    int newid = Convert.ToInt32(vch.InsertVoucher(vchDate, VchType, vchNumber, vchNarration, vchIsPostDated, vchIsOptional, 0, DateTime.Now, DateTime.Now, Convert.ToInt32(MySessionManager.CurrentUser.UserID), 0)[0].vchNewID);
                    decimal totAmount = 0;
                    foreach (FinancialDS.tempTransaction_EntriesRow entry in entries)
                    {
                        led.InsertLedgerEntry(entry.datAccountType, entry.datAccountID, Convert.ToDecimal(entry.datAmount),1, newid, "On Account", entry.datPaymentMode, "", "", "", "", "", "", "","","");
                        totAmount += entry.datAmount;
                    }

                    led.InsertLedgerEntry(vtypes[0].datCreditAccountTypes, Convert.ToInt32(ListofCreditAccounts.SelectedValue), Convert.ToDecimal(totAmount), 0, newid, "On Account", entries[0].datPaymentMode, "", "", "", "", "", "", "","","");
                    return true;
                }
                catch (Exception ex) { return false; }
            }
            else { return false; }

        }
        else { return false; }



    }