تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كود حفظ
#7
(31-07-19, 10:28 AM)asemshahen5 كتب : ضع هذا بالكلاس :

PHP كود :
     public static void SaveColumnValueXT(DataGridView DGV_EmployInt32 RowIndexstring TableName string IDColInt32 IDColIndexbool IdentityIncrement)
 
       {
 
           if (RowIndex 0)
 
           {
 
               return;
 
           }
 
           ArrayList ArrCol = new ArrayList();
 
           ArrCol FillArrayList(TableName);
 
           //if (DGV_Employ.Rows[RowIndex].Cells[IDColIndex].Value != null)
 
           //{
 
           DataGridViewRow dgvRow DGV_Employ.Rows[RowIndex];
 
           SqlCommand sqlCmd = new SqlCommand();
 
           sqlCmd.CommandType CommandType.Text;
 
           string SqlStr string.Empty;
 
           string SqlPar string.Empty;

 
           if (DGV_Employ.Rows[RowIndex].Cells[IDColIndex].Value.ToString() == string.Empty || RowIndex == DGV_Employ.Rows.Count 2)//Insert
 
           {
 
               SqlStr "INSERT INTO " TableName "(";
 
               for (int i 0ArrCol.Counti++)
 
               {
 
                   if (== ArrCol.Count 1)
 
                   {
 
                       if (IdentityIncrement == true)
 
                       {
 
                           if (IDCol == ArrCol[i].ToString())
 
                           {
 
                               continue;
 
                           }
 
                       }

 
                       SqlStr += ArrCol[i].ToString() + ")VALUES(";
 
                       SqlPar += "@" ArrCol[i].ToString() + ")";
 
                   }
 
                   else
                    
{
 
                       if (IdentityIncrement == true)
 
                       {
 
                           if (IDCol == ArrCol[i].ToString())
 
                           {
 
                               continue;
 
                           }
 
                       }
 
                       SqlStr += ArrCol[i].ToString() + ",";
 
                       SqlPar += "@" ArrCol[i].ToString() + ",";
 
                   }
 
               }
 
               SqlStr += SqlPar;
 
               sqlCmd = new SqlCommand(SqlStrCon);
 
           }
 
           else //update
 
           {
 
               SqlStr "UPDATE " TableName " SET ";
 
               for (int i 0ArrCol.Counti++)
 
               {

 
                   if (== ArrCol.Count 1)
 
                   {
 
                       if (IDCol == ArrCol[i].ToString())
 
                       {
 
                           continue;
 
                       }
 
                       SqlStr += ArrCol[i].ToString() + "=@" ArrCol[i].ToString();
 
                   }
 
                   else
                    
{
 
                       if (IDCol == ArrCol[i].ToString())
 
                       {
 
                           continue;
 
                       }
 
                       SqlStr += ArrCol[i].ToString() + "=@" ArrCol[i].ToString() + ",";
 
                   }
 
               }
 
               SqlStr += " WHERE " IDCol "=@" IDCol "" "";
 
               sqlCmd = new SqlCommand(SqlStrCon);
 
           }
 
           for (int i 0ArrCol.Counti++)
 
           {
 
               if (SqlStr.Contains("UPDATE"))
 
               {
 
                   sqlCmd.Parameters.AddWithValue("@" ArrCol[i].ToString(), DGV_Employ.Rows[RowIndex].Cells[i].Value == null "" DGV_Employ.Rows[RowIndex].Cells[i].Value.ToString());
 
               }
 
               else if (SqlStr.Contains("INSERT"))
 
               {
 
                   if (IdentityIncrement == true)
 
                   {
 
                       if (IDCol == ArrCol[i].ToString())
 
                       {
 
                           continue;
 
                       }
 
                       else
                        
{
 
                           sqlCmd.Parameters.AddWithValue("@" ArrCol[i].ToString(), DGV_Employ.Rows[RowIndex].Cells[i].Value.ToString());// == DBNull.Value ? "" : dgvRow.Cells[i].Value.ToString());
 
                       }
 
                   }
 
                   else
                    
{
 
                       sqlCmd.Parameters.AddWithValue("@" ArrCol[i].ToString(), DGV_Employ.Rows[RowIndex].Cells[i].Value.ToString());// == DBNull.Value ? "" : dgvRow.Cells[i].Value.ToString());
 
                   }
 
               }
 
           }
 
           Con.Open();
 
           sqlCmd.ExecuteNonQuery();
 
           Con.Close();
 
           FillDGV(DGV_Employ"Select * From " TableName);
 
       }

 
       private static ArrayList FillArrayList(string TableName)
 
       {
 
           DataTable DT = new DataTable();
 
           ArrayList ColumnNameXT = new ArrayList();
 
           ColumnNameXT.Clear();
 
           DT DB.ExecSelect("Select * From "TableName);
 
           for (int i 0DT.Columns.Counti++)
 
           {
 
               ColumnNameXT.Add(DT.Columns[i].ColumnName);
 
           }
 
           return ColumnNameXT;
 
       

و هذا كود استخدامه :

PHP كود :
       private void DGV_Employ_CellValueChanged(object senderDataGridViewCellEventArgs e)
 
       {
 
           DB.SaveColumnValueXT(DGV_Employe.RowIndex"Employ" "Emp_ID",0,true);
 
       

و اصلح كود التنظيف كالتالي :

PHP كود :
       public static void CleanAllControl(Control ctrlParentbool DGVCleanRow)
 
       {
 
           foreach (Control ctrl in ctrlParent.Controls)
 
           {
 
               if (ctrl.HasChildren == true)
 
               {
 
                   CleanAllControl(ctrlDGVCleanRow);
 
               }
 
               if (ctrl is System.Windows.Forms.TextBox)
 
               {
 
                   ctrl.Text "";
 
               }
 
               else if (ctrl is CheckBox)
 
               {
 
                   //bool chk;
 
                   CheckBox chk ctrlParent.Controls[ctrl.Name] as CheckBox;
 
                   chk.Checked false;
 
               }
 
               else if (ctrl is System.Windows.Forms.ComboBox)
 
                   ctrl.Text "";
 
               else if (ctrl is DataGridView)
 
               {
 
                   if (DGVCleanRow == true)
 
                   {
 
                       DataGridView Dgv ctrlParent.Controls[ctrl.Name] as DataGridView;
 
                       Dgv.DataSource null;
 
                   }
 
               }
 
           }
 
           //return StrD;
 
       

PHP كود :
               //true لتنظيف الجداول ايضا//false لا تنظف الجداول
 
               DB.CleanAllControl(thistrue); 

كود الماكس عدلته لك في موضوع آخر .

نسيت إخبارك إحذف كل أزرار الحذف من الجداول ليعمل الكود على اي جدول .
الف شكر ليك استاذي الفالى 
بس لو ممكن تتعب شويه معايا وترفق الاكواد داخل الملف 
اكون شاكر جدا لحضرتك لاننى حاولت افهم الكود مقدرتش لقلة خبرتى 
وجزاك الله كل خير
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
كود حفظ - بواسطة amonem - 30-07-19, 08:09 PM
RE: كود حفظ - بواسطة amonem - 30-07-19, 11:50 PM
RE: كود حفظ - بواسطة asemshahen5 - 31-07-19, 12:15 AM
RE: كود حفظ - بواسطة amonem - 31-07-19, 12:53 AM
RE: كود حفظ - بواسطة amonem - 31-07-19, 10:25 AM
RE: كود حفظ - بواسطة asemshahen5 - 31-07-19, 10:28 AM
RE: كود حفظ - بواسطة amonem - 31-07-19, 05:23 PM
RE: كود حفظ - بواسطة asemshahen5 - 01-08-19, 01:53 AM
RE: كود حفظ - بواسطة amonem - 01-08-19, 03:18 AM
RE: كود حفظ - بواسطة asemshahen5 - 01-08-19, 04:13 AM
RE: كود حفظ - بواسطة amonem - 01-08-19, 04:58 AM
RE: كود حفظ - بواسطة asemshahen5 - 01-08-19, 09:37 AM
RE: كود حفظ - بواسطة amonem - 01-08-19, 04:30 PM
RE: كود حفظ - بواسطة amonem - 02-08-19, 09:17 PM
RE: كود حفظ - بواسطة amonem - 02-08-19, 01:52 PM
RE: كود حفظ - بواسطة asemshahen5 - 03-08-19, 02:00 PM
VB.NET - بواسطة ansamshtaya - 09-01-24, 12:19 AM
RE: كود حفظ - بواسطة SATDJATV - 05-04-25, 03:54 PM

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


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