Esempio n. 1
0
        private void btnEntry_Click(object sender, EventArgs e)
        {
            int i = 0;
            int maxid = -1;
            List<KBRec> rec;
            KBRec wkrec;
            KBDatabase kdb = new KBDatabase();
            string[] wkdate;

            rec = new List<KBRec>();
            wkrec = new KBRec();

            maxid = kdb.getMaxKBDatId();
            for (i = 0; i < dgvKBDat.Rows.Count - 1; i++)
            {
                wkrec.id = ++maxid;
                if (null == dgvKBDat.Rows[i].Cells["buy_date"].Value)
                {
                    wkrec.buy_date = String.Format("{0}-{1:D2}-{2:D2}", dtp.Value.Year, dtp.Value.Month, dtp.Value.Day);
                }
                else
                {
                    wkdate = ((string)dgvKBDat.Rows[i].Cells["buy_date"].Value).Split('-');
                    wkrec.buy_date = String.Format("{0}-{1:D2}-{2:D2}", Int32.Parse(wkdate[0]), Int32.Parse(wkdate[1]), Int32.Parse(wkdate[2])); ;
                }

                if (txtWhere.Text.Trim().Length == 0)
                {
                    if (null == dgvKBDat.Rows[i].Cells["where"].Value)
                    {
                        wkrec.where = "";
                    }
                    else
                    {
                        wkrec.where = (string)dgvKBDat.Rows[i].Cells["where"].Value;
                    }
                }
                else
                {
                    wkrec.where = txtWhere.Text;
                }
                wkrec.rid = txtRID.Text.Trim().Length == 0 ? -1 :  Int32.Parse(txtRID.Text);

                if ((null == dgvKBDat.Rows[i].Cells["income"].Value) || (0 == ((string)dgvKBDat.Rows[i].Cells["income"].Value).Trim().Length))
                {
                    // 支出
                    wkrec.ie_type = 0;
                    wkrec.money = int.Parse(((string)dgvKBDat.Rows[i].Cells["payment"].Value).Trim());
                }
                else if ((null == dgvKBDat.Rows[i].Cells["payment"].Value) || (0 == ((string)dgvKBDat.Rows[i].Cells["payment"].Value).Trim().Length))
                {
                    // 収入
                    wkrec.ie_type = 1;
                    wkrec.money = int.Parse(((string)dgvKBDat.Rows[i].Cells["income"].Value).Trim());
                }
                else
                {
                    MessageBox.Show(i.ToString() + " 行目の金額を入力してください。");
                }

                wkrec.name = (string)dgvKBDat.Rows[i].Cells["name"].Value;
                wkrec.cate_main = Int16.Parse(((string)dgvKBDat.Rows[i].Cells["cate_main"].Value).Split(':')[0].Trim());
                wkrec.cate_sub = Int16.Parse(((string)dgvKBDat.Rows[i].Cells["cate_sub"].Value).Split(':')[0].Trim());
                wkrec.id_usr = this.id_usr;
                if ((null == dgvKBDat.Rows[i].Cells["memo"].Value) || (((string)dgvKBDat.Rows[i].Cells["memo"].Value).Trim().Length == 0))
                {
                    wkrec.memo = "";
                }
                else
                {
                    wkrec.memo = (string)dgvKBDat.Rows[i].Cells["memo"].Value;
                }

                if (cmb_massaccount.SelectedIndex != 0)
                {
                    string[] wk;
                    DateTime dt;
                    int eot = kdb.getEOT(int.Parse((cmb_massaccount.SelectedItem.ToString().Split(':')[0].Trim())));
                    wkrec.id_accaount = Int16.Parse(cmb_massaccount.SelectedItem.ToString().Split(':')[0].Trim());
                    if (eot != 0)
                    {
                        wk = ((string)dgvKBDat.Rows[i].Cells["buy_date"].Value).Split('-');

                        dt = new DateTime(int.Parse(wk[0]), int.Parse(wk[1]), eot);
                        dt = dt.AddMonths(1);
                        wkrec.pay_date = String.Format("{0}-{1}-{2}", dt.Year, dt.Month, dt.Day);
                    }
                    else
                    {
                        wkrec.pay_date = wkrec.buy_date;
                    }
                }
                else
                {
                    wkrec.id_accaount = Int16.Parse(((string)dgvKBDat.Rows[i].Cells["balance"].Value).Split(':')[0].Trim());
                    wkdate = ((string)dgvKBDat.Rows[i].Cells["pay_date"].Value).Split('-');
                    wkrec.pay_date = String.Format("{0}-{1:D2}-{2:D2}", Int32.Parse(wkdate[0]), Int32.Parse(wkdate[1]), Int32.Parse(wkdate[2])); ;

                }
                rec.Add(wkrec);
            }
            kdb.entryKBData(rec);
            updateBalance();
            dgvKBDat.Rows.Clear();
            txtRID.Text = "";
            txtWhere.Text = "";
            lbl_in.Text = "0 円";
            lbl_out.Text = "0 円";
            cmb_massaccount.SelectedIndex = 0;
            txt_masspay.Text = "";

            // cate_sub.Items.Clear();
        }
Esempio n. 2
0
        private void dgvKBList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int h = dgvKBList.Rows[0].Height;

            if ((-1 == e.RowIndex) || (-1 == e.ColumnIndex)) return;

            if ("口座" == dgvKBList.Columns[e.ColumnIndex].HeaderText)
            {
                KBDatabase kdb = new KBDatabase();
                DateTime wkdate;
                string[] wk;
                int eot = -1;	// end of term

                eot = kdb.getEOT(int.Parse((((string)dgvKBList.Rows[e.RowIndex].Cells["col_account"].Value).Split(':')[0].Trim())));

                if ((eot != 0) && (null != dgvKBList.Rows[e.RowIndex].Cells["col_buy_date"].Value))
                {
                    wk = ((string)dgvKBList.Rows[e.RowIndex].Cells["col_buy_date"].Value).Split('-');

                    wkdate = new DateTime(int.Parse(wk[0]), int.Parse(wk[1]), eot);
                    wkdate = wkdate.AddMonths(1);
                    dgvKBList.Rows[e.RowIndex].Cells["col_pay_date"].Value = String.Format("{0}-{1}-{2}", wkdate.Year, wkdate.Month, wkdate.Day);
                }
                else
                {
                    dgvKBList.Rows[e.RowIndex].Cells["col_pay_date"].Value = (string)dgvKBList.Rows[e.RowIndex].Cells["col_buy_date"].Value;
                }
            }
        }
Esempio n. 3
0
        private void dgvKBDat_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string str = "";
            int id_cate_main = -1;
            bool entry = false;
            int h = dgvKBDat.Rows[0].Height;
            int ofs = 0;
            int i = 0;

            if ((-1 == e.RowIndex) || (-1 == e.ColumnIndex)) return;

            # if false
            if ("費目" == dgvKBDat.Columns[e.ColumnIndex].HeaderText)
            {
                id_cate_main = int.Parse(((string)dgvKBDat.Rows[e.RowIndex].Cells["cate_main"].Value).Split(':')[0].Trim());
                //cate_sub.Items.Clear();
                foreach (CateSubRec rec in cate_sub_lst)
                {
                    if (id_cate_main == rec.id_cate_main)
                    {
                        entry = true;
                        str = String.Format("{0, 3}:{1}", rec.id, rec.name);
                        //cate_sub.Items.Add(str);
                        this.lstCateMain.Items.Add(str);
                    }
                    else if (entry)
                    {
                        break;
                    }
                }
                ofs += dgvKBDat.RowHeadersWidth;
                for (i = 0; i < e.ColumnIndex + 1; i++)
                {
                    ofs += dgvKBDat.Columns[i].Width;
                }
                lstCateMain.SetBounds(dgvKBDat.Location.X + ofs, dgvKBDat.Location.Y + h * (e.RowIndex + 2), 100, 80);
                lstCateMain.Visible = true;
            }
            #endif
            if ("口座" == dgvKBDat.Columns[e.ColumnIndex].HeaderText)
            {
                KBDatabase kdb = new KBDatabase();
                DateTime wkdate;
                string[] wk;
                int eot = kdb.getEOT(int.Parse((((string)dgvKBDat.Rows[e.RowIndex].Cells["balance"].Value).Split(':')[0].Trim())));

                if (eot != 0)
                {
                    wk = ((string)dgvKBDat.Rows[e.RowIndex].Cells["buy_date"].Value).Split('-');

                    wkdate = new DateTime(int.Parse(wk[0]), int.Parse(wk[1]), eot);
                    wkdate = wkdate.AddMonths(1);
                    dgvKBDat.Rows[e.RowIndex].Cells["pay_date"].Value = String.Format("{0}-{1}-{2}", wkdate.Year, wkdate.Month, wkdate.Day);
                }
                else
                {
                    dgvKBDat.Rows[e.RowIndex].Cells["pay_date"].Value = (string)dgvKBDat.Rows[e.RowIndex].Cells["buy_date"].Value;
                }
            }
        }
Esempio n. 4
0
        private void btnEntry_Click(object sender, EventArgs e)
        {
            int i = 0;
            int maxid = -1;
            List<KBRec> rec;
            KBRec wkrec;
            KBDatabase kdb = new KBDatabase();
            string[] wkdate;
            int rowcnt = kbDatList_reg.getRowCnt();
            object wkobj = null;
            string err = "";

            rec = new List<KBRec>();
            wkrec = new KBRec();

            maxid = kdb.getMaxKBDatId();
            for (i = 0; i < rowcnt - 1; i++)
            {
                // DB内のインデックスを更新
                wkrec.id = ++maxid;
            #if true
                wkobj = kbDatList_reg.getCellValue(i, "col_buy_date");
                if (null == wkobj)
                {
                    err = String.Format("{0}行目の日付を入力してください", i + 1);
                    MessageBox.Show(err, "入力項目不足");
                    return;
                }
                wkdate = ((string)wkobj).Split('-');
                wkrec.buy_date = String.Format("{0}-{1:D2}-{2:D2}", Int32.Parse(wkdate[0]), Int32.Parse(wkdate[1]), Int32.Parse(wkdate[2])); ;

            #else
                if (null == kbDatList_reg.getCellValue(i, "col_buy_date"))
                {
                    wkrec.buy_date = String.Format("{0}-{1:D2}-{2:D2}", dtp.Value.Year, dtp.Value.Month, dtp.Value.Day);
                }
                else
                {
                    wkdate = ((string)kbDatList_reg.getCellValue(i, "col_buy_date")).Split('-');
                    wkrec.buy_date = String.Format("{0}-{1:D2}-{2:D2}", Int32.Parse(wkdate[0]), Int32.Parse(wkdate[1]), Int32.Parse(wkdate[2])); ;
                }
            #endif
                // 場所
                if (txtWhere.Text.Trim().Length == 0)
                {
                    if (null == kbDatList_reg.getCellValue(i, "col_where"))
                    {
                        wkrec.where = "";
                    }
                    else
                    {
                        wkrec.where = (string)kbDatList_reg.getCellValue(i, "col_where");
                    }
                }
                else
                {
                    wkrec.where = txtWhere.Text;
                }
                wkrec.rid = txtRID.Text.Trim().Length == 0 ? -1 :  Int32.Parse(txtRID.Text);

                if ((null == kbDatList_reg.getCellValue(i, "col_income")) || (0 == ((string)kbDatList_reg.getCellValue(i, "col_income")).Trim().Length))
                {
                    // 支出
                    wkrec.ie_type = 0;
                    wkrec.money = int.Parse(((string)kbDatList_reg.getCellValue(i, "col_payment")).Trim());
                }
                else if ((null == kbDatList_reg.getCellValue(i, "col_payment")) || (0 == ((string)kbDatList_reg.getCellValue(i, "col_payment")).Trim().Length))
                {
                    // 収入
                    wkrec.ie_type = 1;
                    wkrec.money = int.Parse(((string)kbDatList_reg.getCellValue(i, "col_income")).Trim());
                }
                else
                {
                    err = String.Format("{0}行目の金額を入力してください", i + 1);
                    MessageBox.Show(err, "入力項目不足");
                    return;
                }

                // 品名
                wkobj = kbDatList_reg.getCellValue(i, "col_name");
                if (null == wkobj)
                {
                    err = String.Format("{0}行目の品名を入力してください", i+1);
                    MessageBox.Show(err, "入力項目不足");
                    return;
                }
                wkrec.name = (string)wkobj;

                // 費目
                wkobj = kbDatList_reg.getCellValue(i, "col_cate_main");
                if (null == wkobj)
                {
                    err = String.Format("{0}行目の費目を入力してください", i + 1);
                    MessageBox.Show(err, "入力項目不足");
                    return;
                }
                wkrec.cate_main = Int16.Parse(((string)wkobj).Split(':')[0].Trim());

                // 詳細
                wkobj = kbDatList_reg.getCellValue(i, "col_cate_sub");
                if (null == wkobj)
                {
                    err = String.Format("{0}行目の詳細を入力してください", i + 1);
                    MessageBox.Show(err, "入力項目不足");
                    return;
                }
                wkrec.cate_sub = Int16.Parse(((string)wkobj).Split(':')[0].Trim());

                // ユーザID
                wkrec.id_usr = this.id_usr;

                // メモ
                wkobj = kbDatList_reg.getCellValue(i, "col_memo");
                if ((null == wkobj) || (((string)wkobj).Trim().Length == 0))
                {
                    wkrec.memo = "";
                }
                else
                {
                    wkrec.memo = (string)wkobj;
                }

                // 口座
                if (cmb_massaccount.SelectedIndex != 0)
                {
                    string[] wk;
                    DateTime dt;
                    int eot = kdb.getEOT(int.Parse((cmb_massaccount.SelectedItem.ToString().Split(':')[0].Trim())));
                    wkrec.id_accaount = Int16.Parse(cmb_massaccount.SelectedItem.ToString().Split(':')[0].Trim());
                    if (eot != 0)
                    {
                        wk = wkrec.buy_date.Split('-');

                        dt = new DateTime(int.Parse(wk[0]), int.Parse(wk[1]), eot);
                        dt = dt.AddMonths(1);
                        wkrec.pay_date = String.Format("{0}-{1}-{2}", dt.Year, dt.Month, dt.Day);
                    }
                    else
                    {
                        wkrec.pay_date = wkrec.buy_date;
                    }
                }
                else
                {
                    wkobj = kbDatList_reg.getCellValue(i, "col_account");
                    if (null == wkobj)
                    {
                        err = String.Format("{0}行目の口座を入力してください", i + 1);
                        MessageBox.Show(err, "入力項目不足");
                        return;
                    }
                    wkrec.id_accaount = Int16.Parse(((string)wkobj).Split(':')[0].Trim());

                    wkobj = kbDatList_reg.getCellValue(i, "col_pay_date");
                    if (null == wkobj)
                    {
                        err = String.Format("{0}行目の取扱日を入力してください", i + 1);
                        MessageBox.Show(err, "入力項目不足");
                        return;
                    }
                    wkdate = ((string)wkobj).Split('-');
                    wkrec.pay_date = String.Format("{0}-{1:D2}-{2:D2}", Int32.Parse(wkdate[0]), Int32.Parse(wkdate[1]), Int32.Parse(wkdate[2])); ;

                }
                rec.Add(wkrec);
            }
            // DBに登録
            kdb.entryKBData(rec);
            updateBalance();
            kbDatList_reg.rowClear();
            txtRID.Text = "";
            txtWhere.Text = "";
            lbl_in.Text = "0 円";
            lbl_out.Text = "0 円";
            cmb_massaccount.SelectedIndex = 0;
            txt_masspay.Text = "";

            // cate_sub.Items.Clear();
        }