コード例 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            BugImageDAO    imageDAO      = new BugImageDAO();
            SourceCodeDAO  codeDAO       = new SourceCodeDAO();
            ControlLinkDAO sourceControl = new ControlLinkDAO();
            BugDAO         bugDAO        = new BugDAO();

            DialogResult dr = MessageBox.Show("Are you sure want to delete this bug?", "Are you sure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

            if (dr == DialogResult.Yes)
            {
                try
                {
                    codeDAO.Delete(bugId);
                    imageDAO.Delete(bugId);
                    bugDAO.Delete(bugId);
                    sourceControl.Delete(bugId);

                    MessageBox.Show("Deleted");
                    this.Dispose();
                    new Bugs().Show();
                } catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: UttamBhandari/Bug-Tracking
        private void button3_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(comboBox1.SelectedItem.ToString()) || string.IsNullOrEmpty(textBox2.Text) || string.IsNullOrEmpty(textBox3.Text) || string.IsNullOrEmpty(textBox4.Text) || string.IsNullOrEmpty(textBox5.Text) || string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox6.Text) || string.IsNullOrEmpty(textBox7.Text))
            {
                MessageBox.Show("You must add all project information");
            }
            else if (string.IsNullOrEmpty(fastColoredTextBox1.Text))
            {
                MessageBox.Show("Code field cann't be null");
            }
            else
            {
                //bug
                Bug bug = new Bug
                {
                    ProjectName  = comboBox1.SelectedItem.ToString(),
                    ClassName    = textBox2.Text,
                    MethodName   = textBox3.Text,
                    StartLine    = Convert.ToInt16(textBox4.Text),
                    EndLine      = Convert.ToInt16(textBox5.Text),
                    ProgrammerId = UserLogin.userId,
                    Status       = "0"
                };

                try
                {
                    BugDAO bugDao = new BugDAO();
                    bugDao.Insert(bug);
                    inserted = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //image


                if (!string.IsNullOrEmpty(imageName))
                {
                    string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\code_image\";
                    Bug_Tracker.Model.BugImage image = new Bug_Tracker.Model.BugImage
                    {
                        ImagePath = "code_image",
                        ImageName = ImageName,
                        BugId     = bug.BugId
                    };

                    try
                    {
                        BugImageDAO codeDao = new BugImageDAO();
                        codeDao.Insert(image);

                        File.Copy(imageName, appPath + ImageName);

                        inserted1 = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ////code
                string c            = fastColoredTextBox1.Text;
                string codeFileName = DateTime.Now.Second.ToString();

                SourceCode code = new SourceCode
                {
                    CodePath     = "code",
                    CodeFileName = codeFileName,
                    Language     = programminLanguage,
                    BugId        = bug.BugId
                };

                try
                {
                    SourceCodeDAO codeDao = new SourceCodeDAO();
                    codeDao.Insert(code);

                    string path = "code/" + codeFileName + ".txt";
                    if (!File.Exists(path))
                    {
                        // Create a file to write to.
                        using (StreamWriter sw = File.CreateText(path))
                        {
                            sw.WriteLine(c);
                        }
                    }

                    inserted2 = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }


                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ////Link

                Model.ControlLink sourceControl = new Model.ControlLink
                {
                    CodeLink  = textBox1.Text,
                    StartLine = Convert.ToInt32(textBox6.Text),
                    EndLine   = Convert.ToInt32(textBox7.Text),
                    BugId     = bug.BugId
                };

                DAO.ControlLinkDAO sourceControlDAO = new DAO.ControlLinkDAO();

                try
                {
                    sourceControlDAO.Insert(sourceControl);
                    inserted3 = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }


                if (inserted && inserted1 && inserted2)
                {
                    MessageBox.Show("Added");
                }
                else
                {
                    MessageBox.Show("Unable to add");
                }
            }
        }