コード例 #1
0
ファイル: ManageData.cs プロジェクト: meysamrazmi/desk
        public static MyProduct myProducts(UserLogin userLogin)
        {
            MyProduct myProducts = null;

            try
            {
                if (!string.IsNullOrEmpty(userLogin.sessid))
                {
                    myProducts = Classes.WebService.myProducts(userLogin);
                    db.insertMyProduct(myProducts);
                }
                myProducts = db.getMyProduct();
            }
            catch (Exception)
            {
                myProducts = db.getMyProduct();
                isOffLine  = true;
            }

            return(myProducts);
        }
コード例 #2
0
        public bool insertMyProduct(MyProduct myProducts)
        {
            try
            {
                deleteMyProduct();
                int index = 1;
                foreach (var product in myProducts.product)
                {
                    string local_picture = null;
                    if (!string.IsNullOrEmpty(product.picture))
                    {
                        local_picture = Helper.saveImage(product.picture);
                    }

                    var sql = "INSERT INTO Product (id,nid, title,author,picture,local_picture,order_time,price,type) " +
                              "values ('" + index + "','" + product.nid + "','" + product.title + "','" + product.author + "','" + product.picture + "','" + local_picture + "','" + product.order_time + "'," + product.price + ",'product')";
                    SQLiteCommand commandp = new SQLiteCommand(sql, m_dbConnection);
                    commandp.ExecuteNonQuery();
                    commandp.Dispose();

                    var pid = index;
                    sql = string.Empty;
                    foreach (var file in product.files)
                    {
                        var key      = Helper.RandomString();
                        var password = Helper.Encrypt(file.password, key);
                        sql += "INSERT INTO File (pid, url,filesize,title,name,new_name,password,password_key) " +
                               "values ('" + pid + "','" + file.url + "','" + file.filesize + "','" + file.title + "','" + file.name + "','" + file.new_name + ".bin','" + password + "','" + key + "');";
                    }
                    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                    command.Dispose();
                    index++;
                }

                foreach (var product in myProducts.college)
                {
                    string local_picture = null;
                    if (!string.IsNullOrEmpty(product.picture))
                    {
                        local_picture = Helper.saveImage(product.picture);
                    }

                    var sql = "INSERT INTO Product (id,nid, title,author,picture,local_picture,order_time,price,type) " +
                              "values ('" + index + "','" + product.nid + "','" + product.title + "','" + product.author + "','" + product.picture + "','" + local_picture + "','" + product.order_time + "'," + product.price + ",'college')";
                    SQLiteCommand commandp = new SQLiteCommand(sql, m_dbConnection);
                    commandp.Dispose();

                    var pid = index;
                    sql = string.Empty;
                    foreach (var file in product.files)
                    {
                        var key      = Helper.RandomString();
                        var password = Helper.Encrypt(file.password, key);
                        sql += "INSERT INTO File (pid, url,filesize,title,name,new_name,password,password_key) " +
                               "values ('" + pid + "','" + file.url + "','" + file.filesize + "','" + file.title + "','" + file.name + "','" + file.new_name + ".bin','" + password + "','" + key + "');";
                    }
                    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                    command.Dispose();
                    index++;
                }

                foreach (var product in myProducts.product_kit)
                {
                    string local_picture = null;
                    if (!string.IsNullOrEmpty(product.picture))
                    {
                        local_picture = Helper.saveImage(product.picture);
                    }

                    var sql = "INSERT INTO Product (id,nid, title,author,picture,local_picture,order_time,price,type) " +
                              "values ('" + index + "','" + product.nid + "','" + product.title + "','" + product.author + "','" + product.picture + "','" + local_picture + "','" + product.order_time + "'," + product.price + ",'product_kit')";
                    SQLiteCommand commandp = new SQLiteCommand(sql, m_dbConnection);
                    commandp.Dispose();

                    var pid = index;
                    sql = string.Empty;
                    foreach (var file in product.files)
                    {
                        var key      = Helper.RandomString();
                        var password = Helper.Encrypt(file.password, key);
                        sql += "INSERT INTO File (pid, url,filesize,title,name,new_name,password,password_key) " +
                               "values ('" + pid + "','" + file.url + "','" + file.filesize + "','" + file.title + "','" + file.name + "','" + file.new_name + ".bin','" + password + "','" + key + "');";
                    }
                    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                    command.Dispose();
                    index++;
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #3
0
        public MyProduct getMyProduct()
        {
            MyProduct myProductObj = null;

            try
            {
                DataTable     myProduct = new DataTable();
                var           sql       = "SELECT * FROM Product";
                SQLiteCommand command   = new SQLiteCommand(sql, m_dbConnection);
                myProduct.Load(command.ExecuteReader());
                command.Dispose();
                myProductObj = new MyProduct();

                for (int i = 0; i < myProduct.Rows.Count; i++)
                {
                    var productObj = new Product();
                    var type       = myProduct.Rows[i]["type"].ToString();

                    #region load Files

                    DataTable files = new DataTable();
                    var       id    = myProduct.Rows[i]["id"].ToString();
                    sql     = "SELECT * FROM File WHERE pid = " + id;
                    command = new SQLiteCommand(sql, m_dbConnection);
                    files.Load(command.ExecuteReader());

                    #endregion

                    productObj.author        = myProduct.Rows[i]["author"].ToString();
                    productObj.nid           = int.Parse(myProduct.Rows[i]["nid"].ToString());
                    productObj.order_time    = int.Parse(myProduct.Rows[i]["order_time"].ToString());
                    productObj.picture       = myProduct.Rows[i]["picture"].ToString();
                    productObj.local_picture = myProduct.Rows[i]["local_picture"].ToString();
                    productObj.price         = int.Parse(myProduct.Rows[i]["price"].ToString());
                    productObj.title         = myProduct.Rows[i]["title"].ToString();
                    productObj.files         = new List <File>();
                    for (int j = 0; j < files.Rows.Count; j++)
                    {
                        var fileObj = new File();
                        fileObj.title    = files.Rows[j]["title"].ToString();
                        fileObj.url      = files.Rows[j]["url"].ToString();
                        fileObj.filesize = int.Parse(files.Rows[j]["filesize"].ToString());
                        fileObj.name     = files.Rows[j]["name"].ToString();
                        fileObj.new_name = files.Rows[j]["new_name"].ToString();
                        var key      = files.Rows[j]["password_key"].ToString();
                        var password = files.Rows[j]["password"].ToString();
                        fileObj.password = Helper.Decrypt(password, key);
                        productObj.files.Add(fileObj);
                    }

                    if (type == "product_kit")
                    {
                        if (myProductObj.product_kit == null)
                        {
                            myProductObj.product_kit = new List <Product>();
                        }
                        myProductObj.product_kit.Add(productObj);
                    }
                    else if (type == "product")
                    {
                        if (myProductObj.product == null)
                        {
                            myProductObj.product = new List <Product>();
                        }
                        myProductObj.product.Add(productObj);
                    }
                    else
                    {
                        if (myProductObj.college == null)
                        {
                            myProductObj.college = new List <Product>();
                        }
                        myProductObj.college.Add(productObj);
                    }
                }
                return(myProductObj);
            }
            catch (Exception e)
            {
                return(myProductObj);
            }
        }