/// <summary> /// /// </summary> /// <param name="mData"></param> /// <returns>-1: false; 0: success; 1: Can't connect DB; 2: Can't sendmail</returns> public int ReplySupportRequest(UserSupport_Model mData) { int result = -1; try { //Ghi DB voi thong tin username if (DBHandler.updateDataBase(ref conn, "`order_user_support`", "`isreplied`=" + true.ToString() + ",`repliedsubject`='" + mData.repliedsubject + "',`repliedmessage`='" + mData.repliedmessage + "'", "`id`= " + mData.id)) { //Gui mai : SMPTGMail mail = new SMPTGMail(AppConfig.UserGmailSupport, AppConfig.PasswordGmailSupport); bool sendmailSuccess = false; for (int i = 0; i < 5; i++) { if (mail.SendMailOnlyOne(mData.mail, mData.repliedsubject, mData.repliedmessage.Replace("\n", "<br/>"))) { sendmailSuccess = true; break; } } result = (sendmailSuccess) ? 0 : 2; if (result == 2) { DBHandler.updateDataBase(ref conn, "`order_user_support`", "`isreplied`=" + false.ToString() + ",`repliedsubject`='',`repliedmessage`=''", "`id`= " + mData.id); } } else { result = 1; } } catch (Exception ex) { LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message); } return(result); }
/// <summary> /// Add User /// </summary> /// <param name="UserName">User name need add</param> /// <returns>0: success; -1: Unknown; 1: Can't not DB; 2: Can not send mail; 3: User đã được sử dụng; 4: Dinh dang mail khong dung</returns> public int AddUser(string UserName) { int result = -1; try { System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); bool check = regex.IsMatch(UserName); if (check == false) { result = 4; return(result); } bool IsHave = false; // Kiểm tra username có được sử dụng hay chưa using (DataTable dt = DBHandler.selectDataBase(ref conn, "`order_user`", "*", "`username` = '" + UserName + "'")) { if (dt.Rows.Count > 0) { IsHave = true; } } if (IsHave) { result = 3; } else { //Ghi DB voi thong tin username if (DBHandler.insertDataBase(ref conn, "`order_user`", "(`username`,`usernamemd5`,`email`)", "('" + UserName + "','" + Functions.GetMD5(UserName) + "','" + UserName + "')")) { //Gui mai : SMPTGMail mail = new SMPTGMail(AppConfig.UserGmailNoReply, AppConfig.PasswordGmailNoReply); bool sendmailSuccess = false; for (int i = 0; i < 5; i++) { if (mail.SendMailOnlyOne(UserName, getSubject(), getContent(UserName))) { sendmailSuccess = true; break; } } result = (sendmailSuccess) ? 0 : 2; if (result == 2) { DBHandler.deleteDataBase(ref conn, "`order_user`", "`username` = '" + UserName + "'"); } } else { result = 1; } } } catch (Exception ex) { LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message); } return(result); }