public UnitOfWork()
 {
     BearingResult = new BearingResultRepos();
     Machine       = new MachineRepos();
     FL            = new FLRepos();
     EngineResult  = new EngineResultRepos();
     Repairs       = new RepairsRepos();
     ShaftResult   = new ShaftResultRepos();
     StateClass    = new StateClassRepos();
 }
Beispiel #2
0
        public bool Add(Machine value, List <StateClass> ShaftClasses, List <StateClass> BearingClasses)
        {
            StateClassRepos stateClassRepos = new StateClassRepos();
            string          sql             = "start transaction;" +
                                              "insert into `machine` (`marking`,`number`,`speed`,`power`,`countpairs`,`head`) values (" +
                                              "\'" + value.Marking + "\'," + "\'" + value.Number + "\'," + value.Speed + ","
                                              + value.Power + "," + value.CountPairs + "," + value.Head + ");";

            StateClassController.AddShaft(ShaftClasses, ref sql);
            StateClassController.AddBearing(BearingClasses, ref sql);
            //stateClassRepos.AddShaftClasses(ShaftClasses, ref sql);
            //stateClassRepos.AddBearingClasses(BearingClasses, ref sql);
            sql += "commit;";
            string       sqlrb = "rollback;";
            MySqlCommand cmd   = new MySqlCommand();
            MySqlCommand cmdrb = new MySqlCommand();

            using (MySqlConnection conn = DBUtils.GetDBConnection())
            {
                try
                {
                    conn.Open();
                    cmd.Connection  = conn;
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Машина успешно добавлена!");
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    cmd.CommandText = sqlrb;
                    cmd.ExecuteNonQuery();
                    return(false);
                }
            }
        }