private void btnsave_Click(object sender, EventArgs e)
        {
            if (txtstdname.Text != null && txtstdname.Text != "" && txtathername.Text != null && txtathername.Text != "" && txtregno.Text != null && txtregno.Text != "" &&
                txtmothername.Text != null && txtmothername.Text != "" && DateofBirthPicker.Text != null && DateofBirthPicker.Text != "" && txtaddress.Text != null && txtaddress.Text != "" &&
                txtplaceofbirth.Text != null && txtplaceofbirth.Text != "" && txtcnic.Text != null && txtcnic.Text != "" &&
                ComboBoxGender.Text != null && ComboBoxGender.Text != "" && txtreligion.Text != null && txtreligion.Text != "" &&
                txtcontact.Text != null && txtcontact.Text != "" && comboboxclass.Text != null && comboboxclass.Text != "" &&
                comboboxsection.Text != null && comboboxsection.Text != "" && Admitdatepicker.Text != null && Admitdatepicker.Text != "")
            {
                try
                {
                    var i = db.StudentDatas.Where(c => c.ID == ModifyStudent.STUDENT_ID).FirstOrDefault();
                    var j = db.StudentProfiles.Where(d => d.ID == ModifyStudent.STUDENT_ID).FirstOrDefault();
                    i.StudentName  = txtstdname.Text;
                    i.FatherName   = txtathername.Text;
                    i.RegNo        = txtregno.Text;
                    i.MotherName   = txtmothername.Text;
                    i.DateOfBirth  = DateofBirthPicker.Value.ToString();
                    i.PlaceOfBirth = txtplaceofbirth.Text;
                    i.Address      = txtaddress.Text;
                    i.NIC          = txtcnic.Text;
                    i.Gender       = ComboBoxGender.Text;
                    i.Religion     = txtreligion.Text;
                    i.Contact      = txtcontact.Text;
                    i.Class        = comboboxclass.Text;
                    i.Section      = comboboxsection.Text;
                    i.AdmitDate    = Admitdatepicker.Value.ToString();

                    if (bimage != null)
                    {
                        j.Profile = bimage;
                    }

                    db.Entry(i).State = System.Data.Entity.EntityState.Modified;
                    db.Entry(j).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBoxAdv.Show(ex.Message.ToString(), "Something Went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    db.Dispose();
                    MessageBox.Show("You have successfully updated a new record named as: " + txtstdname.Text, "New record added - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.None);
                    RESET = true;
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("All fields are mandatory!", "Error - Student Management Sytem", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void btnsave_Click(object sender, EventArgs e)
        {
            if (txtstdname.Text != null && txtstdname.Text != "" && txtathername.Text != null && txtathername.Text != "" && txtregno.Text != null && txtregno.Text != "" &&
                txtmothername.Text != null && txtmothername.Text != "" && DateofBirthPicker.Text != null && DateofBirthPicker.Text != "" && txtaddress.Text != null && txtaddress.Text != "" &&
                txtplaceofbirth.Text != null && txtplaceofbirth.Text != "" && txtcnic.Text != null && txtcnic.Text != "" &&
                ComboBoxGender.Text != null && ComboBoxGender.Text != "" && txtreligion.Text != null && txtreligion.Text != "" &&
                txtcontact.Text != null && txtcontact.Text != "" && comboboxclass.Text != null && comboboxclass.Text != "" &&
                comboboxsection.Text != null && comboboxsection.Text != "" && Admitdatepicker.Text != null && Admitdatepicker.Text != "")
            {
                try
                {
                    var       data      = db.Randoms.Where(x => x.ID == 6).FirstOrDefault();
                    ArrayList arrayList = new ArrayList();
                    arrayList.AddRange(data.Text.Split(','));

                    bool classcheck = false;

                    for (int i = 0; i <= arrayList.ToArray().Length - 1; i++)
                    {
                        if (comboboxclass.Text == arrayList[i].ToString())
                        {
                            classcheck = true;
                        }
                    }


                    if (classcheck)
                    {
                        int index = 0;
                        for (int x = 0; x <= arrayList.ToArray().Length - 1; x++)
                        {
                            if (comboboxclass.Text == arrayList[x].ToString())
                            {
                                index = x;
                                break;
                            }
                        }
                        var othersfee = db.Randoms.Where(x => x.ID == 10).FirstOrDefault();
                        var latefee   = db.Randoms.Where(x => x.ID == 11).FirstOrDefault();
                        var fee       = db.Randoms.Where(x => x.ID == 8).FirstOrDefault();
                        var feearray  = fee.Text.Split(';');

                        var    feearray1 = feearray[index].ToString().Split(',');
                        string fees      = feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString() + "," + feearray1[0].ToString();


                        DateTime dob   = Convert.ToDateTime(DateofBirthPicker.Value);
                        DateTime admit = Convert.ToDateTime(Admitdatepicker.Value);

                        var i = db.StudentDatas.Where(c => c.ID == ModifyStudent.STUDENT_ID).FirstOrDefault();
                        var j = db.StudentProfiles.Where(d => d.ID == ModifyStudent.STUDENT_ID).FirstOrDefault();
                        var k = db.StudentFees.Where(c => c.ID == ModifyStudent.STUDENT_ID).FirstOrDefault();

                        i.StudentName  = txtstdname.Text;
                        i.FatherName   = txtathername.Text;
                        i.RegNo        = txtregno.Text;
                        i.MotherName   = txtmothername.Text;
                        i.DateOfBirth  = dob.ToString("dd/MM/yyyy");
                        i.PlaceOfBirth = txtplaceofbirth.Text;
                        i.Address      = txtaddress.Text;
                        i.NIC          = txtcnic.Text;
                        i.Gender       = ComboBoxGender.Text;
                        i.Religion     = txtreligion.Text;
                        i.Contact      = txtcontact.Text;
                        i.Class        = comboboxclass.Text;
                        i.Section      = comboboxsection.Text;
                        i.AdmitDate    = admit.ToString("dd/MM/yyyy");
                        i.Fees         = fees;

                        if (bimage != null)
                        {
                            j.Profile = bimage;
                        }

                        k.ExamFee = Convert.ToInt32(feearray1[1].ToString());

                        db.Entry(i).State = System.Data.Entity.EntityState.Modified;
                        db.Entry(j).State = System.Data.Entity.EntityState.Modified;
                        db.Entry(k).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxAdv.Show(ex.Message.ToString(), "Something Went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    db.Dispose();
                    MessageBox.Show("You have successfully updated a new record named as: " + txtstdname.Text, "New record added - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.None);
                    RESET = true;
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("All fields are mandatory!", "Error - Student Management Sytem", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        private void Restore()
        {
            System.Threading.Thread.Sleep(5000);


            DbEntities newdb = new DbEntities();

            DbEntityRefresh.Refresh(newdb);
            try
            {
                sourcepath = txtfilename.Text;
                File.Move(sourcepath, Path.ChangeExtension(sourcepath, ".db"));

                if (File.Exists(destpath + "/Database.db"))
                {
                    File.Delete(destpath + "/Database.db");
                }

                File.Copy(Path.GetDirectoryName(sourcepath) + "/Database.db", destpath + "/Database.db");

                File.Move(Path.GetDirectoryName(sourcepath) + "/Database.db", Path.ChangeExtension(Path.GetDirectoryName(sourcepath) + "/Database.db", ".backupsms"));

                var schoolname    = newdb.Randoms.Where(c => c.ID == 1).FirstOrDefault();
                var schooladdress = newdb.Randoms.Where(c => c.ID == 2).FirstOrDefault();
                var schoolcontact = newdb.Randoms.Where(c => c.ID == 3).FirstOrDefault();
                var schoolemail   = newdb.Randoms.Where(c => c.ID == 4).FirstOrDefault();
                var ownername     = newdb.Randoms.Where(c => c.ID == 5).FirstOrDefault();
                var softid        = newdb.Randoms.Where(c => c.ID == 18).FirstOrDefault();

                string fileName = Application.StartupPath + @"\bin\License.lic";


                // Check if file already exists. If yes, delete it.
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                // Create a new file
                using (StreamWriter sw = File.CreateText(fileName))
                {
                    sw.WriteLine("Owner Name:" + ownername.Text);
                    sw.WriteLine("School Name:" + schoolname.Text);
                    sw.WriteLine("School Address:" + schooladdress.Text);
                    sw.WriteLine("School Contact:" + schoolcontact.Text);
                    sw.WriteLine("School Email:" + schoolemail.Text);
                    sw.WriteLine("Installation Date:" + DateTime.Now.ToString("dd/MM/yyyy"));
                    sw.WriteLine("IsActivated:" + ClsTripleDES.Encrypt("False"));
                    string ency = DateTime.Now.ToString("dd/MM/yyyy") + "," + DateTime.Now.AddDays(5).ToString("dd/MM/yyyy") + "," + softid.Text + "," + ownername.Text + "," + schoolname.Text + "," + "True";
                    sw.WriteLine("Licensed Hash:" + ClsTripleDES.Encrypt(ency));
                }

                string[] lines = File.ReadAllLines(Application.StartupPath + @"\bin\User.Config");
                lines[0] = "Owner Name:" + txtowner.Text;
                lines[1] = "School Name:" + txtschoolname.Text;
                lines[2] = "FirstRun:" + "False";
                lines[3] = "DefaultPrinter:null";

                File.WriteAllLines(Application.StartupPath + @"\bin\User.Config", lines);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                newdb.Dispose();
            }
        }