Example #1
0
        public static Chart NewChart(ChartTemplate chartTemplate)
        {
            int resId = 0;
            string query = "BEGIN TRANSACTION NEWCHART;";
            query += "DECLARE @insertId AS int;";
            query += "INSERT INTO Chart (Name) VALUES ('"+chartTemplate.Name+"');";
            query += "SET @insertId = SCOPE_IDENTITY();";
            query += "INSERT INTO ChartProfile (ChartID,ProfileID) VALUES (@insertId," + chartTemplate.Profile.ProfileID + ");";
            foreach (User u in chartTemplate.Users)
                query += "INSERT INTO ChartUser (ChartID,UserID) VALUES (@insertId," + u.UserID + ");";
            query += "COMMIT TRANSACTION NEWCHART;";
            query += "SELECT @insertId;";

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    resId = Convert.ToInt32(reader[0]);
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                string errmsg = "Fehler beim Erstellen der Auswertung.\n\n";
                errmsg += "DatabaseHandler.NewChart(chartTemplate): " + ex.ToString();
                throw new Exception(errmsg);
            }

            return GetChart(resId);
        }
Example #2
0
 public Chart Create(ChartTemplate chartTemplate)
 {
     return DatabaseHandler.NewChart(chartTemplate);
 }