public IEnumerable <ILatchModel> GetAll()
        {
            List <LatchModel> latchModelList = new List <LatchModel>();

            using (MySqlConnection connection = new MySqlConnection(_connString))
            {
                try
                {
                    string queryString = "SELECT * FROM sql_latch_tests1.latches";
                    connection.Open();
                    using (MySqlCommand command = new MySqlCommand(queryString, connection))
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                LatchModel model = new LatchModel();
                                model.ComponentID = Int32.Parse(reader["component_id"].ToString());
                                model.LatchID     = Int32.Parse(reader["latch_id"].ToString());
                                model.Type        = reader["type"].ToString();
                                latchModelList.Add(model);
                            }
                        }
                }
                catch (MySqlException ex)
                {
                    throw new Exception(ex.Message.ToString(), ex);
                }
                finally { connection.Close(); }

                return(latchModelList);
            }
        }
Exemplo n.º 2
0
        // Introducing changes to db data
        private void BtnSubmitChanges_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells[0].Value == null)
                    {
                        return;
                    }

                    switch (currentView)
                    {
                    case View.Component:
                        CompModel componentModel = new CompModel();
                        componentModel.ComponentID = Convert.ToInt32(row.Cells[0].Value);
                        componentModel.Type        = row.Cells[1].Value.ToString();
                        componentModel.Status      = Convert.ToBoolean(row.Cells[2].Value);
                        componentRepository.Update(componentModel);
                        break;

                    case View.Latch:
                        LatchModel latchModel = new LatchModel();
                        latchModel.LatchID     = Convert.ToInt32(row.Cells[0].Value);
                        latchModel.Type        = row.Cells[1].Value.ToString();
                        latchModel.ComponentID = Convert.ToInt32(row.Cells[2].Value);
                        latchRepository.Update(latchModel);
                        break;

                    case View.Test:
                        TestModel testModel = new TestModel();
                        testModel.TestID    = Convert.ToInt32(row.Cells[0].Value);
                        testModel.LatchID   = Convert.ToInt32(row.Cells[1].Value);
                        testModel.EndTime   = Convert.ToDateTime(row.Cells[2].Value);
                        testModel.Date      = Convert.ToDateTime(row.Cells[3].Value);
                        testModel.Status    = Convert.ToBoolean(row.Cells[4].Value);
                        testModel.Cycles    = Convert.ToInt32(row.Cells[5].Value);
                        testModel.VideoLink = row.Cells[6].Value.ToString().Replace("\\", "\\\\");
                        testModel.Comments  = row.Cells[7].Value.ToString();
                        testRepository.Update(testModel);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            ViewDataFromTable(currentView);   // Refresh the data grid view
        }