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() + ")";
            OleDbCommand cmd = OleDAL.Connection.CreateCommand();

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

            if (insert)
            {
                int             infoID = OleDAL.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]);
                    OleDAL.ExecuteNonQuery(sql1, cmd);
                }
                string sql2 = "insert into T_Product (Picture) values (@Picture)";
                cmd.Parameters.AddWithValue("@Picture", GetBytesFromImageList(product.Picture));
                bool insert1 = OleDAL.ExecuteNonQuery(sql2, cmd);
                if (insert1)
                {
                    OleDAL.CommitTransaction(cmd);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
 public static bool UpdateProduct(OleDbParameter[] set, string where)
 {
     if (set.Length > 0)
     {
         StringBuilder sb = new StringBuilder();
         foreach (OleDbParameter para in set)
         {
             if (sb.Length == 0)
             {
                 sb.Append(para.ParameterName + "=@" + para.ParameterName);
             }
             else
             {
                 sb.Append("," + para.ParameterName + "=@" + para.ParameterName);
             }
         }
         string sql = "update T_Product set " + sb.ToString();
         if (!string.IsNullOrEmpty(where))
         {
             where = where.Trim().ToLower();
             if (where.StartsWith("and "))
             {
                 where = where.Substring(4);
             }
             sql += " where (1=1) and " + where;
         }
         return(OleDAL.ExecuteNonQuery(sql, set));
     }
     else
     {
         throw new Exception("set参数为空,更新失败!");
     }
 }
Ejemplo n.º 3
0
        public static bool UpdateType(int id, string typeName)
        {
            if (ExistsType(GetParentType(id).Id, typeName))
            {
                return(false);
            }
            string sql = "update T_Type set TypeName='" + typeName + "' where Id=" + id;

            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 4
0
        public static bool AddType(string typeName, string description, int parentID)
        {
            //lock (LockObject)
            //{
            if (ExistsType(parentID, typeName))
            {
                return(false);
            }
            string sql = "insert into T_Type (TypeName, Description, ParentID) values ('" + typeName + "', '" + description + "', " + parentID.ToString() + ")";

            return(OleDAL.ExecuteNonQuery(sql));
            //}
        }
Ejemplo n.º 5
0
        public static bool AddKeyInfo(int typeId, string keyName, string friendName, string unit)
        {
            //lock (LockObject)
            //{
            if (ExistsKey(typeId, keyName))
            {
                return(false);
            }
            string sql = "insert into T_KeyInfo (TypeId, KeyName, FriendName, Unit) values (" + typeId.ToString() + ", '" + keyName + "', '" + friendName + "', '" + unit + "')";

            return(OleDAL.ExecuteNonQuery(sql));
            //}
        }
Ejemplo n.º 6
0
        public static bool DeleteType(string where)
        {
            string sql = "dalete from T_Type";

            if (!string.IsNullOrEmpty(where))
            {
                where = where.Trim().ToLower();
                if (where.StartsWith("and "))
                {
                    where = where.Substring(4);
                }
                sql += " where (1=1) and " + where;
            }
            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 7
0
        public static bool UpdateInfoTitle(string title, string where)
        {
            string sql = "update T_Info set Title='" + title + "'";

            if (!string.IsNullOrEmpty(where))
            {
                where = where.Trim().ToLower();
                if (where.StartsWith("and "))
                {
                    where = where.Substring(4);
                }
                sql += " where (1=1) and " + where;
            }
            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 8
0
        public static bool UpdateInfoType(int typeId, string where)
        {
            string sql = "update T_Info set TypeId=" + typeId.ToString();

            if (!string.IsNullOrEmpty(where))
            {
                where = where.Trim().ToLower();
                if (where.StartsWith("and "))
                {
                    where = where.Substring(4);
                }
                sql += " where (1=1) and " + where;
            }
            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 9
0
        public static bool UpdateInfoVisible(bool visible, string where)
        {
            string sql = "update T_Info set Visible=" + (visible ? "1" : "0");

            if (!string.IsNullOrEmpty(where))
            {
                where = where.Trim().ToLower();
                if (where.StartsWith("and "))
                {
                    where = where.Substring(4);
                }
                sql += " where (1=1) and " + where;
            }
            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 10
0
        public static bool CopyKeyInfoTo(int id, int typeId)
        {
            KeyClass key = GetKey(id);

            if (key.TypeId != typeId)
            {
                if (ExistsKey(typeId, key.KeyName))
                {
                    return(false);
                }
                string sql = "insert into T_KeyInfo (TypeId, KeyName, FriendName, Unit) values (" + typeId + ", '" + key.KeyName + "', '" + key.FriendName + "', '" + key.Unit + "')";
                return(OleDAL.ExecuteNonQuery(sql));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
 public static bool UpdateKeyValue(string set, string where)
 {
     if (!string.IsNullOrEmpty(set))
     {
         string sql = "update T_KeyValue set " + set;
         if (!string.IsNullOrEmpty(where))
         {
             where = where.Trim().ToLower();
             if (where.StartsWith("and "))
             {
                 where = where.Substring(4);
             }
             sql += " where (1=1) and " + where;
         }
         return(OleDAL.ExecuteNonQuery(sql));
     }
     else
     {
         throw new Exception("set参数为空,更新失败!");
     }
 }
Ejemplo n.º 12
0
        public static bool DeleteKeyInfo(int id)
        {
            string sql = "delete from T_KeyInfo where ID=" + id;

            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 13
0
        public static bool MoveKeyInfoTo(int id, int typeId)
        {
            string sql = "update T_KeyInfo set TypeId=" + typeId + " where ID=" + id;

            return(OleDAL.ExecuteNonQuery(sql));
        }
Ejemplo n.º 14
0
        public static bool UpdateKeyInfo(int id, string friendName, string unit)
        {
            string sql = "update T_KeyInfo set FriendName='" + friendName + "', Unit='" + unit + "' where ID=" + id;

            return(OleDAL.ExecuteNonQuery(sql));
        }