تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مشكلة في كود
#1
السلام عليكم اخوانى 
بيظهر لي هذا الخطأ 
Operator '>' cannot be applied to operands of type 'void' and 'int'
وهذا هو الكود المستخدم 
كود :
       public void VerifyEntredQuantity(string Product_S_N,int QuantityEntred)
       {
           DataTable dt6 = new DataTable();
           dt6.Clear();
           cmd = new SqlCommand("select * from Products where Product_S_N='" + Product_S_N + "' and Quantity > '" + QuantityEntred + "'", con);
           da = new SqlDataAdapter(cmd);
           da.Fill(dt6);
       }

والخطأ بيظهر فى هذا الكود فى السطر رقم ( 5 ) 
 if (VerifyEntredQuantity(ProductS_N, Convert.ToInt32(txtQuantity.Text)) > 1)
كود :
       private void txtDiscount_KeyDown(object sender, KeyEventArgs e)
       {
           if(e.KeyCode == Keys.Enter)
           {
               if(txtDiscount.Text != string.Empty)
               {
                   foreach(DataGridViewRow Loop in dataGridView1.Rows)
                   {
                       if (VerifyEntredQuantity(ProductS_N, Convert.ToInt32(txtQuantity.Text)) > 1)
                       if(Loop.Cells[1].Value.ToString() == cmbProductName.Text)
                       {
                           MessageBox.Show("هذا المنتج موجود بالفعل", "تنبية", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                           return;
                       }
                   }
                   DataRow Row = dt.NewRow();
                   Row[0] = ProductS_N;
                   Row[1] = cmbProductName.Text;
                   Row[2] = txtPrice.Text;
                   Row[3] = txtQuantity.Text;
                   Row[4] = txtDiscount.Text;
                   Row[5] = txtTotalRequired.Text;
                   dt.Rows.Add(Row);
                   dataGridView1.DataSource = dt;
                   CalculateSumBill();
                   CalculateBill();
                   ClearBillDetails();
                   txtPrice.Focus();
               }
               else
               {
                   MessageBox.Show("يجب ملئ خانة الخصم", "تنبية", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
           }
       }
بتمني  حد يساعني في حل هذه المشكلة 

شكراً مقدماً
الرد }}}
تم الشكر بواسطة:
#2
الفنكشن VerifyEntredQuantity من نوع void لا يرجع باي قيمه

للتصحيح

غير void الى int
كود :
public int VerifyEntredQuantity(string Product_S_N, int QuantityEntred)

واضف return قبل ;(da.Fill(dt6
كود :
return  da.Fill(dt6);
الرد }}}
تم الشكر بواسطة: maxruined
#3
PHP كود :
       public Int32 VerifyEntredQuantity(string Product_S_Nint QuantityEntred)
 
       {
 
           System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
 
           System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
 
           System.Data.SqlClient.SqlConnection con =
 
               new System.Data.SqlClient.SqlConnection("Server =(local);database=TestDB;integrated security=True");
 
           DataTable dt6 = new DataTable();
 
           dt6.Clear();
 
           cmd = new System.Data.SqlClient.SqlCommand("select Count(*) from Products where Product_S_N='" Product_S_N "' and Quantity > '" QuantityEntred "'"con);
 
           da = new System.Data.SqlClient.SqlDataAdapter(cmd);
 
           da.Fill(dt6);
 
           if (dt6.Rows.Count<=0)
 
           {
 
               return 0;
 
           }
 
           return Convert.ToInt32(dt6.Rows[0][0]);
 
       
الرد }}}
تم الشكر بواسطة: maxruined
#4
(23-12-20, 12:12 PM)Ngm كتب : الفنكشن VerifyEntredQuantity من نوع void لا يرجع باي قيمه

للتصحيح

غير void الى int
كود :
public int VerifyEntredQuantity(string Product_S_N, int QuantityEntred)

واضف return قبل ;(da.Fill(dt6
كود :
return  da.Fill(dt6);

شكراً جداً اخوي .. تم حل المشكلة بمساعدتكم

(23-12-20, 01:00 PM)asemshahen5 كتب :
PHP كود :
       public Int32 VerifyEntredQuantity(string Product_S_Nint QuantityEntred)
 
       {
 
           System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
 
           System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
 
           System.Data.SqlClient.SqlConnection con =
 
               new System.Data.SqlClient.SqlConnection("Server =(local);database=TestDB;integrated security=True");
 
           DataTable dt6 = new DataTable();
 
           dt6.Clear();
 
           cmd = new System.Data.SqlClient.SqlCommand("select Count(*) from Products where Product_S_N='" Product_S_N "' and Quantity > '" QuantityEntred "'"con);
 
           da = new System.Data.SqlClient.SqlDataAdapter(cmd);
 
           da.Fill(dt6);
 
           if (dt6.Rows.Count<=0)
 
           {
 
               return 0;
 
           }
 
           return Convert.ToInt32(dt6.Rows[0][0]);
 
       
اخوي عاصم .. الاكثر من رائع .. فعلا تم حل المشكلة بمساعدتكم .. حقيقي شكراً جدا لكم 
دمت متألق اخوي عاصم الله يجزيك كل خير يارب
الرد }}}
تم الشكر بواسطة: asemshahen5 , asemshahen5
#5
واجهتني مشكلة تاني
وهذا هو الخطأ اللى بيظهر 
Unclosed quotation mark after the character string ''.'

وهذا هو الكود اللي مستخدم في عمليه الحفظ

كود :
           if(txtNewClient.Text != string.Empty)
           {
               con.Open();
               cmd = new SqlCommand("insert into Unknown_Clients (S_N,Client_Name)values(@S_N,@Client_Name)", con);
               cmd.Parameters.AddWithValue("S_N", txtClientID.Text);
               cmd.Parameters.AddWithValue("Client_Name", txtNewClient.Text);
               cmd.ExecuteNonQuery();
               con.Close();
               //----------------------------------------------------------
               con.Open();
               cmd = new SqlCommand("insert into Orders_Unknown_Clients (ID_Order,Order_Date,Client_S_N,Description_Order)values(@ID_Order,@Order_Date,@Client_S_N,@Description_Order)", con);
               cmd.Parameters.AddWithValue("ID_Order", Convert.ToInt32(txtOrderID.Text));
               cmd.Parameters.AddWithValue("Order_Date", Convert.ToDateTime(dateTimePicker1.Text));
               cmd.Parameters.AddWithValue("Client_S_N", Convert.ToInt32(txtClientID.Text));
               cmd.Parameters.AddWithValue("Description_Order", txtDescription.Text);
               cmd.ExecuteNonQuery();
               con.Close();

               foreach(DataGridViewRow loop in dataGridView1.Rows)
               {
                   con.Open();
                   cmd = new SqlCommand("insert into Order_Details_Unknown_Clients (Product_S_N,ID_Order,Price,Quantity,Discount,Total_Required)values(@Product_S_N,@ID_Order,@Price,@Quantity,@Discount,@Total_Required)", con);
                   cmd.Parameters.AddWithValue("Product_S_N", Convert.ToInt32(loop.Cells[0].Value.ToString()));
                   cmd.Parameters.AddWithValue("ID_Order", Convert.ToInt32(txtOrderID.Text));
                   cmd.Parameters.AddWithValue("Price", loop.Cells[2].Value.ToString());
                   cmd.Parameters.AddWithValue("Quantity", loop.Cells[3].Value.ToString());
                   cmd.Parameters.AddWithValue("Discount", loop.Cells[4].Value.ToString());
                   cmd.Parameters.AddWithValue("Total_Required", loop.Cells[5].Value.ToString());
                   cmd = new SqlCommand("update Products set Quantity=@Quantity - '" + loop.Cells[3].Value.ToString() + " where Product_S_N='" + ProductS_N + "'", con);
                   cmd.Parameters.AddWithValue("Quantity", loop.Cells[3].Value.ToString());
                   cmd.ExecuteNonQuery();
                   con.Close();
               }
               MessageBox.Show("تم حفظ الفاتورة بنجاح", "إضافه", MessageBoxButtons.OK, MessageBoxIcon.Information);
               ClearDataInDataGridView();
               btnPrintInvoice.Enabled = true;
               btnDeleteCurrentRow.Enabled = false;
               cmbClientName.Enabled = false;
               txtNewClient.Enabled = false;
               txtDescription.Enabled = false;
               dateTimePicker1.Enabled = false;
               cmbProductName.Enabled = false;
               txtPrice.Enabled = false;
               txtQuantity.Enabled = false;
               txtDiscount.Enabled = false;
               txtTotalRequired.Enabled = false;
           }


المفروض ان الخطأ هنا بش مش عارف ليه الحقيقه ليا اكثر من ساعه مش عارف الاقي فين المشكلة
كود :
                   cmd = new SqlCommand("update Products set Quantity=@Quantity - '" + loop.Cells[3].Value.ToString() + " where Product_S_N='" + ProductS_N + "'", con);
                   cmd.Parameters.AddWithValue("Quantity", loop.Cells[3].Value.ToString());
الرد }}}
تم الشكر بواسطة:
#6
Quantity=@Quantity - ' عدله ليكون Quantity=@Quantity -
الرد }}}
تم الشكر بواسطة: maxruined , maxruined
#7
(24-12-20, 08:17 PM)asemshahen5 كتب : Quantity=@Quantity - ' عدله ليكون Quantity=@Quantity -

جلا من لا يسهو .. مع اني نظرت الي الكود اكثر من مرة ولم الاحظ اني ما اغلقتش ال Quotation Mark

شكراً جداً اخوي عاصم 
ولكن ما تزال المشكلة موجود وهي ان الكود بيتم تحديثه بصفر مش بالقيمه الحقيقه المدخله ؟!
وهي المخزن فعلا - المباع = الكمية الموجوده الفعليه في المخزن 
الرد }}}
تم الشكر بواسطة: asemshahen5
#8
حول القيمة من الداتا غريد الى انتجر و الغ ' لانها للقيمة النصية او اعمل استورد بروسيجر يرسل القيمة من الداتاغريد و رقم السيريال للبحث الى الاستعلام في الستورد بروسيجر و هو يقوم بالعملية الحسابية .
الرد }}}
تم الشكر بواسطة: maxruined
#9
(26-12-20, 01:31 PM)asemshahen5 كتب : حول القيمة من الداتا غريد الى انتجر و الغ ' لانها للقيمة النصية او اعمل استورد بروسيجر يرسل القيمة من الداتاغريد و رقم السيريال للبحث الى الاستعلام في الستورد بروسيجر و هو يقوم بالعملية الحسابية .

حولتها ولكن نفس المشكلة بيحدث القيمه بصفر للاسف !!
ودا الكود المستخدم جايز يكون فيه مشكله !!
كود :
                   con.Open();
                   cmd = new SqlCommand("insert into Order_Details_Unknown_Clients (Product_S_N,ID_Order,Price,Quantity,Discount,Total_Required)values(@Product_S_N,@ID_Order,@Price,@Quantity,@Discount,@Total_Required)", con);
                   cmd.Parameters.AddWithValue("Product_S_N", Convert.ToInt32(loop.Cells[0].Value.ToString()));
                   cmd.Parameters.AddWithValue("ID_Order", Convert.ToInt32(txtOrderID.Text));
                   cmd.Parameters.AddWithValue("Price", loop.Cells[2].Value.ToString());
                   cmd.Parameters.AddWithValue("Quantity",loop.Cells[3].Value);
                   cmd.Parameters.AddWithValue("Discount", loop.Cells[4].Value.ToString());
                   cmd.Parameters.AddWithValue("Total_Required", loop.Cells[5].Value.ToString());
                   cmd = new SqlCommand("update Products set Quantity=@Quantity - " +loop.Cells[3].Value + " where Product_S_N='" + ProductS_N + "'", con);
                   cmd.Parameters.AddWithValue("Quantity",loop.Cells[3].Value);
                   cmd.ExecuteNonQuery();
                   con.Close();
الرد }}}
تم الشكر بواسطة:
#10
PHP كود :
cmd = new SqlCommand("update Products set Quantity=Quantity - " +loop.Cells[3].Value " where Product_S_N='" ProductS_N "'"con); 

يعني :

PHP كود :
Quantity=Quantity " +loop.Cells[3].Value + " 

من دون @ .
الرد }}}
تم الشكر بواسطة: maxruined



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


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