コード例 #1
0
        public txt_chuumoncode2(DataGridView dg)
        {
            InitializeComponent();
            textBox1.Text = "true";

            string columnName = dg.Columns[0].Name;

            prueba.Text = columnName;

            /*
             *
             *
             * from here add nith
             */


            if (prueba.Text == "注文コード")
            {
                Register.Enabled = false;
                button2.Enabled  = false;
                ExitBtn.Enabled  = false;
                this.ControlBox  = false;


                OleDbConnection olecon = new OleDbConnection();

                olecon.ConnectionString =
                    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=HacchuuKannri.accdb;";

                try
                {
                    olecon.Open();
                    OleDbCommand ocmd = new OleDbCommand();
                    ocmd.Connection = olecon;

                    //ocmd.CommandText = "SELECT * FROM 会員管理";
                    ocmd.CommandText = "SELECT TOP 1 * FROM 発注 ORDER BY 発注コード DESC";


                    OleDbDataAdapter adapter = new OleDbDataAdapter(ocmd);
                    DataTable        dt      = new DataTable();
                    adapter.Fill(dt);

                    txt_hacchuunum.Text = dt.Rows[0]["発注値"].ToString();
                    int i = int.Parse(txt_hacchuunum.Text);
                    i += 1;
                    txt_hacchuunum.Text  = i.ToString();
                    txt_hacchuucode.Text = "H" + i.ToString("000");

                    txt_arrival.Text = dt.Rows[0]["着荷"].ToString();
                    textBox2.Text    = dt.Rows[0]["注文コード"].ToString();
                    if (textBox2.Text != "")
                    {
                        mise_id   = dt.Rows[0]["店コード"].ToString();
                        mise_name = dt.Rows[0]["店名"].ToString();
                    }
                    olecon.Close();
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex);
                }



                int kakakufinal = 0;

                for (int i = 0; i < dg.RowCount - 1; i++)
                {
                    // if (Convert.ToDouble(dg.Rows[i].Cells[13].Value) < 50)
                    // {

                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[i].Cells[3].Value       = dg.Rows[i].Cells[0].Value; // 注文コード
                    dataGridView1.Rows[i].Cells[6].Value       = dg.Rows[i].Cells[1].Value;
                    dataGridView1.Rows[i].Cells[7].Value       = dg.Rows[i].Cells[2].Value;
                    dataGridView1.Rows[i].Cells[2].Value       = dg.Rows[i].Cells[3].Value;
                    dataGridView1.Rows[i].Cells[1].Value       = dg.Rows[i].Cells[4].Value;
                    dataGridView1.Rows[i].Cells[4].Value       = dg.Rows[i].Cells[5].Value;
                    dataGridView1.Rows[i].Cells[5].Value       = dg.Rows[i].Cells[6].Value;
                    dataGridView1.Rows[i].Cells[11].Value      = dg.Rows[i].Cells[7].Value;
                    dataGridView1.Rows[i].Cells[9].Value       = dg.Rows[i].Cells[8].Value;
                    dataGridView1.Rows[i].Cells[10].Value      = dg.Rows[i].Cells[10].Value;
                    dataGridView1.Rows[i].Cells[12].Value      = txt_hacchuunum.Text;
                    dataGridView1.Rows[i].Cells[0].Value       = txt_hacchuucode.Text;
                    dataGridView1.Rows[i].Cells[8].Value       = dg.Rows[i].Cells[14].Value;
                    dataGridView1.Rows[i].Cells["new在庫"].Value = 50;
                    // kakakufinal+=Convert.ToInt32(dg.Rows[i].Cells[10].Value);
                    //txt_totalprice_final.Text = kakakufinal.ToString();
                    //  }
                }


                for (int i = dataGridView1.Rows.Count - 1; i > -1; i--)
                {
                    DataGridViewRow row = dataGridView1.Rows[i];
                    //if (!row.IsNewRow && row.Cells[0].Value == null)
                    if (Convert.ToInt32(dataGridView1.Rows[i].Cells[8].Value) < 0)
                    {
                        dataGridView1.Rows.RemoveAt(i);
                    }
                }

                for (int o = 0; o < dg.RowCount - 1; o++)
                {
                    kakakufinal     += Convert.ToInt32(dg.Rows[o].Cells[10].Value);
                    total_price.Text = kakakufinal.ToString();
                }
            }

            else
            {
                dataGridView1.AutoGenerateColumns = false;
                int sum            = 0;
                txt_chuumoncode2 n = new txt_chuumoncode2();
                for (int i = 0; i < dg.RowCount - 1; i++)
                {
                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[i].Cells["発注コード"].Value  = n.txt_hacchuucode.Text;    // 発注コード
                    dataGridView1.Rows[i].Cells["商品コード"].Value  = dg.Rows[i].Cells[0].Value; // 商品コード
                    dataGridView1.Rows[i].Cells["商品名"].Value    = dg.Rows[i].Cells[1].Value; // 商品名
                    dataGridView1.Rows[i].Cells["出版社コード"].Value = dg.Rows[i].Cells[4].Value; // 出版社コード
                    dataGridView1.Rows[i].Cells["出版社名"].Value   = dg.Rows[i].Cells[3].Value; // 出版社名

                    int hachuu_num = 50 - Convert.ToInt32(dg.Rows[i].Cells[6].Value);
                    dataGridView1.Rows[i].Cells["発注数量"].Value = hachuu_num;                  //発注数量

                    dataGridView1.Rows[i].Cells["単価"].Value = dg.Rows[i].Cells[7].Value;     // 単価

                    int money = hachuu_num * Convert.ToInt32(dg.Rows[i].Cells[7].Value);
                    dataGridView1.Rows[i].Cells["金額"].Value = money;                            //金額



                    dataGridView1.Rows[i].Cells["発注日付"].Value = dateTimePicker1.Value.ToString("yyyy/MM/dd"); //発注日付

                    dataGridView1.Rows[i].Cells["発注値"].Value   = n.txt_hacchuunum.Text;                       //発注値
                    dataGridView1.Rows[i].Cells["注文コード"].Value = "";                                          //注文コード
                    dataGridView1.Rows[i].Cells["店コード"].Value  = "";                                          //店コード
                    dataGridView1.Rows[i].Cells["店名"].Value    = "";                                          //店名
                    //if(dg.Rows[i].)
                    dataGridView1.Rows[i].Cells["new在庫"].Value = 50;                                          //new在庫
                    dataGridView1.Rows[i].Cells["チェック"].Value  = dg.Rows[i].Cells[8].Value;                   //チェック
                }


                for (int i = dataGridView1.Rows.Count - 1; i > -1; i--)
                {
                    //DataGridViewRow row = dataGridView1.Rows[i];
                    if (Convert.ToInt32(dataGridView1.Rows[i].Cells["チェック"].Value) == 0 || Convert.ToInt32(dataGridView1.Rows[i].Cells["発注数量"].Value) <= 0)
                    {
                        dataGridView1.Rows.RemoveAt(i);
                    }
                }

                //if (txt_totalprice_final.Text == "")

                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    //have_data.Text += dataGridView1.Rows[i].Cells["金額"].Value.ToString();
                    sum += Convert.ToInt32(dataGridView1.Rows[i].Cells["金額"].Value);
                    //sum += sum;
                    total_price.Text = sum.ToString();
                }
            }


            dataGridView1.Columns["new在庫"].Visible = false;
        }
コード例 #2
0
        private void add_hacchuu_btn_Click(object sender, EventArgs e)
        {
            txt_chuumoncode2 f = new txt_chuumoncode2();

            f.ShowDialog();
        }