Пример #1
0
        private void button5_Click(object sender, EventArgs e)
        //配布エリアの町名を一括登録する
        {
            if (MessageBox.Show("選択されている町名を一括追加登録します。よろしいですか?", "登録確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            foreach (DataGridViewRow r in dataGridView3.SelectedRows)
            {
                txtAreaID.Text     = dataGridView3[0, r.Index].Value.ToString();
                txtHaihuMaisu.Text = "0";

                if (fDataCheck() == true)
                {
                    Control.配布エリア dArea = new Control.配布エリア();
                    if (dArea.DataInsert(cArea) == false)
                    {
                        MessageBox.Show(dataGridView3[1, r.Index].Value.ToString() + "の新規登録に失敗しました", "町名一括登録", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    dArea.Close();
                }
            }

            DispClear2();

            txtAreaID.Focus();

            //配布エリア再表示
            GridviewSet.AreaShowData(dataGridView2, long.Parse(txtID.Text.ToString()));
            MaisuSum();
        }
Пример #2
0
        private void txtAdd_Click(object sender, EventArgs e)
        {
            //配布エリア登録
            try
            {
                if (fDataCheck() == true)
                {
                    Control.配布エリア dArea = new Control.配布エリア();

                    switch (aMode.Mode)
                    {
                    case 0:     //新規登録
                        if (MessageBox.Show("新規登録します。よろしいですか?", "登録確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            break;
                        }

                        if (dArea.DataInsert(cArea) == false)
                        {
                            MessageBox.Show("新規登録に失敗しました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }

                        break;

                    case 1:     //更新
                        if (MessageBox.Show("更新します。よろしいですか?", "更新確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            break;
                        }

                        if (dArea.DataUpdate(cArea) == false)
                        {
                            MessageBox.Show("更新に失敗しました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }

                        break;
                    }

                    dArea.Close();

                    DispClear2();

                    txtAreaID.Focus();

                    //配布エリア再表示
                    GridviewSet.AreaShowData(dataGridView2, long.Parse(txtID.Text.ToString()));
                    MaisuSum();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MESSAGE_CAPTION + "保守", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Пример #3
0
        private void GetExcelPos()
        {
            DialogResult ret;

            //ダイアログボックスの初期設定
            openFileDialog1.Title            = "ポスティングエリア表の選択";
            openFileDialog1.CheckFileExists  = true;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.FileName         = "";
            openFileDialog1.Filter           = "Microsoft Office Excelファイル(*.xls)|*.xls|全てのファイル(*.*)|*.*";

            //ダイアログボックスの表示
            ret = openFileDialog1.ShowDialog();
            if (ret == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            if (MessageBox.Show(openFileDialog1.FileName + Environment.NewLine + " が選択されました。よろしいですか?", "ポスティングエリアExcelシート取り込み", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            const int S_GYO = 2;    //エクセルファイル見出し行(明細は2行目から)

            //マウスポインタを待機にする
            this.Cursor = Cursors.WaitCursor;

            //string sAppPath = System.AppDomain.CurrentDomain.BaseDirectory;

            Excel.Application oXls = new Excel.Application();

            Excel.Workbook oXlsBook = (Excel.Workbook)(oXls.Workbooks.Open(openFileDialog1.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                           Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                           Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                           Type.Missing, Type.Missing));

            Excel.Worksheet oxlsSheet = (Excel.Worksheet)oXlsBook.Sheets[1];

            Excel.Range   dRng;
            Excel.Range[] rng = new Microsoft.Office.Interop.Excel.Range[2];

            int    iX  = S_GYO;
            int    Cnt = 0;
            int    err;
            string cellID;
            string cellMaisu;
            int    d;

            try
            {
                while (true)
                {
                    err = 0;

                    //エリアID
                    dRng = (Excel.Range)oxlsSheet.Cells[iX, 1];

                    //空白なら処理終了
                    if ((dRng.Text.ToString().Trim() + "") == "")
                    {
                        break;
                    }

                    cellID = dRng.Text.ToString().Trim();

                    //IDチェック
                    if (cellID == null)
                    {
                        err = 1;
                        MessageBox.Show("エリアIDが正しくありません。この行はスキップされます。 " + Environment.NewLine + iX.ToString() + "行目 : " + cellID, "取り込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (int.TryParse(cellID, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d) == false)
                    {
                        err = 1;
                        MessageBox.Show("エリアIDが正しくありません。この行はスキップされます。 " + Environment.NewLine + iX.ToString() + "行目 : " + cellID, "取り込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (Int32.Parse(cellID, System.Globalization.NumberStyles.Any) < 0)
                    {
                        err = 1;
                        MessageBox.Show("エリアIDが正しくありません。この行はスキップされます。 " + Environment.NewLine + iX.ToString() + "行目 : " + cellID, "取り込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    //配布枚数
                    dRng      = (Excel.Range)oxlsSheet.Cells[iX, 3];
                    cellMaisu = dRng.Text.ToString().Trim();

                    //チェック
                    if (cellMaisu == null)
                    {
                        err = 1;
                        MessageBox.Show("配布枚数が正しくありません。この行はスキップされます。 " + Environment.NewLine + iX.ToString() + "行目 : " + cellMaisu, "取り込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (int.TryParse(cellMaisu, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d) == false)
                    {
                        err = 1;
                        MessageBox.Show("配布枚数が正しくありません。この行はスキップされます。 " + Environment.NewLine + iX.ToString() + "行目 : " + cellMaisu, "取り込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (Int32.Parse(cellMaisu, System.Globalization.NumberStyles.Any) < 0)
                    {
                        err = 1;
                        MessageBox.Show("配布枚数が正しくありません。この行はスキップされます。 " + Environment.NewLine + iX.ToString() + "行目 : " + cellMaisu, "取り込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    //エラーのときは読み飛ばし
                    if (err == 0)
                    {
                        txtAreaID.Text     = cellID.ToString();
                        txtHaihuMaisu.Text = cellMaisu.ToString();

                        if (fDataCheck() == true)
                        {
                            Control.配布エリア dArea = new Control.配布エリア();
                            if (dArea.DataInsert(cArea) == false)
                            {
                                MessageBox.Show("新規登録に失敗しました", "Excelシート取り込み", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                Cnt++;
                            }

                            dArea.Close();
                        }
                    }

                    iX++;
                }

                MessageBox.Show(Cnt.ToString() + " 件の配布エリアを取り込みました", "取り込み終了", MessageBoxButtons.OK, MessageBoxIcon.Information);

                //マウスポインタを元に戻す
                this.Cursor = Cursors.Default;

                // 確認のためExcelのウィンドウを表示する
                //oXls.Visible = true;

                //印刷
                //oxlsSheet.PrintPreview(true);

                //保存処理
                oXls.DisplayAlerts = false;

                //Bookをクローズ
                oXlsBook.Close(Type.Missing, Type.Missing, Type.Missing);

                //Excelを終了
                oXls.Quit();
            }

            catch (Exception e)
            {
                MessageBox.Show(e.Message, "印刷", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            finally
            {
                // COM オブジェクトの参照カウントを解放する
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oxlsSheet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oXlsBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oXls);

                //マウスポインタを元に戻す
                this.Cursor = Cursors.Default;
            }


            DispClear2();

            txtAreaID.Focus();

            //配布エリア再表示
            GridviewSet.AreaShowData(dataGridView2, long.Parse(txtID.Text.ToString()));

            MaisuSum();
        }
Пример #4
0
        //グリッドからデータを選択
        private void GridEnter()
        {
            try
            {
                if (MessageBox.Show(dataGridView1[3, dataGridView1.SelectedRows[0].Index].Value.ToString() + " が選択されました。よろしいですか?", "登録確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }

                DispClear();

                //データを取得する
                OleDbDataReader dr;
                Control.受注      cOrder = new Control.受注();
                dr = cOrder.FillBy("where ID = " + dataGridView1[0, dataGridView1.SelectedRows[0].Index].Value.ToString());

                if (dr.HasRows == false)
                {
                    MessageBox.Show("該当するデータが登録されていません", "検索エラー", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                //'データ値を取得
                while (dr.Read())
                {
                    txtID.Text    = dr["ID"].ToString();
                    txtCName.Text = "";
                    label8.Text   = int.Parse(dr["枚数"].ToString()).ToString("#,##0");
                    label11.Text  = double.Parse(dr["配布単価"].ToString(), System.Globalization.NumberStyles.Any).ToString("#,##0.00");

                    //得意先名
                    OleDbDataReader drt;
                    Control.得意先     Client = new Control.得意先();
                    drt = Client.FillBy("where ID = " + dr["得意先ID"].ToString());

                    while (drt.Read())
                    {
                        txtCName.Text = drt["略称"].ToString();
                    }

                    drt.Close();

                    txtChirashi.Text = dr["チラシ名"].ToString();
                }

                dr.Close();

                cOrder.Close();

                //配布エリアデータ表示
                GridviewSet.AreaShowData(dataGridView2, long.Parse(txtID.Text.ToString()));
                MaisuSum();

                //txtTotal.Text = GetMaisuTotal().ToString("#,##0");
                //int Zan;
                //Zan = Int32.Parse(textBox2.Text, System.Globalization.NumberStyles.Any) - Int32.Parse(txtTotal.Text, System.Globalization.NumberStyles.Any);
                //textBox3.Text = Zan.ToString("#,##0");

                //ボタン表示
                txtAdd.Enabled    = true;
                txtAdel.Enabled   = true;
                txtAclear.Enabled = true;

                button2.Enabled = true;
                button4.Enabled = true;

                tabPage3.Text = txtChirashi.Text + " : ポスティングエリア表";

                txtAreaID.Enabled     = true;
                txtAreaName.Enabled   = true;
                txtHaihuMaisu.Enabled = true;
                textBox5.Enabled      = true;

                txtAreaID.Focus();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "データ表示", MessageBoxButtons.OK);
            }
        }
Пример #5
0
        private void txtAdel_Click(object sender, EventArgs e)
        {
            if (dataGridView2.SelectedRows.Count == 0)
            {
                MessageBox.Show("ポスティングエリアデータが選択されていません", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (MessageBox.Show("選択された " + dataGridView2.SelectedRows.Count.ToString() + "件のポスティングエリアデータを削除します。よろしいですか?", "削除確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                dataGridView2.CurrentCell = null;
                return;
            }

            foreach (DataGridViewRow r in dataGridView2.SelectedRows)
            {
                int aID;
                aID = int.Parse(dataGridView2[0, r.Index].Value.ToString(), System.Globalization.NumberStyles.Any);

                //レコード削除
                Control.配布エリア dArea = new Control.配布エリア();

                if (dArea.DataDelete(aID) == false)
                {
                    MessageBox.Show("削除に失敗しました。エリアID:" + aID.ToString(), MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                dArea.Close();
            }

            DispClear2();

            //配布エリア再表示
            GridviewSet.AreaShowData(dataGridView2, long.Parse(txtID.Text.ToString()));
            MaisuSum();



            ////削除
            //if (MessageBox.Show(txtAreaName.Text + " を削除します。よろしいですか?", "削除確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            //    return;

            ////データ削除
            //Control.配布エリア dArea = new Control.配布エリア();
            //if (dArea.DataDelete(cArea.ID) == true)
            //{
            //    MessageBox.Show("削除されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            //else
            //{
            //    MessageBox.Show("削除に失敗しました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}

            //dArea.Close();

            //DispClear2();

            ////配布エリア再表示
            //GridviewSet.AreaShowData(dataGridView2, long.Parse(txtID.Text.ToString()));
            //MaisuSum();
        }