protected void btnReNew_Click(object sender, EventArgs e) { //Get val form control string param_username = tbCuser.Text.Trim(); string param_old = tbCold.Text.Trim(); string param_new = tbCnew.Text.Trim(); string param_confirm = tbCcon.Text.Trim(); string param_password; string sql_chk = "SELECT * FROM [BESTBoQ].[dbo].[userinfo] WHERE [username] = '" + param_username + "' AND [password] = N'" + ClassConfig.CalculateMD5Hash(param_old + "AISNQM") + "' "; DataTable dt_chk = ClassConfig.GetDataSQL(sql_chk); if (dt_chk.Rows.Count > 0) { string user_id = dt_chk.Rows[0]["userid"].ToString(); if (param_new == param_confirm) { string sql_delete_flag = "DELETE [BESTBoQ].[dbo].[FlagNew] WHERE [userid] = '" + user_id + "'"; ClassConfig.GetDataSQL(sql_delete_flag); param_password = ClassConfig.CalculateMD5Hash(param_new + "AISNQM"); string sql_command = " UPDATE [BESTBoQ].[dbo].[userinfo] " + " SET [password] = '" + param_password + "' " + " WHERE [username] = N'" + param_username + "' AND [password] = N'" + ClassConfig.CalculateMD5Hash(tbCold.Text.Trim() + "AISNQM") + "' "; DataTable dt = ClassConfig.GetDataSQL(sql_command); Response.Redirect("Default?r=forgetComplete"); } } }
protected void btnLogin_Click(object sender, EventArgs e) { //Get val form control string param_username = tbLoginUsername.Text.Trim(); string param_password = ClassConfig.CalculateMD5Hash(tbLoginPassword.Text.Trim() + "AISNQM"); //Execute Command try { string sql_command = "SELECT [status1],[status2],[status3],[status4],[status5],[status6],[userid] FROM [BESTBoQ].[dbo].[userinfo] " + " WHERE [username] = '" + param_username + "' AND [password] = '" + param_password + "' "; DataTable dt = ClassConfig.GetDataSQL(sql_command); if (dt.Rows.Count < 1) { //No Data in userinfo Response.Redirect("Default?r=loginPermission"); //Response.Write("<script>alert('กรุณาลงทะเบียนก่อนเข้าใช้งาน');</script>"); } else { if (dt.Rows[0][0].ToString() != "true") { //Not Yet Approve Response.Redirect("Default?r=userPermission"); //Response.Write("<script>alert('username ของท่านยังไม่ได้รับการอนุมัติ กรุณาติดต่อผู้ดูแล');</script>"); } else { Session["Username"] = param_username; Session["UserID"] = dt.Rows[0][6].ToString(); Session.Timeout = 24 * 60; //log data to database string dqlLog = " INSERT INTO [BESTBoQ].[dbo].[Log_Usage] ( [user],[login_date] ) " + " VALUES(N'" + param_username + "', GETDATE())"; ClassConfig.GetDataSQL(dqlLog); //log data to database string sqlChk = "SELECT * FROM [BESTBoQ].[dbo].[FlagNew] WHERE [userid] = '" + Session["UserID"].ToString() + "'"; DataTable dtFlag = ClassConfig.GetDataSQL(sqlChk); if (dtFlag.Rows.Count > 0) { Response.Redirect("ChangePassword.aspx", false); } else { Response.Redirect("Home.aspx"); } } } } catch (Exception ex) { //SQL Error or Network Error Response.Write("<script>alert('ระบบมีปัญหา กรุณาติดต่อผู้ดูแล');</script>"); } }
protected void btnRegister_Click(object sender, EventArgs e) { //Check password == conform password if (tbPassword.Value.Trim() != tbRepassword.Value.Trim()) { Response.Write("<script>alert('Password <> Confirm Password');</script>"); } else { //Check Username ว่ามีแล้วหรือยังใน DB if (chkusername()) { //Get Val form control string param_username = tbUsername.Text.Trim(); string param_password = ClassConfig.CalculateMD5Hash(tbPassword.Value.Trim() + "AISNQM"); string param_type = rbType.SelectedValue.ToString().Trim(); string param_email = tbEmail.Text.Trim(); string param_mobile = tbMobile.Text.Trim(); string param_name = tbName.Text.Trim(); string param_company = tbCompany.Text.Trim(); string param_alias = tbAlias.Text.Trim(); string param_address = tbAddress.Text.Trim(); string param_id = tbID.Text.Trim(); string param_tax = tbTax.Text.Trim(); string param_nation = tbNation.Text.Trim(); string param_filename = string.Empty; //Debug Val form control //Response.Write("<script>alert('Username : "******"');</script>"); //Execute Command try { //if (FuLogoImageCompany.HasFile) //{ // try // { // string fileuploadDir = Server.MapPath("~/Images/Logo/" + param_username + "/"); // if (!System.IO.Directory.Exists(fileuploadDir)) // { // System.IO.Directory.CreateDirectory(fileuploadDir); // } // string filename = Path.GetFileName(FuLogoImageCompany.FileName); // FuLogoImageCompany.SaveAs(Server.MapPath("~/Images/Logo/" + param_username + "/") + filename); // param_filename = "Images/Logo/" + param_username + "/" + filename; // } // catch (Exception ex) // { // Response.Write("<script>alert('การอัพโหลดรูปภาพมีปัญหา กรุณาตรวจสอบไฟล์ภาพและเลือกภาพใหม่อีกครั้ง');</script>"); // } //} if (FuLogoImageCompany.HasFile) { try { string fn = System.IO.Path.GetFileName(FuLogoImageCompany.PostedFile.FileName); string fileuploadDir = Server.MapPath("~/Images/Logo/" + Session["Username"] + "/"); string fileuploadDirFilename = Server.MapPath("~/Images/Logo/" + Session["Username"] + "/" + fn); string fileExtention = FuLogoImageCompany.PostedFile.ContentType; int fileLenght = FuLogoImageCompany.PostedFile.ContentLength; param_filename = "Images/Logo/" + Session["Username"] + "/" + fn; if (fileExtention == "image/png" || fileExtention == "image/jpeg" || fileExtention == "image/x-png") { if (!System.IO.Directory.Exists(fileuploadDir)) { System.IO.Directory.CreateDirectory(fileuploadDir); } System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(FuLogoImageCompany.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpPostedImage, 60); //ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg); //System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality; //EncoderParameters myEncoderParameters = new EncoderParameters(1); //EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L); //myEncoderParameters.Param[0] = myEncoderParameter; objImage.Save(fileuploadDirFilename, ImageFormat.Jpeg); } else { Response.Write("<script>alert('กรุณาอัพโหลดได้เฉพาะไฟล์สกุล .jpg, .jpeg, .png เท่านั้น');</script>"); } } catch (Exception ex) { Response.Write(ex.Message.ToString()); Response.Write("<script>alert('การอัพโหลดรูปภาพมีปัญหา กรุณาตรวจสอบไฟล์ภาพและเลือกภาพใหม่อีกครั้ง');</script>"); } } string param_command = " EXEC [dbo].[set_Register_Logo] N'" + param_username + "',N'" + param_password + "',N'" + param_type + "',N'" + param_email + "',N'" + param_mobile + "',N'" + param_name + "',N'" + param_company + "',N'" + param_address + "',N'" + param_id + "',N'" + param_tax + "',N'" + param_alias + "',N'" + param_nation + "',N'" + param_filename + "' "; ClassConfig.GetDataSQL(param_command); Response.Redirect("Default?r=regisComplete"); //Response.Write("<script>alert('Register Success');</script>"); } catch (Exception) { Response.Write("<script>alert('Register Fail Please Contract Admin');</script>"); throw; } } else { Response.Write("<script>alert('มี Username นี้อยู่ในระบบแล้ว');</script>"); } } }