Exemple #1
0
 public bool UpdateImage(Image img)
 {
     try
     {
         return(Network.SendImage(DataClient.Email, DataClient.Token, ConvertImage.ImageToByteArray(img)));
     }
     catch (Exception)
     {
         return(false);
     }
 }
        private void btnAddFood_Click(object sender, EventArgs e)
        {
            Food food = new Food();

            food.Name = tbFoodName.Text;
            float price;

            if (float.TryParse(tbFoodPrice.Text, out price))
            {
                food.Price = price;
            }
            ;
            food.FoodCategoryId = (cbbFoodCate.SelectedItem as dynamic).Value;
            food.Content        = ConvertImage.ImageToByteArray(pbFoodImage.Image);
            using (var DbContext = new AppContext())
            {
                DbContext.Foods.Add(food);
                DbContext.SaveChanges();
            }
            LoadFood();
            ResetFoodData();
        }
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (pbS.Image != null)
     {
         (salesmanDetailsBindingSource.Current as Salesman_Details).Image          = ci.ImageToByteArray(pbS.Image);
         cmd.Entry(salesmanDetailsBindingSource.Current as Salesman_Details).State = EntityState.Modified;
         cmd.SaveChanges();
         //btnNew.PerformClick();
         this.Visible = false;
     }
     else
     {
         MessageBox.Show("Please Enter a Picture");
     }
 }
Exemple #4
0
 public static Protocol GetImage(Protocol prot, DataTcpClient client)
 {
     try
     {
         if (prot.Token == "")
         {
             return(new Protocol(MessageType.Error)
             {
                 Message = "Empty token"
             });
         }
         int              ID          = GetIdbyToken(prot.Token);
         string           query_token = "SELECT COUNT(*) FROM gamesess WHERE ID_user = @ID AND token = @token";
         MySqlParameter[] parameters  = new MySqlParameter[2];
         parameters[0] = new MySqlParameter("@ID", ID);
         parameters[1] = new MySqlParameter("@token", DBManager.Escape(prot.Token));
         if (DataServer.Database.Count(query_token, parameters) == 1)
         {
             string           query_user       = "******";
             string           query_user_count = "SELECT COUNT(*) FROM user WHERE email = @mail";
             MySqlParameter[] parameters_user  = new MySqlParameter[1];
             parameters_user[0] = new MySqlParameter("@mail", prot.Email);
             if (DataServer.Database.Count(query_user_count, parameters_user) == 1)
             {
                 Dictionary <string, string> result =
                     DataServer.Database.Select(query_user, parameters_user)[0];
                 int    idavatar = int.Parse(result["avatar_path"]);
                 byte[] img      = null;
                 try
                 {
                     string           query_img      = "SELECT * FROM image WHERE ID = @id";
                     MySqlParameter[] parameters_img = new MySqlParameter[1];
                     parameters_img[0] = new MySqlParameter("@id", idavatar);
                     Dictionary <string, string> result_img =
                         DataServer.Database.Select(query_img, parameters_img)[0];
                     string path = result_img["path"];
                     img = ConvertImage.ImageToByteArray(ConvertImage.FromFile(path));
                 }
                 catch (Exception)
                 {
                     return(new Protocol(MessageType.Error)
                     {
                         Message = "invalid request"
                     });
                 }
                 return(new Protocol(MessageType.Response)
                 {
                     Email = result["email"],
                     ImageBytes = img
                 });
             }
             return(new Protocol(MessageType.Error)
             {
                 Message = "Bad request"
             });
         }
         else
         {
             return(new Protocol(MessageType.Error)
             {
                 Message = "Bad token"
             });
         }
     }
     catch (Exception)
     {
         return(new Protocol(MessageType.Error)
         {
             Message = "Error"
         });
     }
 }
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (pbP.Image != null)
     {
         int stock = (productDetailsBindingSource.Current as Product_Details).Stock;
         try
         {
             stock = stock + int.Parse(txtPPurchaseU.Text);
             (productDetailsBindingSource.Current as Product_Details).Stock = stock;
         }
         catch (Exception)
         {
             MessageBox.Show("Please Enter valid input");
             txtPPurchaseU.Focus();
         }
         (productDetailsBindingSource.Current as Product_Details).Image          = ci.ImageToByteArray(pbP.Image);
         cmd.Entry(productDetailsBindingSource.Current as Product_Details).State = EntityState.Modified;
         cmd.SaveChanges();
         //btnNew.PerformClick();
         this.Visible = false;
     }
     else
     {
         MessageBox.Show("Please Enter a Picture");
     }
 }