Example #1
0
        public static int AddStage(Stage stage)
        {
            // If _Stage is null, create the Observable Collection
            if (_stages == null) GetStages();

            try
            {
                // Add to db
                DbParameter param = Database.AddParameter("@name", stage.Name);
                DbDataReader reader = Database.GetData("INSERT INTO stage(name) VALUES(@name); SELECT LAST_INSERT_ID() AS ID;", param);
                foreach (DbDataRecord record in reader)
                {
                    // Get ID
                    if (DBNull.Value.Equals(record["ID"])) stage.ID = -1;
                    else stage.ID = Convert.ToInt32(record["ID"]);
                }
                if (reader != null)
                    reader.Close();

                _stages.Add(stage);
                return stage.ID;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return -1;
        }
Example #2
0
        public StageVM()
        {
            Stages = Stage.GetStages();

            SelectedStage = new Stage();
            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
Example #3
0
        public static void UpdateStage(Stage stage)
        {
            // If _Stage is null, create the Observable Collection
            if (_stages == null) GetStages();

            try
            {
                // Update db
                DbParameter param1 = Database.AddParameter("@id", stage.ID);
                DbParameter param2 = Database.AddParameter("@name", stage.Name);
                int affectedRows = Database.ModifyData("UPDATE stage SET name = @name WHERE id = @id", param1, param2);
                if (affectedRows == 0) return;

                // Update _stages
                _stages[GetIndexByID(stage.ID)] = stage;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #4
0
        public static ObservableCollection<Stage> GetStages()
        {
            // If _stages is null, create the Observable Collection
            if (_stages == null)
            {
                try
                {
                    // Create _stages
                    _stages = new ObservableCollection<Stage>();

                    // Get data
                    DbDataReader reader = Database.GetData("SELECT * FROM stage");
                    foreach (DbDataRecord record in reader)
                    {
                        // Create new Stage
                        Stage stage = new Stage();

                        // Get ID
                        if (DBNull.Value.Equals(record["ID"])) stage.ID = -1;
                        else stage.ID = Convert.ToInt32(record["ID"]);

                        // Get Name
                        if (DBNull.Value.Equals(record["Name"])) stage.Name = "";
                        else stage.Name = record["Name"].ToString();

                        // Add Stage
                        _stages.Add(stage);
                    }
                    if (reader != null)
                        reader.Close();
                }

                // Fail
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);

                    // Clear Stages
                    _stages.Clear();
                    _stages = null;
                }

            }

            // Return _stages
            return _stages;
        }
Example #5
0
        public static void DeleteStage(Stage stage)
        {
            // If _Stage is null, create the Observable Collection
            if (_stages == null) GetStages();

            try
            {
                // Add to db
                DbParameter param = Database.AddParameter("@id", stage.ID);
                int affectedRows = Database.ModifyData("DELETE FROM stage WHERE id = @id", param);
                if (affectedRows == 0) return;

                // Update _stages
                _stages.RemoveAt(GetIndexByID(stage.ID));
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #6
0
        private void SelectionChanged(StageVM stagevm)
        {
            if (SelectedStage == null) return;
            if (ShowCancel == "Visible") CancelUpdateStage(this);
            _oldType = SelectedStage.Copy();

            stagevm.ShowEdit = "Visible";
            stagevm.ShowCancel = "Hidden";
            stagevm.ShowSave = "Hidden";
            Enabled = false;
        }
Example #7
0
        private void DeleteStage(StageVM stagevm)
        {
            if (SelectedStage == null) return;

            Stage.DeleteStage(SelectedStage);

            SelectedStage = new Stage();
            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
Example #8
0
 private void AddStage(StageVM stagevm)
 {
     SelectedStage = new Stage();
     _oldType = null;
     stagevm.ShowEdit = "Hidden";
     stagevm.ShowCancel = "Visible";
     stagevm.ShowSave = "Visible";
     stagevm.Enabled = true;
 }