Esempio n. 1
0
        public Int32 Create(AVersion entity)
        {
            Int32  id;
            String insertVersion = "sp_InsertVersion";

            using (SqlConnection conn = CDbConnection.GetConnection())
            {
                conn.Open();

                SqlCommand command = new SqlCommand(insertVersion, conn);
                command.CommandType = System.Data.CommandType.StoredProcedure;
                SqlParameter major = new SqlParameter
                {
                    ParameterName = "@major",
                    Value         = entity.Major
                };
                command.Parameters.Add(major);
                SqlParameter minor = new SqlParameter
                {
                    ParameterName = "@minor",
                    Value         = entity.Minor
                };
                command.Parameters.Add(minor);
                SqlParameter filenumber = new SqlParameter
                {
                    ParameterName = "@filenumber",
                    Value         = entity.FileNumber
                };
                command.Parameters.Add(filenumber);
                SqlParameter comment = new SqlParameter
                {
                    ParameterName = "@comment",
                    Value         = entity.Comment
                };
                command.Parameters.Add(comment);
                SqlParameter date = new SqlParameter
                {
                    ParameterName = "@date",
                    Value         = DateTime.Now
                };
                command.Parameters.Add(date);

                try
                {
                    var result = command.ExecuteScalar();
                    Console.WriteLine("Id добавленного объекта: {0}", result);
                    var value = result.ToString();
                    Int32.TryParse(value, out id);
                    return(id);
                }
                catch (Exception e)
                {
                    SLogger.Log.Fatal($"CMigrationGateway.Create method. Exception: {e.Message}");
                    return(-1);
                }
            }
        }
Esempio n. 2
0
        internal override void GetVersion()
        {
            CDbConnection.IsLocalDb  = true;
            CDbConnection.IsCreating = true;
            using (SqlConnection conn = CDbConnection.GetConnection())
            {
                var dbCreate                 = s_scripts.DbCreate;
                var dbUse                    = s_scripts.DbUse;
                var tablesCreate             = s_scripts.TablesCreate.GetAll();
                var StoredProceduresCreate   = s_scripts.StoredProceduresCreate.GetArticles;
                var StoredProceduresCreate2  = s_scripts.StoredProceduresCreate.GetArticleTagRelations;
                var StoredProceduresCreate3  = s_scripts.StoredProceduresCreate.GetCountryById;
                var StoredProceduresCreate4  = s_scripts.StoredProceduresCreate.GetTagByName;
                var StoredProceduresCreate5  = s_scripts.StoredProceduresCreate.GetTags;
                var StoredProceduresCreate6  = s_scripts.StoredProceduresCreate.InsertArticle;
                var StoredProceduresCreate7  = s_scripts.StoredProceduresCreate.InsertArticleTag;
                var StoredProceduresCreate8  = s_scripts.StoredProceduresCreate.InsertTag;
                var StoredProceduresCreate9  = s_scripts.StoredProceduresCreate.InsertCountry;
                var StoredProceduresCreate10 = s_scripts.StoredProceduresCreate.InsertVersion;
                var StoredProceduresCreate11 = s_scripts.StoredProceduresCreate.GetAllCountries;


                SqlCommand cmd  = new SqlCommand(dbCreate, conn);
                SqlCommand cmd2 = new SqlCommand(dbUse, conn);
                SqlCommand cmd3 = new SqlCommand(tablesCreate, conn);
                SqlCommand
                    cmd4 = new SqlCommand(StoredProceduresCreate,
                                          conn); //:todo resolve the problem with sql query with creating all procedures in one (like with tables)
                SqlCommand cmd5  = new SqlCommand(StoredProceduresCreate2, conn);
                SqlCommand cmd6  = new SqlCommand(StoredProceduresCreate3, conn);
                SqlCommand cmd7  = new SqlCommand(StoredProceduresCreate4, conn);
                SqlCommand cmd8  = new SqlCommand(StoredProceduresCreate5, conn);
                SqlCommand cmd9  = new SqlCommand(StoredProceduresCreate6, conn);
                SqlCommand cmd10 = new SqlCommand(StoredProceduresCreate7, conn);
                SqlCommand cmd11 = new SqlCommand(StoredProceduresCreate8, conn);
                SqlCommand cmd12 = new SqlCommand(StoredProceduresCreate9, conn);
                SqlCommand cmd13 = new SqlCommand(StoredProceduresCreate10, conn);
                SqlCommand cmd14 = new SqlCommand(StoredProceduresCreate11, conn);
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    cmd2.ExecuteNonQuery();
                    cmd3.ExecuteNonQuery();
                    cmd4.ExecuteNonQuery();
                    cmd5.ExecuteNonQuery();
                    cmd6.ExecuteNonQuery();
                    cmd7.ExecuteNonQuery();
                    cmd8.ExecuteNonQuery();
                    cmd9.ExecuteNonQuery();
                    cmd10.ExecuteNonQuery();
                    cmd11.ExecuteNonQuery();
                    cmd12.ExecuteNonQuery();
                    cmd13.ExecuteNonQuery();
                    cmd14.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    SLogger.Log.Fatal("Unexpected termination: " + e.Message);
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    CDbConnection.IsCreating = false;
                }
                InsertDefaultValues();
            }
        }