Beispiel #1
0
        private DamaiDataSet.AccVouchRow CalcTotalAndSetMoney()
        {
            var rowView = accVouchBindingSource.Current as DataRowView;

            if (rowView == null)
            {
                return(null);
            }
            DamaiDataSet.AccVouchRow parent = rowView.Row as DamaiDataSet.AccVouchRow;
            if (parent == null)
            {
                return(parent);
            }
            decimal credit = 0, debt = 0;
            var     details = parent.GetAccVouchDetailRows();

            foreach (var row in details)
            {
                if (!row.IsCreditNull())
                {
                    credit += row.Credit;
                }
                if (!row.IsDebtNull())
                {
                    debt += row.Debt;
                }
            }
            labelDebt.Text   = debt.ToString("N2");
            labelCredit.Text = credit.ToString("N2");
            if (parent.IsMoneyNull() || parent.Money != debt)
            {
                parent.Money = debt;
            }
            return(parent);
        }
Beispiel #2
0
        private void accVoucherDetailDataGridView_DragDrop(object sender, DragEventArgs e)
        {
            var view = sender as DataGridView;

            view.BackgroundColor = Color.FromArgb(216, 228, 248);
            if (dgvAccVoucher.Rows.Count == 0)
            {
                MessageBox.Show("請新增傳票,再拖資料!");
                return;
            }
            var list = e.Data.GetData(typeof(List <AccDragItem>)) as List <AccDragItem>;

            if (list.Count != 0)
            {
                var rowView = accVouchBindingSource.Current as DataRowView;
                DamaiDataSet.AccVouchRow parent = rowView.Row as DamaiDataSet.AccVouchRow;
                if (parent != null)
                {
                    foreach (var item in list)
                    {
                        if (AddAccVoucherDetail(item, parent))
                        {
                            item.dgv.Rows.Remove(item.row);
                        }
                    }
                }
                CalcTotalAndSetMoney();
            }
            accVouchBindingSource.ResetBindings(false);
        }
Beispiel #3
0
        private void dgvAccVoucher_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            var             view    = sender as DataGridView;
            DataGridViewRow viewRow = e.Row;
            var             rowView = viewRow.DataBoundItem as DataRowView;

            if (rowView == null)
            {
                return;
            }
            DamaiDataSet.AccVouchRow acc = rowView.Row as DamaiDataSet.AccVouchRow;
            var details = acc.GetAccVouchDetailRows();
            var dic     = new Dictionary <AccDataSource, List <int> >();

            dic.Add(AccDataSource.Voucher, new List <int>());
            dic.Add(AccDataSource.Expense, new List <int>());
            dic.Add(AccDataSource.PosRevenue, new List <int>());
            dic.Add(AccDataSource.Shipment, new List <int>());
            dic.Add(AccDataSource.Bank, new List <int>());
            List <int> list = new List <int>();

            foreach (var acc1 in details)
            {
                if ((!acc1.IsSourceDataTypeNull()) && (!acc1.IsSourceDataIDNull()))
                {
                    if (dic.TryGetValue((AccDataSource)acc1.SourceDataType, out list))
                    {
                        list.Add(acc1.SourceDataID);
                    }
                }
                acc1.Delete();
            }
            foreach (var pair in dic)
            {
                DeleteRelatedDGV(pair.Key, pair.Value);
            }
        }
Beispiel #4
0
        private bool AddAccVoucherDetail(AccDragItem item, DamaiDataSet.AccVouchRow parent)
        {
            if (parent == null)
            {
                return(false);
            }
            if (item.row == null)
            {
                return(false);
            }
            if (item.row.DataBoundItem == null || item.row.DataBoundItem == DBNull.Value)
            {
                return(false);
            }
            string note = "", note1;
            string creditCode = "", debtCode = "";
            var    sourceRowView = item.row.DataBoundItem as DataRowView;

            if (sourceRowView == null)
            {
                return(false);
            }
            if (sourceRowView.Row == null)
            {
                return(false);
            }
            var detailTable = damaiDataSet.AccVouchDetail;

            try
            {
                short  shType = (short)item.dataSourceType;
                string strDay;
                switch (item.dataSourceType)
                {
                case AccDataSource.Voucher:
                    var voucherRow = sourceRowView.Row as DamaiDataSet.VoucherRow;
                    note = SafeNote(voucherRow.VendorRow.Name + " " + voucherRow.StockTime.Month.ToString() + "月貨款");
                    string dotVendorID = "." + (voucherRow.IsVendorIDNull()?"x":voucherRow.VendorID.ToString());
                    note1 = SafeNote(note + voucherRow.VoucherID);
                    detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.AssetIngredients, voucherRow.Cost, 0, note1, shType, item.intDragID);
                    detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.VoucherShouldPay + dotVendorID, 0, voucherRow.Cost, note1, shType, item.intDragID);
                    if (parent.IsNoteNull())
                    {
                        parent.Note = note;
                    }
                    return(true);

                case AccDataSource.Expense:
                    var expenseRow = sourceRowView.Row as DamaiDataSet.ExpenseRow;
                    strDay = expenseRow.IsApplyTimeNull()?"":expenseRow.ApplyTime.ToString("M/dd");
                    if (!expenseRow.IsNoteNull())
                    {
                        note = SafeNote(expenseRow.Note);
                    }
                    if (expenseRow.IsTitleCodeCreditNull())
                    {
                        creditCode = damaiDataSet.BankAccount[0].AccountTitleCode;
                    }
                    else
                    {
                        creditCode = expenseRow.TitleCodeCredit;
                    }
                    if (!expenseRow.IsTitleCodeNull())
                    {
                        debtCode = expenseRow.TitleCode;
                    }
                    detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, debtCode, expenseRow.Money, 0, strDay + note, shType, item.intDragID);
                    detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, creditCode, 0, expenseRow.Money, strDay + note, shType, item.intDragID);
                    if (parent.IsNoteNull())
                    {
                        parent.Note = "零用金 " + note + " ...";
                    }
                    return(true);

                case AccDataSource.PosRevenue:
                    var revenueRow = sourceRowView.Row as DamaiDataSet.HeaderRow;
                    note = SafeNote(revenueRow.DataDate.ToString("M/dd"));
                    if (!revenueRow.IsRevenueNull() && revenueRow.IsCashNull() &&
                        revenueRow.IsCreditCardNull() && revenueRow.IsCoupondNull())
                    {
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.CashIncome, 0, revenueRow.Revenue, note + "營收", shType, item.intDragID);
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.CashReceivable, revenueRow.Revenue, 0, note + "营收", shType, item.intDragID);
                    }
                    if (!revenueRow.IsCashNull() && revenueRow.Cash != 0)
                    {
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.CashIncome, 0, revenueRow.Cash, note + "现金营收", shType, item.intDragID);
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.CashReceivable, revenueRow.Cash, 0, note + "现金营收", shType, item.intDragID);
                    }
                    if (!revenueRow.IsCreditCardNull() && revenueRow.CreditCard != 0)
                    {
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.CardIncome, 0, revenueRow.CreditCard, note + "刷卡营收", shType, item.intDragID);
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.CardReceivable, revenueRow.CreditCard, 0, note + "刷卡营收", shType, item.intDragID);
                    }
                    if (!revenueRow.IsCoupondNull() && revenueRow.Coupond != 0)
                    {
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.SoldOnCreditIncome, 0, revenueRow.Coupond, note + "赊销-劵", shType, item.intDragID);
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, Setup.SoldOnCreditReceivable, revenueRow.Coupond, 0, note + "赊销-劵", shType, item.intDragID);
                    }
                    if (parent.IsNoteNull())
                    {
                        parent.Note = note + "營收";
                    }
                    return(true);

                case AccDataSource.Bank:
                    var bankRow = sourceRowView.Row as DamaiDataSet.BankDetailRow;
                    if (bankRow == null)
                    {
                        return(false);
                    }
                    int    bankID     = bankRow.BankID;
                    var    bankAccRow = damaiDataSet.BankAccount.FindByID(bankID);
                    string bankName   = "銀行" + bankID.ToString();
                    if (bankAccRow != null && !bankAccRow.IsShowNameNull())
                    {
                        bankName = bankAccRow.ShowName;
                    }
                    strDay     = (bankRow.IsDayNull()?"":bankRow.Day.ToString("M/dd"));
                    note       = SafeNote("<" + bankName + strDay + ">" + (bankRow.IsNoteNull() ? "" : bankRow.Note));
                    creditCode = bankAccRow.AccountTitleCode + "." + bankID.ToString();
                    debtCode   = bankRow.IsTitleCodeNull() ? "" : bankRow.TitleCode;
                    if (bankRow.IsIsCreditNull() || !bankRow.IsCredit)      // 存款增加
                    {
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, creditCode, bankRow.Money, 0, note, (short)item.dataSourceType, item.intDragID);
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, debtCode, 0, bankRow.Money, note, (short)item.dataSourceType, item.intDragID);
                    }
                    else
                    {
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, creditCode, 0, bankRow.Money, note, (short)item.dataSourceType, item.intDragID);
                        detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, debtCode, bankRow.Money, 0, note, (short)item.dataSourceType, item.intDragID);
                    }
                    if (parent.IsNoteNull())
                    {
                        parent.Note = note;
                    }
                    return(true);

                case AccDataSource.Shipment:
                    var shipmentRow = sourceRowView.Row as DamaiDataSet.ShipmentRow;
                    if (shipmentRow.IsCustomerNull())
                    {
                        note = "";
                    }
                    else
                    {
                        note = shipmentRow.CustomerRow.Name + " ";
                    }
                    if (!shipmentRow.IsShipTimeNull())
                    {
                        note += shipmentRow.ShipTime.Month.ToString() + "月進貨";
                    }
                    note1 = SafeNote(note + (shipmentRow.IsShipCodeNull() ? "" : shipmentRow.ShipCode.ToString()));
                    string dotCumstomerID = "." + (shipmentRow.IsCustomerNull()?"x":shipmentRow.Customer.ToString());
                    debtCode   = Setup.SoldOnCreditReceivable + dotCumstomerID;
                    creditCode = Setup.SoldOnCreditIncome + dotCumstomerID;
                    decimal cost = (shipmentRow.IsCostNull()?0:shipmentRow.Cost);
                    detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, debtCode, cost, 0, note1, (short)item.dataSourceType, item.intDragID);
                    detailTable.AddAccVouchDetailRow(Guid.NewGuid(), parent, creditCode, 0, cost, note1, (short)item.dataSourceType, item.intDragID);
                    if (parent.IsNoteNull())
                    {
                        parent.Note = SafeNote("赊销 " + note);
                    }
                    return(true);

                default: return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("加入傳票項目時出錯,原因:" + ex.Message);
                return(false);
            }
        }