private void btnChoose_Click(object sender, EventArgs e)
        {
            radGridViewExtended1.DataSource = null;
            dataGridView1.DataSource        = null;
            btnChoose.Cursor = Cursors.WaitCursor;

            string         filePath = string.Empty;
            string         fileExt  = string.Empty;
            OpenFileDialog file     = new OpenFileDialog();                //open dialog to choose file

            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user
            {
                filePath = file.FileName;                                  //get the path of the file
                fileExt  = Path.GetExtension(filePath);                    //get the file extension
                if (fileExt.CompareTo(".xls") == 0 || fileExt.CompareTo(".xlsx") == 0)
                {
                    try
                    {
                        DataTable dtExcel = new DataTable();
                        dtExcel = ReadExcel(filePath, fileExt);//read excel file
                        dataGridView1.Visible    = true;
                        dataGridView1.DataSource = dtExcel;

                        #region Validate
                        List <ErrorExcel> _listerro = new List <ErrorExcel>();
                        for (int rows = 0; rows < dataGridView1.Rows.Count; rows++)
                        {
                            string        PersonnelNumber = "";
                            StringBuilder er = new StringBuilder();
                            try
                            {
                                if (dataGridView1.Rows[rows].Cells[0].Value != null)
                                {
                                    //چک کردن شماره پرسنلی ها
                                    PersonnelNumber = dataGridView1.Rows[rows].Cells[0].Value.ToString();
                                    if (CheckPersonnelNumber(PersonnelNumber) == false)
                                    {
                                        er.Append("کد پرسنلی");
                                        er.Append("'" + PersonnelNumber + "'");
                                        er.Append("در سیستم وجود دارد");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                er.Append(ex);
                            }

                            if (er.Length != 0)
                            {
                                ErrorExcel ex = new ErrorExcel();
                                ex.Row             = rows;
                                ex.PerssonelNumber = PersonnelNumber;
                                ex.Error           = er;
                                _listerro.Add(ex);
                                continue;
                            }
                        }
                        #endregion
                        if (_listerro.Any())
                        {
                            radGridViewExtended1.DataSource = null;
                            radGridViewExtended1.DataSource = _listerro;
                            radGridViewExtended1.EnableAlternatingRowColor = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.ToString().Contains("not set"))
                        {
                            MessageBox.Show("هیچی اطلاعاتی وارد نشده است");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please choose .xls or .xlsx file only.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);//custom messageBox to show error
                }
            }
            btnChoose.Cursor = Cursors.Default;
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (dossierTypeComboBoxExtended.SelectedValue == null)
            {
                MessageBox.Show("سطح دسترسی پرونده ها را مشخص نکرده اید");
            }
            else if (dataGridView1.Rows.Count <= 1)
            {
                MessageBox.Show("اطلاعات دانشجویان وارد نشده است");
            }
            #region CreateDossier
            List <ErrorExcel> _listerro = new List <ErrorExcel>();
            for (int rows = 0; rows < dataGridView1.Rows.Count; rows++)
            {
                string        PersonnelNumber = "";
                StringBuilder er = new StringBuilder();
                try
                {
                    if (dataGridView1.Rows[rows].Cells[0].Value != null)
                    {
                        //کدپرسنلی
                        PersonnelNumber = dataGridView1.Rows[rows].Cells[0].Value.ToString();
                        //چک کردن شماره پرسنلی ها
                        if (CheckPersonnelNumber(PersonnelNumber) == false)
                        {
                            continue;
                        }
                        else
                        {
                            //اضافه کردن ااطلاعات کدپرسنلی
                            List <Model.Archive.ArchiveTab>         archiveTabs    = Controller.Archive.ArchiveTabController.GetActiveDossierTabs();
                            Model.Archive.Dossier                   dossier        = Model.Archive.Dossier.GetNewInstance(PersonnelNumber, null, Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase ? Setting.Archive.ThisProgram.LoadedArchiveSettings.DocumentsPathOrDatabaseName : Path.Combine(Setting.Archive.ThisProgram.LoadedArchiveSettings.DocumentsPathOrDatabaseName, Njit.Common.PublicMethods.ReplaceInvalidPathAndFileNameChars(PersonnelNumber, "-")), Convert.ToInt32(dossierTypeComboBoxExtended.SelectedValue));
                            List <System.Data.SqlClient.SqlCommand> sqlCommandList = new List <System.Data.SqlClient.SqlCommand>();
                            foreach (Model.Archive.ArchiveTab tab in archiveTabs)
                            {
                                sqlCommandList.Add(SqlHelper.GetDeleteCommandForArchiveTab(tab, PersonnelNumber));
                                List <Dossier1> listDossier1 = new List <Dossier1>();
                                //نام
                                listDossier1.Add(CreateDossier1(rows, 1, "Field1", "string"));
                                //نام خانوادگی
                                listDossier1.Add(CreateDossier1(rows, 2, "Field2", "string"));
                                //کدملی
                                listDossier1.Add(CreateDossier1(rows, 3, "Field15", "string"));
                                //نام پدر
                                listDossier1.Add(CreateDossier1(rows, 4, "Field1018", "string"));
                                //جنسیت
                                listDossier1.Add(CreateDossier1(rows, 5, "Field1019", "string"));
                                //ش ش
                                listDossier1.Add(CreateDossier1(rows, 6, "Field1020", "int"));
                                // ت ت
                                listDossier1.Add(CreateDossier1(rows, 7, "Field1021", "string"));
                                //تلفن دائم
                                listDossier1.Add(CreateDossier1(rows, 8, "Field1049", "int"));
                                //تلفن ضروری
                                listDossier1.Add(CreateDossier1(rows, 9, "Field1045", "string"));
                                //تلفن همراه
                                listDossier1.Add(CreateDossier1(rows, 10, "Field1041", "string"));
                                //کد پستی
                                listDossier1.Add(CreateDossier1(rows, 11, "Field1043", "string"));
                                //صندوق پستی
                                listDossier1.Add(CreateDossier1(rows, 12, "Field1044", "string"));
                                //استان
                                listDossier1.Add(CreateDossier1(rows, 13, "Field1034", "string"));
                                //شهر
                                listDossier1.Add(CreateDossier1(rows, 14, "Field1035", "string"));
                                //بخش
                                listDossier1.Add(CreateDossier1(rows, 15, "Field1036", "string"));
                                //ادرس
                                listDossier1.Add(CreateDossier1(rows, 16, "Field1029", "string"));
                                //رشته
                                listDossier1.Add(CreateDossier1(rows, 17, "Field1032", "string"));
                                //مقطع
                                listDossier1.Add(CreateDossier1(rows, 18, "Field1033", "string"));
                                //معدل
                                listDossier1.Add(CreateDossier1(rows, 19, "Field1046", "double"));
                                //تاریخ اخذ
                                listDossier1.Add(CreateDossier1(rows, 20, "Field1048", "string"));
                                //نظام وظیفه
                                listDossier1.Add(CreateDossier1(rows, 21, "Field1047", "string"));
                                //دین
                                listDossier1.Add(CreateDossier1(rows, 22, "Field1037", "string"));
                                //مذهب
                                listDossier1.Add(CreateDossier1(rows, 23, "Field1038", "string"));
                                //ملیت
                                listDossier1.Add(CreateDossier1(rows, 24, "Field1042", "string"));
                                //سال قبولی
                                listDossier1.Add(CreateDossier1(rows, 25, "Field1040", "int"));
                                //رتبه
                                listDossier1.Add(CreateDossier1(rows, 26, "Field1039", "int"));
                                //سهمیه نهایی
                                listDossier1.Add(CreateDossier1(rows, 27, "Field1025", "string"));
                                //سهمیه ثبت نام
                                listDossier1.Add(CreateDossier1(rows, 28, "Field1024", "string"));
                                //ترم ورود
                                listDossier1.Add(CreateDossier1(rows, 29, "Field1023", "int"));
                                //تاریخ شروع تحصیل
                                listDossier1.Add(CreateDossier1(rows, 30, "Field1022", "int"));
                                //نیسمال ثبت نام
                                listDossier1.Add(CreateDossier1(rows, 31, "Field1026", "int"));
                                //نوع پذیرش
                                listDossier1.Add(CreateDossier1(rows, 32, "Field1027", "string"));
                                // نوع بورسیه
                                listDossier1.Add(CreateDossier1(rows, 33, "Field1028", "string"));
                                //نوع دوره
                                listDossier1.Add(CreateDossier1(rows, 34, "Field1030", "string"));
                                //دانشکده
                                listDossier1.Add(CreateDossier1(rows, 35, "Field1031", "string"));
                                //شماره قدیم
                                listDossier1.Add(CreateDossier1(rows, 36, "Field1050", "string"));
                                //دانشجو میهمان
                                listDossier1.Add(CreateDossier1(rows, 37, "Field1051", "bool"));
                                listDossier1.Add(CreateDossier1(rows, 38, "Field1052", "bool"));
                                listDossier1.Add(CreateDossier1(rows, 39, "Field1053", "string"));
                                List <System.Data.SqlClient.SqlCommand> sqlCommands = SqlHelper.GetDossier1InsertCommands(listDossier1, tab, PersonnelNumber);
                                sqlCommandList.AddRange(sqlCommands);
                                List <Model.Archive.ContactView> contactView = new List <Model.Archive.ContactView>();
                                List <Model.Archive.AddressView> addressView = new List <Model.Archive.AddressView>();
                                Model.Archive.Info info = null;

                                Controller.Archive.DossierController.Insert(dossier, sqlCommandList, contactView, addressView, info);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    er.Append(ex);
                }

                if (er.Length != 0)
                {
                    ErrorExcel ex = new ErrorExcel();
                    ex.Row             = rows;
                    ex.PerssonelNumber = PersonnelNumber;
                    ex.Error           = er;
                    _listerro.Add(ex);
                    continue;
                }
            }
            #endregion
            if (_listerro.Any())
            {
                radGridViewExtended1.DataSource = null;
                radGridViewExtended1.DataSource = _listerro;
                radGridViewExtended1.EnableAlternatingRowColor = true;
            }
            else
            {
                MessageBox.Show("تمام اطلاعات با موفقیت ثبت شد");
            }
        }