Esempio n. 1
0
        //private void MakeBankAccountComboBox()
        //{
        //    BankAccountAdapter.Fill(this.m_DataSet.BankAccount);
        //    List<CBankAccountForComboBox> list = new List<CBankAccountForComboBox>();
        //    CBankAccountForComboBox acc = new CBankAccountForComboBox();
        //    list.Add(acc);
        //    foreach (var r in m_DataSet.BankAccount)
        //    {
        //        if (r.ID != 1)   // ID 1是給零用金的特殊帳號
        //        {
        //            acc = new CBankAccountForComboBox();
        //            acc.Name = r.ShowName;
        //            acc.ID   = r.ID;
        //            list.Add(acc);
        //        }
        //    }
        //    cbBankAccount.DataSource = list;
        //}

        private void FormImportBankExcel_Load(object sender, EventArgs e)
        {
            string[] names = null;
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                m_CloseForm = true;
                return;
            }
            m_FileName = openFileDialog1.FileName;
            try
            {
                excel = new ExcelLib();
                names = excel.SheetNames(m_FileName);
                if (names == null || names.Length < 1)
                {
                    MessageBox.Show("找不到<" + m_FileName + ">!");
                    m_CloseForm = true;
                    return;
                }
                cbSheetNames.Items.Clear();
                foreach (string name in names)
                {
                    cbSheetNames.Items.Add(name);
                }
            }
            catch
            {
                MessageBox.Show("轉換Excel表過程出錯! 是否沒有安裝Excel或 Microsoft.Office.Interop.Excel.dll不存在!");
                m_CloseForm = true;
            }
            var bankAccountAdapter = new VoucherExpense.DamaiDataSetTableAdapters.BankAccountTableAdapter();

            //            MakeBankAccountComboBox();
            bankAccountAdapter.Fill(this.m_DataSet.BankAccount);
            List <CBankAccountForComboBox> list = new List <CBankAccountForComboBox>();
            CBankAccountForComboBox        acc  = new CBankAccountForComboBox();

            list.Add(acc);
            foreach (var r in m_DataSet.BankAccount)
            {
                if (r.ID != 1)   // ID 1是給零用金的特殊帳號
                {
                    acc      = new CBankAccountForComboBox();
                    acc.Name = r.ShowName;

                    acc.ID = r.ID;
                    list.Add(acc);
                }
            }
            cbBankAccount.DataSource = list;
        }
Esempio n. 2
0
        private void MakeBankAccountComboBox()
        {
            List <CBankAccountForComboBox> list = new List <CBankAccountForComboBox>();
            CBankAccountForComboBox        acc  = new CBankAccountForComboBox();

            acc.Name = "全部";
            list.Add(acc);
            foreach (var r in m_DataSet.BankAccount)
            {
                if (r.ID != 1)   // ID 1是給零用金的特殊帳號
                {
                    acc      = new CBankAccountForComboBox();
                    acc.Name = r.ShowName;
                    acc.ID   = r.ID;
                    list.Add(acc);
                }
            }
            cbSelectBank.DataSource = list;
        }
Esempio n. 3
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            if (cbBankAccount.SelectedIndex < 1)
            {
                MessageBox.Show("請先選擇轉入的戶頭!");
                return;
            }
            if (m_ImportDataList == null)
            {
                MessageBox.Show("請選擇有資料的xls表!");
                return;
            }
            BankDetailAdapter.Fill(m_DataSet.BankDetail);

            CBankAccountForComboBox acc = new CBankAccountForComboBox();

            try
            {
                acc = (CBankAccountForComboBox)cbBankAccount.SelectedItem;
            }
            catch
            {
                MessageBox.Show("銀行帳號資料庫有誤! 無法設定BankID!");
                return;
            }
            int maxId = 1;

            foreach (var r in m_DataSet.BankDetail)
            {
                if (r.ID > maxId)
                {
                    maxId = r.ID;
                }
            }

            int count = 0;
            var table = new MyBankDetailTable();

            int maxNoteLen = table.NoteColumn.MaxLength;

            foreach (CBankDetail d in m_ImportDataList)
            {
                count++;
                foreach (var r in m_DataSet.BankDetail)
                {
                    if (r.BankID != acc.ID)
                    {
                        continue;
                    }
                    if (r.Day != d.Date)
                    {
                        continue;
                    }
                    if (MessageBox.Show("日期" + d.Date.ToShortDateString() + "己有資料! 按OK繼續, 按取消中斷操作",
                                        "<" + count.ToString() + ">  " + r.Day.ToString("MM/dd") + " " + r.Money.ToString(),
                                        MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        MessageBox.Show("所有資料都沒有轉入! ");
                        return;
                    }
                    break;
                }

                var row = table.NewBankDetailRow();
                maxId++;
                row.ID     = maxId;
                row.BankID = acc.ID;
                row.Day    = d.Date;
                if (d.Debt > 0)
                {
                    row.IsCredit = true;    // 定義反了
                    row.Money    = d.Debt;
                }
                else
                {
                    row.IsCredit = false;
                    row.Money    = d.Credit;
                }

                string s = d.Note;
                if (s != null)
                {
                    if (s.Length <= maxNoteLen)
                    {
                        row.Note = s;
                    }
                    else
                    {
                        row.Note = s.Substring(0, maxNoteLen);
                    }
                }
                row.TitleCode = "";///
                table.Rows.Add(row);
            }
            if (table == null || table.Count == 0)
            {
                MessageBox.Show("沒有新資料加入,不需要存!");
                return;
            }
            BankDetailAdapter.Update(table);
            btnConvert.Enabled = false;
            MessageBox.Show("成功轉入<" + acc.Name + "> 共" + count.ToString() + "筆資料!");
        }