示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.gData.Rows.Count == -1)
            {
                alert.Show("No data to save ....", alert.AlertType.info);
            }
            alert.Show("Saving ....", alert.AlertType.info);
            using (var context = new SmartdbEntities())
            {
                for (int i = 0; i < this.gData.Rows.Count - 1; i++)
                {
                    DataGridViewRow dr = gData.Rows[i];
                    if (dr != null && (dr.Cells["RegNo"].Value != null) && (dr.Cells["FullName"].Value != null))
                    {
                        try
                        {
                            context.Students.Add(new Student
                            {
                                //check for duplicate Admin number
                                Regno        = dr.Cells["RegNo"].Value.ToString(),
                                FullName     = dr.Cells["FullName"].Value.ToString(),
                                School       = dr.Cells["School"].Value.ToString(),
                                SchoolCode   = dr.Cells["SchoolCode"].Value.ToString(),
                                LearningMode = dr.Cells["LearningMode"].Value.ToString(),
                            });
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Check all entries are correct and retry", "Error");
                            // throw;
                        }
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "Critical error contact developer immediately \n :( :( :( :( :( :(:( :( ", "Read Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                try
                {
                    context.SaveChanges();
                    alert.Show("Saved Successfully", alert.AlertType.success);
                }
                catch (Exception) { }
            }


            this.Close();
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //verification
            if (currentStudent == null)
            {
                alert.Show("Required info \n Search for Student", alert.AlertType.warnig);
                return;
            }

            if (disAction == 0 & disLevel == 0)
            {
                alert.Show("Required info \n Select provided options", alert.AlertType.warnig);
                return;
            }


            //save the current student info
            using (var context = new SmartdbEntities())
            {
                Disciplinary dd = new Disciplinary();
                dd.Regno   = currentStudent.Regno;
                dd.Action  = dropAction.selectedValue.ToString();
                dd.Details = tbLegalInfo.Text;
                dd.level   = (disAction + disLevel);

                try
                {
                    context.Disciplinaries.Add(dd);
                    context.SaveChanges();
                    alert.Show("Saved Successfully", alert.AlertType.success);

                    //set ui again
                    UIset(currentStudent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }