コード例 #1
0
ファイル: FormAlert.cs プロジェクト: PaulUChen/SprisWarehouse
        private void Orderbutton_Click(object sender, EventArgs e)
        {
            FormOrderList f = new FormOrderList();//產生Form2的物件,才可以使用它所提供的Method

            OrderTable = new DataTable();
            OrderTable.Columns.Add("物品名稱", typeof(string));
            OrderTable.Columns.Add("目前數量", typeof(string));
            //OrderTable.Columns.Add("提取數量", typeof(string));
            OrderTable.Columns.Add("製造日期", typeof(DateTime));
            OrderTable.Columns.Add("有效日期", typeof(DateTime));
            int events = 0;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];

                if (check != null && ((bool)check.EditingCellFormattedValue == true || (bool)check.FormattedValue == true))
                {
                    txtChooseProductName.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    txtStock.Text             = dataGridView1.Rows[i].Cells[5].Value.ToString();
                    txtCreateDate.Text        = dataGridView1.Rows[i].Cells[3].Value.ToString();
                    txtExpiryDate.Text        = dataGridView1.Rows[i].Cells[4].Value.ToString();
                    DataRow dataRow = OrderTable.NewRow();
                    dataRow["物品名稱"] = txtChooseProductName.Text.ToString();
                    dataRow["目前數量"] = txtStock.Text.ToString();
                    if (txtCreateDate.Text.ToString() != "")
                    {
                        dataRow["製造日期"] = txtCreateDate.Text.ToString();
                    }
                    if (txtExpiryDate.Text.ToString() != "")
                    {
                        dataRow["有效日期"] = txtExpiryDate.Text.ToString();
                    }
                    OrderTable.Rows.Add(dataRow);
                    events = events + 1;
                }
            }
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)dataGridView2.Rows[i].Cells[0];

                if (check != null && ((bool)check.EditingCellFormattedValue == true || (bool)check.FormattedValue == true))
                {
                    txtChooseProductName.Text = dataGridView2.Rows[i].Cells[1].Value.ToString();
                    txtStock.Text             = dataGridView2.Rows[i].Cells[5].Value.ToString();
                    txtCreateDate.Text        = dataGridView2.Rows[i].Cells[3].Value.ToString();
                    txtExpiryDate.Text        = dataGridView2.Rows[i].Cells[4].Value.ToString();
                    DataRow dataRow = OrderTable.NewRow();
                    dataRow["物品名稱"] = txtChooseProductName.Text.ToString();
                    dataRow["目前數量"] = txtStock.Text.ToString();
                    if (txtCreateDate.Text.ToString() != "")
                    {
                        dataRow["製造日期"] = txtCreateDate.Text.ToString();
                    }
                    if (txtExpiryDate.Text.ToString() != "")
                    {
                        dataRow["有效日期"] = txtExpiryDate.Text.ToString();
                    }
                    OrderTable.Rows.Add(dataRow);
                    events = events + 1;
                }
            }
            if (events != 0)
            {
                UserID = LoginUserID;
                Date   = dateTimePicker1.Value.ToString("yyyy/MM/dd");
                f.f2   = this;
                f.ShowDialog();
            }
            else
            {
                MessageBox.Show("請勾選欲提取之物品");
            }

            //Update
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = bindingSource1;
            GetData("select * from product WHERE ExpiryDate <= DATEADD(m,+0,GetDate()) AND  ExpiryDate > '1900/1/1'", bindingSource1);
            dataGridView2.DataSource = null;
            dataGridView2.DataSource = bindingSource2;
            GetData("select * from product WHERE ExpiryDate Between DATEADD(m,+0,GetDate()) AND DATEADD(m,+2,GetDate()) ", bindingSource2);
        }
コード例 #2
0
        private void NextPageButton_Click(object sender, EventArgs e)
        {
            FormOrderList f = new FormOrderList();//產生Form2的物件,才可以使用它所提供的Method

            //this.Visible = false;//將Form1隱藏。由於在Form1的程式碼內使用this,所以this為Form1的物件本身
            //f.Visible = true;//顯示第二個視窗
            OrderTable = new DataTable();
            OrderTable.Columns.Add("物品名稱", typeof(string));
            OrderTable.Columns.Add("目前數量", typeof(string));
            //OrderTable.Columns.Add("提取數量", typeof(string));
            OrderTable.Columns.Add("製造日期", typeof(DateTime));
            OrderTable.Columns.Add("有效日期", typeof(DateTime));
            int events = 0;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];

                if (check != null && ((bool)check.EditingCellFormattedValue == true || (bool)check.FormattedValue == true))
                {
                    txtChooseProductName.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    txtStock.Text             = dataGridView1.Rows[i].Cells[8].Value.ToString();
                    txtCreateDate.Text        = dataGridView1.Rows[i].Cells[4].Value.ToString();
                    txtExpiryDate.Text        = dataGridView1.Rows[i].Cells[5].Value.ToString();
                    DataRow dataRow = OrderTable.NewRow();
                    dataRow["物品名稱"] = txtChooseProductName.Text.ToString();
                    dataRow["目前數量"] = txtStock.Text.ToString();
                    if (txtCreateDate.Text.ToString() != "")
                    {
                        dataRow["製造日期"] = txtCreateDate.Text.ToString();
                    }
                    if (txtExpiryDate.Text.ToString() != "")
                    {
                        dataRow["有效日期"] = txtExpiryDate.Text.ToString();
                    }

                    OrderTable.Rows.Add(dataRow);
                    events = events + 1;
                }
            }
            if (events != 0)
            {
                if (LoginUserID == "1")
                {
                    UserID   = UserComboBox.SelectedValue.ToString();
                    Username = UserComboBox.Text.ToString();
                    Date     = OrderDate.Value.ToString("yyyy/MM/dd");
                }
                else //除管理者外,其餘使用者只能以自身身分提領
                {
                    UserID = LoginUserID;
                    SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Spris;Persist Security Inf" +
                                                           "o=True;User ID=sa;Password=99437510");
                    try
                    {
                        conn.Open();
                        try
                        {
                            String        SQLUserName = "******" + UserID + "'";
                            SqlCommand    cmdUserName = new SqlCommand(SQLUserName, conn);
                            SqlDataReader UserRead    = cmdUserName.ExecuteReader();
                            while (UserRead.Read())
                            {
                                Username = UserRead[0].ToString();
                            }
                            UserRead.Close();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                    Date = OrderDate.Value.ToString("yyyy/MM/dd");
                }

                f.f1 = this;
                f.ShowDialog();
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = bindingSource1;
                GetData("SELECT * from Product");
            }
            else
            {
                MessageBox.Show("請勾選欲提取之物品");
            }
        }