تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
MVP C# و الصور
#1
السلام عليكم ورحمة الله وبركاته 

ماهي طريقة التعامل مع الصور في mvp design pattern : 

حاولت البحث ولم أجد طريقة مثلا أنا لدي كلاس يوجد به : 


كود :
       public static void ImgToByteArray(Image PicBox)
       {
           using (MemoryStream mStream = new MemoryStream())
           {
               PicBox.Save(mStream, PicBox.RawFormat);
               byte[] byteimage = mStream.ToArray();
           }
       }

ويوجد لدي كلا آخر في طبقة  Services : 


كود :
       private static void CumstomerParamerterInsert(int CustomerID, string CustomerName, string CustomerEmail, string CustomerPhone, bool CustomerStatus, byte CustomerPhoto, SqlCommand command)
       {
           command.Parameters.Add("@CustomerID", SqlDbType.Int).Value = CustomerID;
           command.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 150).Value = CustomerName;
           command.Parameters.Add("@CustomerEmail", SqlDbType.NVarChar, 50).Value = CustomerEmail;
           command.Parameters.Add("@CustomerPhone", SqlDbType.NVarChar, 10).Value = CustomerPhone;
           command.Parameters.Add("@CustomerStatus", SqlDbType.Bit).Value = CustomerStatus;
           command.Parameters.Add("@CustomerPhoto", SqlDbType.Image).Value = CustomerPhoto;
       }

       //This Method For Insert Customer To Database
       static public bool InsertCustomer(int CustomerID, string CustomerName, string CustomerEmail, string CustomerPhone, bool CustomerStatus, byte CustomerPhoto)
       {
           return DBHelper.ExcuteData("Save_Customer", () => CumstomerParamerterInsert(CustomerID, CustomerName, CustomerEmail, CustomerPhone, CustomerStatus,CustomerPhoto, DBHelper.command));
       }
 
و يوجد طبقة أخرى وهي Presenter : 
كود :
   class OpsPresenter
   {
       IOps iops;
       OpsModel opsModel = new OpsModel();

       public OpsPresenter(IOps view)
       {
           iops = view;
       }

       // Connect Between Model And Interface
       private void ConnectBetweenModelAndInterface()
       {
           opsModel.CustomerID = iops.CustomerID;
           opsModel.CustomerName = iops.CustomerName;
           opsModel.CustomerEmail = iops.CustomerEmail;
           opsModel.CustomerPhone = iops.CustomerPhone;
           opsModel.CustomerStatus = iops.CustomerStatus;
           opsModel.CustomerPhoto = iops.CustomerPhoto;
       }

       public static byte[] ImageToByteArray1(Image imageIn)
       {
           using (var ms = new MemoryStream())
           {
               imageIn.Save(ms, imageIn.RawFormat);
               return ms.ToArray();
           }
       }

       // Insert Customer To Database
       public void CusInsert()
       {
           if (iops.CustomerName == "")
           {
               MessageBox.Show("يرجى كتابة إسم العميل");
               return;
           }
           if (iops.CustomerEmail == "")
           {
               MessageBox.Show("يرجى كتابة إيميل العميل");
               return;
           }
           if (iops.CustomerPhone == "")
           {
               MessageBox.Show("يرجى كتابة هاتف العميل");
               return;
           }
           else
           {
               ConnectBetweenModelAndInterface();
               OpsService.InsertCustomer(opsModel.CustomerID, opsModel.CustomerName, opsModel.CustomerEmail, opsModel.CustomerPhone, opsModel.CustomerStatus, opsModel.CustomerPhoto);
               GetAllCus();
               AutoNumber();
               MessageBox.Show("تمت الإضافة بنجاح");
           }
       }
  
اما عن كلا الموديل فيحتوي على : 
كود :
namespace TestMVP.Models
{
   class OpsModel
   {
       public int CustomerID { get; set; }
       public string CustomerName { get; set; }
       public string CustomerEmail { get; set; }
       public string CustomerPhone { get; set; }
       public bool CustomerStatus { get; set; }
       public byte CustomerPhoto { get; set; }
       
   }
}

و يوجد Interface : 
كود :
namespace TestMVP.Views.Inerfaces
{
   public interface IOps
   {
       int CustomerID { get; set; }
       string CustomerName { get; set; }
       string CustomerEmail { get; set; }
       string CustomerPhone { get; set; }
       bool CustomerStatus { get; set; }
       object DataGridView { get; set; }
       DataGridView DataGridViewRows { get; set; }
       object simpleButton2 { get; set; }
       object simpleButton3 { get; set; }
       object simpleButton4 { get; set; }
       object Cbx { get; set; }
       string CustomerDisplayMember { get; set; }
       string CustomerValueMember { get; set; }
       byte CustomerPhoto { get; set; }
   }
}

أريد التالي : 
حفظ الصور 
التعديل 
جلب الصورة من قاعدة البيانات
الرد }}}
تم الشكر بواسطة:
#2
هل من مساعدة ؟ !!
الرد }}}
تم الشكر بواسطة:
#3
(11-12-20, 04:12 PM)khalid475 كتب : السلام عليكم ورحمة الله وبركاته 

ماهي طريقة التعامل مع الصور في mvp design pattern : 

حاولت البحث ولم أجد طريقة مثلا أنا لدي كلاس يوجد به : 


كود :
       public static void ImgToByteArray(Image PicBox)
       {
           using (MemoryStream mStream = new MemoryStream())
           {
               PicBox.Save(mStream, PicBox.RawFormat);
               byte[] byteimage = mStream.ToArray();
           }
       }

ويوجد لدي كلا آخر في طبقة  Services : 


كود :
       private static void CumstomerParamerterInsert(int CustomerID, string CustomerName, string CustomerEmail, string CustomerPhone, bool CustomerStatus, byte CustomerPhoto, SqlCommand command)
       {
           command.Parameters.Add("@CustomerID", SqlDbType.Int).Value = CustomerID;
           command.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 150).Value = CustomerName;
           command.Parameters.Add("@CustomerEmail", SqlDbType.NVarChar, 50).Value = CustomerEmail;
           command.Parameters.Add("@CustomerPhone", SqlDbType.NVarChar, 10).Value = CustomerPhone;
           command.Parameters.Add("@CustomerStatus", SqlDbType.Bit).Value = CustomerStatus;
           command.Parameters.Add("@CustomerPhoto", SqlDbType.Image).Value = CustomerPhoto;
       }

       //This Method For Insert Customer To Database
       static public bool InsertCustomer(int CustomerID, string CustomerName, string CustomerEmail, string CustomerPhone, bool CustomerStatus, byte CustomerPhoto)
       {
           return DBHelper.ExcuteData("Save_Customer", () => CumstomerParamerterInsert(CustomerID, CustomerName, CustomerEmail, CustomerPhone, CustomerStatus,CustomerPhoto, DBHelper.command));
       }
 
و يوجد طبقة أخرى وهي Presenter : 
كود :
   class OpsPresenter
   {
       IOps iops;
       OpsModel opsModel = new OpsModel();

       public OpsPresenter(IOps view)
       {
           iops = view;
       }

       // Connect Between Model And Interface
       private void ConnectBetweenModelAndInterface()
       {
           opsModel.CustomerID = iops.CustomerID;
           opsModel.CustomerName = iops.CustomerName;
           opsModel.CustomerEmail = iops.CustomerEmail;
           opsModel.CustomerPhone = iops.CustomerPhone;
           opsModel.CustomerStatus = iops.CustomerStatus;
           opsModel.CustomerPhoto = iops.CustomerPhoto;
       }

       public static byte[] ImageToByteArray1(Image imageIn)
       {
           using (var ms = new MemoryStream())
           {
               imageIn.Save(ms, imageIn.RawFormat);
               return ms.ToArray();
           }
       }

       // Insert Customer To Database
       public void CusInsert()
       {
           if (iops.CustomerName == "")
           {
               MessageBox.Show("يرجى كتابة إسم العميل");
               return;
           }
           if (iops.CustomerEmail == "")
           {
               MessageBox.Show("يرجى كتابة إيميل العميل");
               return;
           }
           if (iops.CustomerPhone == "")
           {
               MessageBox.Show("يرجى كتابة هاتف العميل");
               return;
           }
           else
           {
               ConnectBetweenModelAndInterface();
               OpsService.InsertCustomer(opsModel.CustomerID, opsModel.CustomerName, opsModel.CustomerEmail, opsModel.CustomerPhone, opsModel.CustomerStatus, opsModel.CustomerPhoto);
               GetAllCus();
               AutoNumber();
               MessageBox.Show("تمت الإضافة بنجاح");
           }
       }
  
اما عن كلا الموديل فيحتوي على : 
كود :
namespace TestMVP.Models
{
   class OpsModel
   {
       public int CustomerID { get; set; }
       public string CustomerName { get; set; }
       public string CustomerEmail { get; set; }
       public string CustomerPhone { get; set; }
       public bool CustomerStatus { get; set; }
       public byte CustomerPhoto { get; set; }
       
   }
}

و يوجد Interface : 
كود :
namespace TestMVP.Views.Inerfaces
{
   public interface IOps
   {
       int CustomerID { get; set; }
       string CustomerName { get; set; }
       string CustomerEmail { get; set; }
       string CustomerPhone { get; set; }
       bool CustomerStatus { get; set; }
       object DataGridView { get; set; }
       DataGridView DataGridViewRows { get; set; }
       object simpleButton2 { get; set; }
       object simpleButton3 { get; set; }
       object simpleButton4 { get; set; }
       object Cbx { get; set; }
       string CustomerDisplayMember { get; set; }
       string CustomerValueMember { get; set; }
       byte CustomerPhoto { get; set; }
   }
}

أريد التالي : 
حفظ الصور 
التعديل 
جلب الصورة من قاعدة البيانات

انا لا اعرف mvp design pattern

ضع مشروعك لان هناك اكواد ناقصه
مع زيادة في توضيح المطلوب
الرد }}}
تم الشكر بواسطة: ابراهيم ايبو



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم