Exemplo n.º 1
0
 protected void btnUpload_Click(object sender, EventArgs e)
 {
     using (dbExtranetEntities db = new dbExtranetEntities())
     {
         using (var trans = db.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
         {
             try
             {
                 using (BinaryReader br = new BinaryReader(FileUpload11.PostedFile.InputStream))
                 {
                     byte[] bytes = br.ReadBytes((int)FileUpload11.PostedFile.InputStream.Length);
                     var bf= new Beg_Files
                     {
                         Name = Path.GetFileName(FileUpload11.PostedFile.FileName),
                         ContentType = "audio/mpeg3",
                         Play  = bytes,
                         BegAlphabetId = 1
                     };
                     db.Beg_Files.Add(bf);
                     db.SaveChanges();
                     trans.Commit();
                 }
                 //Response.Redirect(Request.Url.AbsoluteUri);
             }
             catch(Exception ex)
             {
                 trans.Rollback();
                 throw;
             }
         
         }
     }
     //using (BinaryReader br = new BinaryReader(FileUpload11.PostedFile.InputStream))
                 //{
                 //    byte[] bytes = br.ReadBytes((int)FileUpload11.PostedFile.InputStream.Length);
                 //    string strConnString = ConfigurationManager.ConnectionStrings["LearnData"].ConnectionString;
                 //    using (SqlConnection con = new SqlConnection(strConnString))
                 //    {
                 //        using (SqlCommand cmd = new SqlCommand())
                 //        {
                 //            cmd.CommandText = "insert into Beg_Files(Name, ContentType, Play) values (@Name, @ContentType, @Play)";
                 //            cmd.Parameters.AddWithValue("@Name", Path.GetFileName(FileUpload11.PostedFile.FileName));
                 //            cmd.Parameters.AddWithValue("@ContentType", "audio/mpeg3");
                 //            cmd.Parameters.AddWithValue("@Play", bytes);
                 //            cmd.Connection = con;
                 //            con.Open();
                 //            cmd.ExecuteNonQuery();
                 //            con.Close();
                 //        }
                 //    }
                 //}
                 //
             }
Exemplo n.º 2
0
    protected void btnSignup_Click(object sender, EventArgs e)
    {
        if (txtusername.Text != "" && txtPassword.Text != "" && txtConfirmPass.Text != "" && txtEmail.Text != "" && ddlPreferedLanguage.SelectedItem.Text!="Select" && 
            txtName.Text != "")
        {
            if (txtPassword.Text == txtConfirmPass.Text)
            {

                using (dbExtranetEntities db = new dbExtranetEntities())
                {
                    using (var trans = db.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        try
                        { 
                            var username = db.Users.Where(a=> a.Username == txtusername.Text).Select(x => x.Username).FirstOrDefault();
                            if (username == null)
                            {
                                var addUser = new User
                                {
                                    Username  = txtusername.Text,
                                    Password  = txtPassword.Text,
                                    Email = txtEmail.Text ,
                                    Name = txtName.Text,
                                    LanguagePrefered  = ddlPreferedLanguage.SelectedItem.Text,
                                   
                                };
                                db.Users.Add(addUser);
                            }
                            else
                            {
                                lblMsg.ForeColor = Color.Red;
                                lblMsg.Text = "Username Already Exists In Our Database";
                            }
                           
                            db.SaveChanges();
                            trans.Commit();
                            Response.Redirect("~/SignIn.aspx",false);

                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            throw;
                        }
                    }
                }
            
            //string cs = ConfigurationManager.ConnectionStrings["LearnData"].ConnectionString;
                //    using (SqlConnection con = new SqlConnection(cs))
                //    {

                //        SqlCommand cmduser =
                //            new SqlCommand("Select Username from Users where username ='******'", con);
                //    SqlDataAdapter sda = new SqlDataAdapter(cmduser);
                //    DataTable dt = new DataTable();
                //    sda.Fill(dt);
                //        if (dt.Rows.Count == 0)
                //        {

                //            SqlCommand cmd =
                //                new SqlCommand(
                //                    " Insert into Users values ('" + txtusername.Text + "','" + txtPassword.Text +
                //                    "', '" +
                //                    txtEmail.Text + "','" + txtName.Text + "' , '" + "U" + "')", con);
                //            con.Open();
                //            cmd.ExecuteNonQuery();
                //            lblMsg.ForeColor = Color.Green;
                //            lblMsg.Text = "Registration Successfull";
                //            Response.Redirect("~/SignIn.aspx");
                //            con.Close();
                //        }
                //        else
                //        {
                //        lblMsg.ForeColor = Color.Red;
                //        lblMsg.Text = "Username Already Exists In Our Database";
                //    }
                //}
            }
            else
            {
                lblMsg.ForeColor = Color.Red;
                lblMsg.Text = "Password Do Not Match";
            }
        }
        else
        {
            lblMsg.ForeColor=Color.Red;
            lblMsg.Text = "All Fields Are Required";

        }
    }
Exemplo n.º 3
0
    public static bool SendBacktoSameCourse(string testday, string username)
    {
        using (dbExtranetEntities db = new dbExtranetEntities())
        {
            using (var trans = db.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                try
                {
                    var removeusertest = db.Beg_UserTest.Where(x => x.Username == username && x.Day == testday).ToList();
                    db.Beg_UserTest.RemoveRange(removeusertest);
                    db.SaveChanges();
                    trans.Commit();

                    return false;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }
            }
        }

    }
Exemplo n.º 4
0
    public static void AnswerGiven(int testid, string username, int begid)
    {
        using (dbExtranetEntities db = new dbExtranetEntities())
        {
            using (var trans = db.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                try
                {
                    var getquestioninfo = db.Beg_Test.SingleOrDefault(x => x.Id == testid);
                    var getAnstext = db.Beg_Alphabet.SingleOrDefault(x => x.Id == begid);
                    var testgiven = new Beg_UserTest()
                    {
                        BegAlphabetId = getquestioninfo.BegAlphabetId,
                        Username = username,
                        Course = testid,
                        Day = getquestioninfo.Day,
                        Question = getquestioninfo.Question,
                        QuestionNumber = getquestioninfo.QuestionNumber,
                        Answer = getAnstext.CapitalLetter

                    };
                    db.Beg_UserTest.Add(testgiven);
                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }

            }
        }
    }