public void SaveOrEdit()
        {
            try
            {
                if (cboLevel.SelectedIndex == -1)
                {
                    MessageBox.Show("Select a class");
                    cboLevel.Focus();
                }

                else if (txtFirstName.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Enter FirstName");
                    txtFirstName.Focus();
                }
                else if (txtLastName.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Enter OtherName");
                    txtLastName.Focus();
                }

                else if (txtAdmision.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Enter Admission Number");
                    txtAdmision.Focus();
                }

                else if (cboGender.SelectedIndex == -1)
                {
                    MessageBox.Show("Select a Gender");
                    cboGender.Focus();
                }


                else
                {
                    AccountLedgerInfo student   = new AccountLedgerInfo();
                    StudentSP         studentSP = new StudentSP();
                    if (cbxActive.Checked)
                    {
                        student.Active = true;
                    }
                    else
                    {
                        student.Active = false;
                    }

                    student.AccountGroupId = 15;
                    student.CrOrDr         = cmbDrorCr.Text.Trim();


                    student.LedgerName     = txtFirstName.Text.Trim();
                    student.OtherName      = txtLastName.Text.Trim();
                    student.DateOfBirth    = Convert.ToDateTime(txtDateOfBirth.Text.Trim());
                    student.OpeningBalance = txtOpeningBalance.Text.Trim() == string.Empty? balance : Convert.ToDecimal(txtOpeningBalance.Text.Trim());
                    student.HomePhone      = txtPhone.Text.Trim();
                    student.Email          = txtEmail.Text.Trim();
                    student.Gender         = cboGender.SelectedItem.ToString();

                    student.AdminNumber = txtAdmision.Text.Trim();
                    student.ClassNo     = Convert.ToInt32(cboLevel.SelectedValue.ToString());
                    student.DateJoined  = Convert.ToDateTime(txtDateJoined.Text.Trim());
                    student.Photo       = photoPath;

                    student.GuardianName         = txtGuardianName.Text.Trim();
                    student.GuardianEmail        = txtGuardianEmail.Text.Trim();
                    student.GuardianRelationship = txtRelatioship.Text.Trim();
                    student.GuardianPhone        = txtGuardianPhone.Text.Trim();


                    if (btnSave.Text == "Save")
                    {
                        if (Messages.SaveMessage())
                        {
                            studentSP.StudentAdd(student);
                            Messages.SavedMessage();
                            ClearFunction();
                            txtFirstName.Focus();
                        }
                    }
                    else
                    {
                        if (Messages.UpdateMessage())
                        {
                            studentSP.StudentEdit(student, studentId);
                            Messages.UpdatedMessage();
                            ClearFunction();
                            txtFirstName.Focus();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txbExcelPath.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Browse for the excel path");
                txbExcelPath.Focus();
            }

            if (textSheetName.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Enter Sheet Name");
                textSheetName.Focus();
            }

            else
            {
                AccountLedgerInfo student   = new AccountLedgerInfo();
                StudentSP         studentSP = new StudentSP();

                int rowcounter = dataGridView1.RowCount;
                try
                {
                    for (int i = 0; i < rowcounter; i++)
                    {
                        if (dataGridView1.Rows[i].Cells["FirstName"].Value != null && dataGridView1.Rows[i].Cells["FirstName"].Value.ToString() != string.Empty)
                        {
                            student.LedgerName = Convert.ToString(dataGridView1.Rows[i].Cells["FirstName"].Value);
                        }

                        if (dataGridView1.Rows[i].Cells["LastName"].Value != null && dataGridView1.Rows[i].Cells["LastName"].Value.ToString() != string.Empty)
                        {
                            student.OtherName = Convert.ToString(dataGridView1.Rows[i].Cells["LastName"].Value);
                        }

                        if (dataGridView1.Rows[i].Cells["gender"].Value != null && dataGridView1.Rows[i].Cells["gender"].Value.ToString() != string.Empty)
                        {
                            student.Gender = Convert.ToString(dataGridView1.Rows[i].Cells["gender"].Value);
                        }

                        if (dataGridView1.Rows[i].Cells["dateOfBirth"].Value != null && dataGridView1.Rows[i].Cells["dateOfBirth"].Value.ToString() != string.Empty)
                        {
                            student.DateOfBirth = Convert.ToDateTime(dataGridView1.Rows[i].Cells["dateOfBirth"].Value.ToString());
                        }


                        if (dataGridView1.Rows[i].Cells["AdminNumber"].Value != null && dataGridView1.Rows[i].Cells["AdminNumber"].Value.ToString() != string.Empty)
                        {
                            student.AdminNumber = Convert.ToString(dataGridView1.Rows[i].Cells["AdminNumber"].Value);
                        }

                        if (dataGridView1.Rows[i].Cells["Class"].Value != null && dataGridView1.Rows[i].Cells["Class"].Value.ToString() != string.Empty)
                        {
                            student.ClassNo = Convert.ToInt32(dataGridView1.Rows[i].Cells["Class"].Value.ToString());
                        }

                        if (dataGridView1.Rows[i].Cells["AdmissionDate"].Value != null && dataGridView1.Rows[i].Cells["AdmissionDate"].Value.ToString() != string.Empty)
                        {
                            student.DateJoined = Convert.ToDateTime(dataGridView1.Rows[i].Cells["AdmissionDate"].Value);
                        }

                        student.AccountGroupId = 15;
                        student.CrOrDr         = "Cr";
                        studentSP.StudentAdd(student);
                    }

                    MessageBox.Show("Saved succesfully");
                    btnSave.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }