コード例 #1
0
 ///<summary>
 ///Inserts items into Product table while checking for duplicates
 ///</summary>
 public static void InsertIntoTable(params ItemDisc[] id)
 {
     if (!CommBase.IsIntialized)
     {
         CommBase.Intialize();
     }
     command.Connection = CommBase.connection;
     ItemDisc[] Items = Receiver.ReadFromProduct("SELECT * FROM Product;");
     foreach (ItemDisc i in id)
     {
         bool FoundDublicate = false;
         foreach (ItemDisc j in Items)
         {
             if (i.name == j.name)
             {
                 FoundDublicate = true;
                 ExecuteNoReturn("UPDATE Product SET quantity = quantity + " + i.Quantity + " WHERE id = " + j.ID + ";");
                 break;
             }
         }
         if (!FoundDublicate)
         {
             command.CommandText = "INSERT INTO Product (name , price , quantity , type) Values('" + i.name + "', " + i.price + ", " + i.Quantity + ", '" + i.Type + "');";
             command.ExecuteNonQuery();
         }
     }
 }
コード例 #2
0
        public static ItemDisc[] GetOrdersOf(string UserName)
        {
            if (!CommBase.IsIntialized)
            {
                CommBase.Intialize();
            }
            command.Connection  = CommBase.connection;
            command.CommandText = "SELECT * FROM Orders WHERE username = '******';";
            reader = command.ExecuteReader();
            List <ItemDisc> IDList = new List <ItemDisc>();

            while (reader.Read())
            {
                ItemDisc i;
                i.ID         = (int)reader["ProductID"];
                i.name       = (string)reader["name"];
                i.price      = (float)reader["price"];
                i.Quantity   = (int)reader["quantity"];
                i.Type       = (string)reader["type"];
                i.delivered  = (bool)reader["delivered"];
                i.manfacture = " ";
                IDList.Add(i);
            }
            reader.Close();
            return(IDList.ToArray());
        }
コード例 #3
0
        ///<summary>
        ///returns products from Product table according to the query specified via the ItemDisc struct
        ///</summary>
        public static ItemDisc[] ReadFromProduct(string Query)
        {
            if (!CommBase.IsIntialized)
            {
                CommBase.Intialize();
            }
            command.Connection  = CommBase.connection;
            command.CommandText = Query;
            reader = command.ExecuteReader();
            List <ItemDisc> IDlist = new List <ItemDisc>();

            while (reader.Read())
            {
                ItemDisc i;
                i.ID         = (int)reader["id"];
                i.name       = (string)reader["name"];
                i.price      = (float)reader["price"];
                i.Quantity   = (int)reader["quantity"];
                i.Type       = (string)reader["type"];
                i.manfacture = " ";
                i.delivered  = false;
                IDlist.Add(i);
            }
            reader.Close();
            return(IDlist.ToArray());
        }
コード例 #4
0
 ///<summary>
 ///Execute a query that doesn't return anything
 ///</summary>
 public static void ExecuteNoReturn(string Query)
 {
     if (!CommBase.IsIntialized)
     {
         CommBase.Intialize();
     }
     command.Connection  = CommBase.connection;
     command.CommandText = Query;
     command.ExecuteNonQuery();
 }
コード例 #5
0
 ///<summary>
 ///registers a user , returns false if username already exists
 ///</summary>
 public static bool CheckUser(User user)
 {
     if (!CommBase.IsIntialized)
     {
         CommBase.Intialize();
     }
     command.Connection = CommBase.connection;
     User[] AllUsers = Receiver.ReadFromAccounts("SELECT * FROM Accounts;");
     foreach (User i in AllUsers)
     {
         if (i.Username == user.Username)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #6
0
        ///<summary>
        ///returns users from Accounts table according to the query specified via User struct
        ///</summary>
        public static User[] ReadFromAccounts(string Query)
        {
            if (!CommBase.IsIntialized)
            {
                CommBase.Intialize();
            }
            command.Connection  = CommBase.connection;
            command.CommandText = Query;
            reader = command.ExecuteReader();
            List <User> Userlist = new List <User>();

            while (reader.Read())
            {
                User i;
                i.ID       = (int)reader["id"];
                i.Username = (string)reader["username"];
                i.Password = (string)reader["password"];
                i.process  = new Marketing();
                Userlist.Add(i);
            }
            reader.Close();
            return(Userlist.ToArray());
        }