Exemplo n.º 1
0
        private void Execute_Click(object sender, EventArgs e)
        {
            try
            {
                if(String.IsNullOrWhiteSpace(querySqlBox.Text))
                {
                    StatusLabel.ForeColor = Color.Red;
                    StatusLabel.Text = "Field is empty!";
                }
                else
                {

                    DB db = new DB();
                    dataGridView.DataSource = db.Read(querySqlBox.Text);

                    StatusLabel.ForeColor = Color.Green;
                    StatusLabel.Text = "Success!";
                }
            }
            catch (SqlException exept)
            {
                StatusLabel.ForeColor = Color.Red;
                StatusLabel.Text = exept.Message;

            }
            try
            {
                using (StreamReader sr = new StreamReader(ConfigurationManager.ConnectionStrings["DefaultTask"].ConnectionString))
                {
                    String contents = sr.ReadToEnd();
                    var listTask = JsonConvert.DeserializeObject<List<TaskControl>>(contents);
                    var corrTask = listTask[taskNum];
                    String correctHash = corrTask.correctSQL;
                    DB db = new DB();
                    HashSum currHS = new HashSum(db.Read(querySqlBox.Text));
                    String currentHash = currHS.GetHashString();

                    if (currentHash==correctHash)
                    {
                        ResultLabel.ForeColor = Color.Green;
                        ResultLabel.Text = "Test passed!";
                        this.result = true;

                    }
                    else
                    {
                        ResultLabel.ForeColor = Color.Red;
                        ResultLabel.Text = "Test failed!";
                    }

                };
            }
            catch (Exception exept)
            {
               ResultLabel.ForeColor = Color.Red;
               ResultLabel.Text = exept.Message;

            }
        }
Exemplo n.º 2
0
        private void Create_Click(object sender, EventArgs e)
        {
            DescStatusLabel.Text = "";
            ErdStatusLabel.Text = "";
            SqlStatusLabel.Text = "";
            List<TaskControl> task = new List<TaskControl>();
            TaskControl t = new TaskControl();
            DB db = new DB();
            try
            {
                if (String.IsNullOrWhiteSpace(descriptionBox.Text))
                {
                    DescStatusLabel.ForeColor = Color.Red;
                    DescStatusLabel.Text = "Description field is empty!";
                }
                else
                {
                    if (String.IsNullOrWhiteSpace(fileStatus.Text))
                    {
                        ErdStatusLabel.ForeColor = Color.Red;
                        ErdStatusLabel.Text = "ERD must be added!";
                    }
                    else
                    {
                        if (String.IsNullOrWhiteSpace(corrSqlBox.Text))
                        {
                            SqlStatusLabel.ForeColor = Color.Red;
                            SqlStatusLabel.Text = "SQL request field is empty!";
                        }
                        else
                        {
                            using (StreamReader sr = new StreamReader(ConfigurationManager.ConnectionStrings["DefaultTask"].ConnectionString))
                            {
                                String line = sr.ReadToEnd();
                                var listTC = JsonConvert.DeserializeObject<List<TaskControl>>(line);
                                foreach (var item in listTC)
                                {
                                    task.Add(item);
                                }

                            }

                            HashSum hash = new HashSum(db.Read(corrSqlBox.Text));
                            t.description = descriptionBox.Text;
                            t.imgPath = fileStatus.Text;
                            t.correctSQL = hash.GetHashString();

                            task.Add(t);
                            string jstr = JsonConvert.SerializeObject(task, Formatting.Indented);
                            System.IO.File.WriteAllText(ConfigurationManager.ConnectionStrings["DefaultTask"].ConnectionString, jstr);
                            SqlStatusLabel.ForeColor = Color.Green;
                            SqlStatusLabel.Text = "Success!";
                        }
                    }
                }
            }
            catch (SqlException exept)
            {
                SqlStatusLabel.ForeColor = Color.Red;
                SqlStatusLabel.Text = exept.Message;
            };
        }