Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static ProductClass CreateInstance(string Title, int InfoID, string TypeLink, Dictionary <KeyClass, ValueClass> KeyValues, List <Image> Picture = null)
        {
            ProductClass product = new ProductClass();

            product.title = Title;
            if (Picture != null)
            {
                product.picture = Picture;
            }
            else
            {
                product.picture = new List <Image>();
            }
            product.infoId    = InfoID;
            product.typeLink  = TypeLink;
            product.keyValues = KeyValues;
            return(product);
        }
Ejemplo n.º 3
0
        public static ProductClass GetLastOneProduct()
        {
            ProductClass product = null;
            DataTable    last    = OleDAL.GetRecords("select top 1 * from T_Product order by ID desc");

            if (last != null && last.Rows.Count > 0)
            {
                int          infoID   = (int)last.Rows[0]["InfoID"];
                string       typeLink = GetTypeNameOfInfo(infoID);
                List <Image> images   = new List <Image>();
                try
                {
                    images = GetImageFromDb((byte[])last.Rows[0]["Picture"]);
                }
                catch// (Exception e)
                {
                    typeLink += "(图片有损)";
                    //throw e;
                }
                Dictionary <KeyClass, ValueClass> keyvalues = GetKeyValues(infoID);
                product = new ProductClass((int)last.Rows[0]["ID"], infoID, GetInfo(infoID).Title, typeLink, keyvalues, images);
            }
            return(product);
        }
Ejemplo n.º 4
0
        public static ProductClass GetProduct(int infoID)
        {
            string    sql = "select * from T_Product where InfoID = " + infoID.ToString();
            DataTable pi  = OleDAL.GetRecords(sql);

            if (pi != null && pi.Rows.Count > 0)
            {
                string       typeLink = GetTypeNameOfInfo(infoID);
                List <Image> images   = new List <Image>();
                try
                {
                    images = GetImageFromDb((byte[])pi.Rows[0]["Picture"]);
                }
                catch// (Exception e)
                {
                    typeLink += "(图片有损)";
                    //throw e;
                }
                Dictionary <KeyClass, ValueClass> keyvalues = GetKeyValues(infoID);
                ProductClass product = new ProductClass((int)pi.Rows[0]["ID"], infoID, GetInfo(infoID).Title, typeLink, keyvalues, images);
                return(product);
            }
            return(null);
        }