Пример #1
0
        //static object LockObject = new object();
        public static bool AddInfo(int typeID, InfoClass info, ProductClass product, Dictionary <int, string> keyvalues)
        {
            string     sql = "insert into T_Info (Title, TypeID) values ('" + info.Title + "', " + info.TypeId.ToString() + ")";
            SqlCommand cmd = SqlDAL.Connection.CreateCommand();

            cmd.Transaction = SqlDAL.Connection.BeginTransaction(IsolationLevel.RepeatableRead);
            bool insert = SqlDAL.ExecuteNonQuery(sql, cmd);

            if (insert)
            {
                int             infoID = SqlDAL.GetMaxID("ID", "T_Info");
                List <KeyClass> keys   = GetKeys(infoID, false);
                foreach (KeyClass key in keys)
                {
                    string sql1 = "insert into T_KeyValue (KeyId, Value) values (@KeyId, @Value)";
                    cmd.Parameters.AddWithValue("@KeyId", key.Id);
                    cmd.Parameters.AddWithValue("@Value", keyvalues[key.Id]);
                    SqlDAL.ExecuteNonQuery(sql1, cmd);
                }
                string sql2 = "insert into T_Product (Picture) values (@Picture)";
                cmd.Parameters.AddWithValue("@Picture", GetBytesFromImageList(product.Picture));
                bool insert1 = SqlDAL.ExecuteNonQuery(sql2, cmd);
                if (insert1)
                {
                    SqlDAL.CommitTransaction(cmd);
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public static InfoClass CreateInstance(string Title, int TypeID)
        {
            InfoClass info = new InfoClass();

            info.title  = Title;
            info.typeId = TypeID;
            return(info);
        }
Пример #3
0
        public static InfoClass GetInfo(int id)
        {
            string    sql   = "select * from T_Info where Id=" + id;
            InfoClass info  = new InfoClass();
            DataTable infos = OleDAL.GetRecords(sql);

            if (infos != null && infos.Rows.Count > 0)
            {
                info = new InfoClass((int)infos.Rows[0]["ID"], infos.Rows[0]["Title"].ToString(), (int)infos.Rows[0]["TypeID"], bool.Parse(infos.Rows[0]["Visible"].ToString()), DateTime.Parse(infos.Rows[0]["SysTime"].ToString()));
                return(info);
            }
            return(info);
        }
Пример #4
0
        public static List <InfoClass> GetInfos(string where)
        {
            string sql = "select * from T_Info";

            if (!string.IsNullOrEmpty(where))
            {
                where = where.Trim().ToLower();
                if (where.StartsWith("and "))
                {
                    where = where.Substring(4);
                }
                sql += " where (1=1) and " + where;
            }
            DataTable        infos = OleDAL.GetRecords(sql);
            List <InfoClass> Is    = new List <InfoClass>();

            for (int i = 0; i < infos.Rows.Count; i++)
            {
                InfoClass ic = new InfoClass((int)infos.Rows[i]["ID"], infos.Rows[i]["Title"].ToString(), (int)infos.Rows[i]["TypeID"], bool.Parse(infos.Rows[i]["Visible"].ToString()), DateTime.Parse(infos.Rows[i]["SysTime"].ToString()));
                Is.Add(ic);
            }
            return(Is);
        }