コード例 #1
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            MySqlConnection conn  = new MySqlConnection("server = localhost; user id = root; database = bugbase");
            int             BugID = 0;

            if (textBox_bugid.Text.Trim() != "")
            {
                BugID = int.Parse(textBox_bugid.Text.Trim());
            }
            string ProjectTitle   = comboBox_project.Text.ToString();
            string BugTitle       = textBox_bugtitle.Text.Trim();
            string BugDescription = textBox_bugissue.Text.Trim();
            string ReportDate     = reportDate.Text.Trim();
            string ImagePath      = lbl_img_path.Text.Trim();
            string status         = combo_bugStatus.Text.ToString();

            //Getting loggedin user in added by field
            string loggeduser = LoginForm.uname;
            string reportedby = loggeduser;

            ReportDate = DateTime.Now.ToString("yyyy-MM-dd");


            try
            {
                //Database connection
                MySqlCommand sda = new MySqlCommand("INSERT INTO bugreport (project, bugtitle, bugissue, reportdate,status,image,reportedby) VALUES ('" + this.comboBox_project.Text + "','" + this.textBox_bugtitle.Text + "','" + this.textBox_bugissue.Text + "','" + this.reportDate.Text + "','" + this.combo_bugStatus.Text + "','" + this.lbl_img_path.Text + "',@reportedby)", conn);
                sda.Parameters.AddWithValue("@reportedby", reportedby);
                conn.Open();
                int rows = sda.ExecuteNonQuery();

                if (rows > 0)
                {
                    MessageBox.Show("Bug added to database. click ok to continue");
                    //Refresh Data Grid View
                    BugReport vb = new BugReport();
                    DataTable dt = vb.Select_bug();
                    dataGridView.DataSource = dt;
                    //Clear all the Input fields
                    textBox_bugid.Clear();
                    comboBox_project.Text = "";
                    textBox_bugtitle.Clear();
                    textBox_bugissue.Clear();
                    reportDate.Text      = "";
                    lbl_img_path.Text    = "path";
                    combo_bugStatus.Text = "";
                }
                else
                {
                    MessageBox.Show("Bug failed to database. click ok to continue");
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                //Step :CLose Connection
                conn.Close();
            }
        }
コード例 #2
0
ファイル: UserPanel.cs プロジェクト: Apocrypha007/MyHackSpace
        private void button1_Click(object sender, EventArgs e)
        {
            BugReport b = new BugReport();

            b.Show();
        }
コード例 #3
0
        private void button_update_Click(object sender, EventArgs e)
        {
            MySqlConnection conn  = new MySqlConnection("server = localhost; user id = root; database = bugbase");
            int             BugID = 0;

            if (textBox_bugid.Text.Trim() != "")
            {
                BugID = int.Parse(textBox_bugid.Text.Trim());
            }
            string ProjectTitle   = comboBox_project.Text.ToString();
            string BugTitle       = textBox_bugtitle.Text.Trim();
            string BugDescription = textBox_bugissue.Text.Trim();
            string ReportDate     = reportDate.Text.Trim();
            string ImagePath      = lbl_img_path.Text.Trim();
            string status         = combo_bugStatus.Text.ToString();
            string loggedusertype = LoginForm.usertype;

            string reportedby = loggedusertype;

            ReportDate = DateTime.Now.ToString("yyyy-MM-dd");


            try
            {
                //Database connection
                MySqlCommand sda = new MySqlCommand("update bugreport set project='" + this.comboBox_project.Text + "',bugtitle='" + this.textBox_bugtitle.Text + "',bugissue='" + this.textBox_bugissue.Text + "',reportdate='" + this.reportDate.Text + "',status='" + this.combo_bugStatus.Text + "',image='" + this.lbl_img_path.Text + "' where bugreport.id='" + this.textBox_bugid.Text + "'", conn);
                conn.Open();

                int rows = sda.ExecuteNonQuery();

                if (rows > 0)
                {
                    MessageBox.Show("Bug updated. click ok to continue");
                    //Refresh Data Grid View
                    BugReport vb = new BugReport();
                    DataTable dt = vb.Select_bug();
                    dataGridView.DataSource = dt;
                    //Clearing the fields
                    textBox_bugid.Clear();
                    comboBox_project.Text = "";
                    textBox_bugtitle.Clear();
                    textBox_bugissue.Clear();
                    reportDate.Text      = "";
                    lbl_img_path.Text    = "path";
                    combo_bugStatus.Text = "";
                }
                else
                {
                    MessageBox.Show("Bug failed to update. click ok to continue");
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                //Close Connection
                conn.Close();
            }
        }