コード例 #1
0
 protected void btnchangepass_Click(object sender, EventArgs e)
 {
     try
     {
         int     studentId = 1;
         DataRow dr        = StudentMst.GetDataByKey(studentId);
         if (dr != null && dr["Pass"].ToString() == txtcurrent.Text)
         {
             StudentMst studentObj = new StudentMst();
             studentObj.Name    = dr["Name"].ToString();
             studentObj.StdName = dr["StdName"].ToString();
             studentObj.DivName = dr["DivName"].ToString();
             studentObj.DOB     = dr["DOB"].ToString();
             studentObj.EDate   = dr["DOB"].ToString() != "" ? (DateTime?)Convert.ToDateTime(dr["DOB"].ToString()) : null;
             studentObj.Email   = dr["Email"].ToString();
             studentObj.Mobile  = dr["Mobile"].ToString();
             studentObj.RollNo  = dr["RollNo"].ToString();
             studentObj.Pincode = dr["Pincode"].ToString();
             studentObj.Uname   = dr["Uname"].ToString();
             studentObj.Pass    = txtnewpass.Text;
             studentObj.City    = dr["City"].ToString();
             studentObj.Add     = dr["Add"].ToString();
             studentObj.Image   = dr["Image"].ToString();
             studentObj.UpdateDataByKey();
             lbl.Text = "Password Changed";
         }
         else
         {
             lbl.Text = "Invalid Current Password";
         }
     }
     catch (Exception ex)
     {
         lbl.Text = "update password fail";
     }
 }
コード例 #2
0
        protected void btnstuadd_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable studentDT = StudentMst.GetAllActiveData();

                if (string.IsNullOrEmpty(txtroll.Text))
                {
                    lblmsg.Text = "Roll can't be null !!";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
                    return;
                }

                if (string.IsNullOrEmpty(txtname.Text) || string.IsNullOrEmpty(txtemail.Text))
                {
                    lblmsg.Text = "Name and email can't be null !!";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
                    return;
                }

                if (string.IsNullOrEmpty(txtuname.Text) || string.IsNullOrEmpty(txtpass.Text))
                {
                    lblmsg.Text = "user name and and password can't be null !!";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
                    return;
                }

                else
                {
                    DateTime   bdate  = Convert.ToDateTime(drpdd.SelectedItem.Text + " " + drpmm.SelectedItem.Text + " " + drpyyyy.SelectedItem.Text);
                    StudentMst stdobj = new StudentMst();
                    stdobj.Name = txtname.Text;
                    // stdobj.StdName = lblstd.Text;
                    // stdobj.DivName = drpdiv.SelectedItem.Text;
                    stdobj.DOB         = bdate.GetDateTimeFormats()[8].ToString();
                    stdobj.EDate       = DateTime.Now;
                    stdobj.Email       = txtemail.Text;
                    stdobj.Mobile      = txtmobi.Text;
                    stdobj.RollNo      = txtroll.Text;
                    stdobj.Pincode     = txtpin.Text;
                    stdobj.Uname       = txtuname.Text;
                    stdobj.Pass        = txtpass.Text;
                    stdobj.City        = txtcity.Text;
                    stdobj.MachineCode = txt_MachineId.Text != "" ? (int?)Convert.ToInt32(txt_MachineId.Text): null;
                    if (drpdiv.SelectedIndex > 0)
                    {
                        stdobj.DivName = drpdiv.SelectedItem.Text;
                        stdobj.DivId   = int.Parse(drpstd.SelectedValue);
                    }

                    if (drpstd.SelectedIndex > 0)
                    {
                        stdobj.StdName = drpdiv.SelectedItem.Text;
                        stdobj.StdId   = int.Parse(drpstd.SelectedValue);
                    }

                    if (!string.IsNullOrEmpty(FileUpload1.FileName))
                    {
                        FileUpload1.SaveAs(Server.MapPath("~/Studentimg/" + FileUpload1.FileName));
                        stdobj.Image = "~/Studentimg/" + FileUpload1.FileName;
                    }

                    if (StudentId != null)
                    {
                        stdobj.SID = int.Parse(StudentId.ToString());
                        if (stdobj.UpdateDataByKey())
                        {
                            lblmsg.Text = "Record updated Successfully";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
                            resret();
                            Response.Redirect("StudentReport.aspx", false);
                        }
                    }
                    else
                    {
                        if (studentDT != null && studentDT.Rows.Count == 1)
                        {
                            lblmsg.Text = "UserName alredy exists !!";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
                        }

                        stdobj.SID = StudentMst.GetNewSID();
                        stdobj.Insert();
                        lblmsg.Text = "Record Added Successfully";
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
                        resret();
                    }
                }
            }
            catch (Exception ex)
            {
                lblmsg.Text = "Fail to Add record";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "fadeLabelOut()", true);
            }
        }