Exemple #1
0
        public string UpdateStudentRecord(tblStudentRecord model)
        {
            string result = string.Empty;

            try
            {
                int count = _db.tblStudentRecords.Where(a => a.ID != model.ID && a.RollNo == model.RollNo).Count();
                if (count > 0)
                {
                    result = "-1";
                    return(result);
                }

                tblStudentRecord data = _db.tblStudentRecords.Where(a => a.ID == model.ID).FirstOrDefault();
                if (data != null)
                {
                    data.Address         = model.Address;
                    data.City            = model.City;
                    data.Email           = model.Email;
                    data.LastUpdatedDate = model.LastUpdatedDate;
                    data.Name            = model.Name;
                    data.Phone           = model.Phone;
                    data.RollNo          = model.RollNo;
                    data.State           = model.State;
                    data.ClassId         = model.ClassId;
                    _db.SaveChanges();
                    result = "1";
                }
            }
            catch (Exception a1)
            {
            }
            return(result);
        }
        public tblStudentRecord GetTblStudentRecordById(int id)
        {
            tblStudentRecord tblStudentRecord = new tblStudentRecord();

            tblStudentRecord = _db.tblStudentRecords.Where(a => a.Id == id).FirstOrDefault();
            return(tblStudentRecord);
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind_course();
                bind_year();

                if (Request.QueryString["ID"] != null)
                {
                    hddn_studentId.Value       = Request.QueryString["ID"].ToString();
                    btn_submit.Text            = "Update";
                    btn_submit.CommandName     = "update";
                    btn_submit.CommandArgument = hddn_studentId.Value;

                    tblStudentRecord data = mm.GetTblStudentRecordById(Convert.ToInt32(hddn_studentId.Value));
                    if (data != null)
                    {
                        txt_address.Text         = data.Address;
                        txt_batch.Text           = data.Batch;
                        txt_city.Text            = data.City;
                        txt_email.Text           = data.EmailId;
                        txt_fatherName.Text      = data.FatherName;
                        txt_motherName.Text      = data.MotherName;
                        txt_name.Text            = data.Name;
                        txt_phoneNumber.Text     = data.PhoneNumber;
                        txt_pincode.Text         = data.Pincode;
                        txt_state.Text           = data.State;
                        ddl_course.SelectedValue = data.CourseId.ToString();
                        ddl_year.SelectedValue   = data.YearId.ToString();
                    }
                }
            }
        }
Exemple #4
0
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            tblStudentRecord data = new tblStudentRecord();

            data.Address         = txt_address.Text.Trim();
            data.Batch           = txt_batch.Text.Trim();
            data.City            = txt_city.Text.Trim();
            data.CourseId        = Convert.ToInt32(ddl_course.SelectedValue);
            data.EmailId         = txt_email.Text.Trim();
            data.FatherName      = txt_fatherName.Text.Trim();
            data.LastUpdatedDate = DateTime.UtcNow;
            data.MotherName      = txt_motherName.Text.Trim();
            data.Name            = txt_name.Text.Trim();
            data.PhoneNumber     = txt_phoneNumber.Text.Trim();
            data.Pincode         = txt_pincode.Text.Trim();
            data.State           = txt_state.Text.Trim();
            data.YearId          = Convert.ToInt32(ddl_year.SelectedValue);
            if (btn_submit.CommandName == "add")
            {
                data.CreatedDate = DateTime.UtcNow;
                int id = mm.AddStudentRecord(data);
                if (id > 0)
                {
                    clear();
                    Page.RegisterStartupScript("puneet", "<script>opendialog(1,\"Your profile added successfully\");window.setTimeout(function(){window.location.href = \"/viewstudentrecords\"}, 3000);</script>");
                }
                else if (id == -1)
                {
                    Page.RegisterStartupScript("puneet", "<script>opendialog(2,\"Email or Phonenumber is already exists. Please try another\");</script>");
                }
                else
                {
                    Page.RegisterStartupScript("puneet", "<script>opendialog(2,\"Error! in adding your profile\");</script>");
                }
            }
            else if (btn_submit.CommandName == "update")
            {
                data.Id = Convert.ToInt32(btn_submit.CommandArgument);
                string result = mm.updateStudentRecord(data);
                if (result == "1")
                {
                    clear();
                    Page.RegisterStartupScript("puneet", "<script>opendialog(1,\"Your profile updated successfully\");window.setTimeout(function(){window.location.href = \"/viewstudentrecords\"}, 3000);</script>");
                }
                else if (result == "-1")
                {
                    Page.RegisterStartupScript("puneet", "<script>opendialog(2,\"Email or Phonenumber is already exists. Please try another\");</script>");
                }
                else
                {
                    Page.RegisterStartupScript("puneet", "<script>opendialog(2,\"Error! in updating your profile\");</script>");
                }
            }
        }
        public bool DeletetblStudentRecord(int id)
        {
            bool             status           = false;
            tblStudentRecord tblStudentRecord = _db.tblStudentRecords.Where(a => a.Id == id).FirstOrDefault();

            if (tblStudentRecord != null)
            {
                _db.tblStudentRecords.Remove(tblStudentRecord);
                _db.SaveChanges();
                status = true;
            }
            return(status);
        }
Exemple #6
0
        //Gridview Eventfire to show full record of student.
        protected void grd_ShowView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = 0;

            Int32.TryParse(e.CommandArgument.ToString(), out id);
            if (e.CommandName == "edt")
            {
                btn_save.CommandArgument = id.ToString();
                btn_save.CommandName     = "update";
                btn_save.Text            = "Update";
                tblStudentRecord data = mm.GetStudentRecordByID(id);
                if (data != null)
                {
                    pnl_saveData.Visible = true;
                    pnl_showGrid.Visible = false;

                    txt_address.Text = data.Address;
                    txt_city.Text    = data.City;
                    txt_email.Text   = data.Email;
                    txt_name.Text    = data.Name;
                    txt_phone.Text   = data.Phone;
                    txt_rollNo.Text  = data.RollNo;
                    txt_state.Text   = data.State;
                    if (data.ClassId > 0)
                    {
                        ddl_class.SelectedValue = data.ClassId.ToString();
                        div_teacher.Style.Add("display", "block");
                        ddl_teacher.DataSource     = mm.GetTeacherByID(data.ClassId.Value);
                        ddl_teacher.DataTextField  = "TeacherName";
                        ddl_teacher.DataValueField = "Id";
                        ddl_teacher.DataBind();
                        ddl_teacher.Enabled = false;
                    }
                }
            }
            //Create method to delete the record.
            else if (e.CommandName == "dlt")
            {
                bool status = mm.DeleteStudentRecordById(id);
                if (status == true)
                {
                    bind_showStudentRecords();
                }
            }
        }
Exemple #7
0
        //Create function to delete record from database.
        public bool DeleteStudentRecordById(int id)
        {
            bool status = false;

            try
            {
                tblStudentRecord tblStudentRecord = _db.tblStudentRecords.Where(a => a.ID == id).FirstOrDefault();
                if (tblStudentRecord != null)
                {
                    _db.tblStudentRecords.Remove(tblStudentRecord);
                    _db.SaveChanges();
                    status = true;
                }
            }
            catch (Exception a1)
            { }
            return(status);
        }
        public string updateStudentRecord(tblStudentRecord model)
        {
            string           result           = "0";
            tblStudentRecord tblStudentRecord = new tblStudentRecord();

            try
            {
                int count = _db.tblStudentRecords.Where(a => a.Id != model.Id && (a.EmailId == model.EmailId || a.PhoneNumber == model.PhoneNumber)).Count();
                if (count == 0)
                {
                    tblStudentRecord = _db.tblStudentRecords.Where(a => a.Id == model.Id).FirstOrDefault();
                    if (tblStudentRecord != null)
                    {
                        tblStudentRecord.Address         = model.Address;
                        tblStudentRecord.Batch           = model.Batch;
                        tblStudentRecord.City            = model.City;
                        tblStudentRecord.CourseId        = model.CourseId;
                        tblStudentRecord.EmailId         = model.EmailId;
                        tblStudentRecord.FatherName      = model.FatherName;
                        tblStudentRecord.LastUpdatedDate = model.LastUpdatedDate;
                        tblStudentRecord.MotherName      = model.MotherName;
                        tblStudentRecord.YearId          = model.YearId;
                        tblStudentRecord.Name            = model.Name;
                        tblStudentRecord.PhoneNumber     = model.PhoneNumber;
                        tblStudentRecord.Pincode         = model.Pincode;
                        tblStudentRecord.State           = model.State;
                        _db.SaveChanges();
                        result = "1";
                    }
                }
                else
                {
                    result = "-1";
                }
            }
            catch (Exception qa)
            {
            }

            return(result);
        }
        public int AddStudentRecord(tblStudentRecord model)
        {
            int id = 0;

            try
            {
                int count = _db.tblStudentRecords.Where(a => a.EmailId == model.EmailId || a.PhoneNumber == model.PhoneNumber).Count();
                if (count == 0)
                {
                    _db.tblStudentRecords.Add(model);
                    _db.SaveChanges();
                    id = model.Id;
                }
                else
                {
                    id = -1;
                }
            }
            catch (Exception a1)
            { }
            return(id);
        }
Exemple #10
0
        //Create function to save new record into database.
        public int SaveStudentRecords(tblStudentRecord model)
        {
            int id = 0;

            try
            {
                int Count = _db.tblStudentRecords.Where(a => a.Name == model.Name && a.RollNo == model.RollNo).Count();
                if (Count == 0)
                {
                    _db.tblStudentRecords.Add(model);
                    _db.SaveChanges();
                    id = model.ID;
                }
                else
                {
                    id = -1;
                }
            }
            catch (Exception a1)
            {
            }
            return(id);
        }
Exemple #11
0
        public tblStudentRecord GetStudentRecordByID(int id)
        {
            tblStudentRecord tblStudentRecord = _db.tblStudentRecords.Where(a => a.ID == id).FirstOrDefault();

            return(tblStudentRecord);
        }
Exemple #12
0
        //Create the ClickEvent of Save Button to Save the New Data.
        protected void btn_save_Click(object sender, EventArgs e)
        {
            lbl_result.Text = string.Empty;

            tblStudentRecord tblStudentRecord = new tblStudentRecord();

            tblStudentRecord.Name            = txt_name.Text.Trim();
            tblStudentRecord.RollNo          = txt_rollNo.Text.Trim();
            tblStudentRecord.Address         = txt_address.Text.Trim();
            tblStudentRecord.City            = txt_city.Text.Trim();
            tblStudentRecord.Email           = txt_email.Text.Trim();
            tblStudentRecord.IsActive        = true;
            tblStudentRecord.Phone           = txt_phone.Text.Trim();
            tblStudentRecord.State           = txt_state.Text.Trim();
            tblStudentRecord.LastUpdatedDate = DateTime.UtcNow;
            tblStudentRecord.ClassId         = Convert.ToInt32(ddl_class.SelectedValue);
            if (btn_save.CommandName == "add")
            {
                tblStudentRecord.CreatedDate = DateTime.UtcNow;
                int id = mm.SaveStudentRecords(tblStudentRecord);
                if (id > 0)
                {
                    Clear();
                    pnl_saveData.Visible = false;
                    pnl_showGrid.Visible = true;
                    Page.Response.Redirect(Page.Request.Url.ToString(), true);
                    // bind_showStudentRecords();
                }
                else if (id == -1)
                {
                    lbl_result.Text      = "Student Detail Already Exist";
                    lbl_result.ForeColor = System.Drawing.Color.Red;
                    lbl_result.Focus();
                }
                else
                {
                    lbl_result.Text      = "Error in adding student detail";
                    lbl_result.ForeColor = System.Drawing.Color.Red;
                    lbl_result.Focus();
                }
            }
            // Create the ClickEvent of Update Button to Update the Existing Records.
            else if (btn_save.CommandName == "update")
            {
                tblStudentRecord.ID = Convert.ToInt32(btn_save.CommandArgument);
                string result = mm.UpdateStudentRecord(tblStudentRecord);
                if (result == "1")
                {
                    Clear();
                    pnl_saveData.Visible = false;
                    pnl_showGrid.Visible = true;
                    bind_showStudentRecords();
                }
                else if (result == "-1")
                {
                    lbl_result.Text      = "This Roll No is already exist";
                    lbl_result.ForeColor = System.Drawing.Color.Red;
                    lbl_result.Focus();
                }
            }
        }