Example #1
0
        } //------------------------

        //this procedure exports the student data to the sql server
        private void ExportStudentDataToSqlServer()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Int32 deniedCount  = 0;
                Int32 successCount = 0;
                Int32 rowCount     = 0;

                pgbImport.Step    = 1;
                pgbImport.Maximum = this.dgvList.Rows.Count;

                foreach (DataRow studRow in _studentTable.Rows)
                {
                    this.SetDataGridViewBehavior(rowCount);

                    String studentId   = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "ACCESSION", "");
                    String cardNumber  = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "KEYWORDS", "");
                    String studentName = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "TITLE0", "");

                    if (!this.IsExistStudentIdStudentInformation(_userInfo, studentId, "") &&
                        !this.IsExistCardNumberStudentInformation(_userInfo, cardNumber, "") &&
                        !String.Equals("(blank)", studentName) &&
                        !String.IsNullOrEmpty(RemoteClient.ProcStatic.TrimStartEndString(cardNumber)) &&
                        !String.IsNullOrEmpty(RemoteClient.ProcStatic.TrimStartEndString(studentId)))
                    {
                        String remarks = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "REMARKS", "");

                        CommonExchange.Student studentInfo = new CommonExchange.Student();

                        studentInfo.ObjectState            = DataRowState.Added;
                        studentInfo.PersonInfo.ObjectState = DataRowState.Added;

                        StudentName    studName   = this.GetStudentNameDetails(studentName);
                        RemarksDetails remarkInfo = this.GetRemarksDetails(remarks);

                        studentInfo.StudentId            = RemoteClient.ProcStatic.TrimStartEndString(studentId);
                        studentInfo.PersonInfo.LastName  = studName.LastName;
                        studentInfo.PersonInfo.FirstName = studName.FirstName;
                        studentInfo.CardNumber           = cardNumber;
                        studentInfo.Scholarship          = studName.Scholoarship;
                        studentInfo.CourseInfo.CourseId  = this.GetCourseId(remarkInfo.CourseName);
                        studentInfo.PersonInfo.OtherPersonInformation = remarkInfo.OtherInformation;
                        studentInfo.PersonInfo.BirthDate = String.Empty;

                        if (!String.IsNullOrEmpty(_imagePath) && this.chkImage.Checked)
                        {
                            StudentImage imageInfo = this.GetStudentImageDetails(studentId);

                            if (!String.IsNullOrEmpty(imageInfo.ImagePath))
                            {
                                studentInfo.PersonInfo.FilePath      = imageInfo.ImagePath;
                                studentInfo.PersonInfo.FileData      = RemoteClient.ProcStatic.GetFileArrayBytes(imageInfo.ImagePath);
                                studentInfo.PersonInfo.FileExtension = imageInfo.ImageExtension;
                                studentInfo.PersonInfo.FileName      = Path.GetFileName(imageInfo.ImagePath);

                                this.txtDirectory.Text = imageInfo.ImagePath;
                            }
                        }

                        using (RemoteClient.RemCntStudentManager remClient = new RemoteClient.RemCntStudentManager())
                        {
                            remClient.InsertStudentInformation(_userInfo, ref studentInfo);
                        }

                        using (RemoteClient.RemCntIdMakerManager remClient = new RemoteClient.RemCntIdMakerManager())
                        {
                            remClient.UpdateForIdMakerStudentInformation(_userInfo, studentInfo);
                        }

                        successCount++;
                    }
                    else
                    {
                        deniedCount++;
                    }

                    pgbImport.PerformStep();

                    rowCount++;

                    Application.DoEvents();
                    this.Refresh();
                }

                MessageBox.Show("Student data has been successfully exported to the SQL Server" + "\n\nSuccess: " + successCount.ToString() + " Record(s)" +
                                "\nDenied: " + deniedCount.ToString() + " Record(s)", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                pgbImport.Value = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in exporting: " + ex.Message, "Error");
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        } //--------------------------------------