예제 #1
0
        private static List <AreaItem> Get(SqlCommand SqlCommand)
        {
            List <AreaItem> AreaItems = new List <AreaItem>();

            using (SqlConnection SqlConnection = ConnectionManager.GetConnection())
            {
                using (SqlCommand.Connection = SqlConnection)
                {
                    SqlConnection.Open();

                    SqlDataReader SqlDataReader = SqlCommand.ExecuteReader();

                    while (SqlDataReader.Read())
                    {
                        string   Id         = (string)SqlDataReader["Id"];
                        string   Name       = (string)SqlDataReader["Name"];
                        int      Sort       = (int)SqlDataReader["Sort"];
                        DateTime UpdateTime = (DateTime)SqlDataReader["UpdateTime"];
                        DateTime CreateTime = (DateTime)SqlDataReader["CreateTime"];

                        AreaItem AreaItem = new AreaItem(Id, Name, Sort, UpdateTime, CreateTime);
                        AreaItems.Add(AreaItem);
                    }
                }
            }

            return(AreaItems);
        }
예제 #2
0
        public static void Remove(AreaItem AreaItem)
        {
            //更新資料庫
            AreaItemAccessor.Delete(AreaItem);

            //更新記憶体
            _AreaItemCache.Remove(AreaItem);
        }
예제 #3
0
        internal static void Delete(AreaItem AreaItem)
        {
            using (SqlConnection SqlConnection = ConnectionManager.GetConnection())
            {
                using (SqlCommand SqlCommand = SqlConnection.CreateCommand())
                {
                    SqlCommand.CommandText = "Delete "
                                             + " School_AreaItem "
                                             + "WHERE "
                                             + " Id = @Id ";

                    SqlCommand.Parameters.AddWithValue("Id", AreaItem.Id);

                    SqlConnection.Open();
                    SqlCommand.ExecuteNonQuery();
                }
            }
        }
예제 #4
0
        public static void Save(AreaItem AreaItem)
        {
            if (AreaItem.Id == "-1")
            {
                AreaItem.Id = Guid.NewGuid().ToString();
            }

            AreaItem.UpdateTime = DateTime.Now;

            lock (SaveObject)
            {
                //更新資料庫
                AreaItemAccessor.UpdateInsert(AreaItem);

                //記憶體重新初始化
                Initial();
            }
        }
예제 #5
0
        internal static void UpdateInsert(AreaItem AreaItem)
        {
            using (SqlConnection SqlConnection = ConnectionManager.GetConnection())
            {
                using (SqlCommand SqlCommand = SqlConnection.CreateCommand())
                {
                    SqlCommand.CommandText = "UPDATE "
                                             + " School_AreaItem "
                                             + "SET "
                                             + " Name = @Name "
                                             + " ,Sort = @Sort "
                                             + " ,UpdateTime = @UpdateTime "
                                             + " ,CreateTime = @CreateTime "
                                             + "WHERE "
                                             + " Id = @Id "

                                             + "IF @@ROWCOUNT = 0 "
                                             + "BEGIN "

                                             + "INSERT INTO "
                                             + " School_AreaItem "
                                             + "( Id, Name, Sort, UpdateTime, CreateTime  ) "
                                             + "VALUES "
                                             + "( @Id, @Name, @Sort, @UpdateTime, @CreateTime ) "

                                             + "END ";

                    SqlCommand.Parameters.AddWithValue("Id", AreaItem.Id);
                    SqlCommand.Parameters.AddWithValue("Name", AreaItem.Name);
                    SqlCommand.Parameters.AddWithValue("Sort", AreaItem.Sort);
                    SqlCommand.Parameters.AddWithValue("UpdateTime", AreaItem.UpdateTime);
                    SqlCommand.Parameters.AddWithValue("CreateTime", AreaItem.CreateTime);

                    SqlConnection.Open();
                    SqlCommand.ExecuteNonQuery();
                }
            }
        }