Esempio n. 1
0
        public async void ForRunThrading()
        {
            try
            {
                dataGridViewX1.Enabled = false;

                ClassDataGridViewDo.ClumChekArray(NameCol, dataGridViewX1);
                progressBarX1.Maximum = dataGridViewX1.Rows.Count;
                int       IndexCombox = comboBoxEx1.SelectedIndex;
                Stopwatch stopwatch   = new Stopwatch();

                stopwatch.Start();
                for (int i = 0; i < dataGridViewX1.Rows.Count; i++)
                {
                    stopwatch.Restart();
                    // إيقاف العمل في خلفية التزامن
                    if (!Workin)
                    {
                        break;
                    }
                    //العداد
                    progressBarX1.Value = i;
                    // إنتظار بين الأمر والثاني
                    await System.Threading.Tasks.Task.Delay(100);



                    int   id             = ClassConvert.Convint(dataGridViewX1.Rows[i].Cells["id"].Value);
                    int   NumberOfCoures = ClassConvert.Convint(dataGridViewX1.Rows[i].Cells["رقم الدورة"].Value);
                    int?  NuberOfDayes   = ClassConvert.ConvintNull(dataGridViewX1.Rows[i].Cells["عدد الأيام"].Value);
                    float?float1         = ClassConvert.ConvFloatNull(dataGridViewX1.Rows[i].Cells["النتيجة"].Value);
                    //أختبار هل الدورة مسجل عند الشخص + أنه تأكد من وجود ID
                    if (!await Couress.GetIsItHaveCouresByIdInformation(id, IndexCombox))
                    {
                        if (id > 0 && NumberOfCoures > 0 && NuberOfDayes != null && float1 != null)
                        {
                            int IdTheNameOfcoures = NameOfCouress.SerchByListStaticRetId(TypeofCouress.TypeofCouressList[IndexCombox].id, NumberOfCoures);
                            if (IdTheNameOfcoures == -1)
                            {
                                DevComponents.DotNetBar.MessageBoxEx.Show("رقم الدورة غير مضاف:" + NumberOfCoures);
                                break;
                            }


                            Couress CouresNew = new Couress(0, IdTheNameOfcoures, id, (int)NuberOfDayes, (float)float1);
                            await Sqldatabasethrding.SqlSaveVitl(CouresNew.adder());

                            dataGridViewX1.Rows[i].DefaultCellStyle.BackColor = Color.Green;
                        }
                        else
                        {
                            dataGridViewX1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                        }
                    }
                    else
                    {
                        dataGridViewX1.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
                    }

                    labelX2.Text = ((stopwatch.ElapsedMilliseconds * (dataGridViewX1.Rows.Count - i)) / 1000).ToString();
                }
            }
            catch (NoColumnsException ex)
            {
                ErrorClass.SaveErrorFile(ex);
                MessageBox.Show(string.Format(" لا يوجد عامود {0} ", ex.Message));
            }
            catch (Exception ex)
            {
                ErrorClass.SaveErrorFile(ex);
            }

            buttonX3.Enabled       = true;
            Workin                 = false;
            dataGridViewX1.Enabled = true;
        }