using System; using CoreSavingLibrary; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using CoreSavingLibrary.WcfNAdmin; using DataLibrary; using Sybase.DataWindow; using System.Web.Services.Protocols; using EncryptDecryptEngine; using System.Security.Cryptography; namespace Saving.Applications.admin { public partial class w_sheet_ad_edituserinfo : PageWebSheet, WebSheet { protected String jsSearch; protected String jsresetpass; protected String NoUserName; protected String jsDescription; Sdt dt = new Sdt(); public void InitJsPostBack() { jsSearch = WebUtil.JsPostBack(this, "jsSearch"); jsresetpass = WebUtil.JsPostBack(this, "jsresetpass"); NoUserName = WebUtil.JsPostBack(this, "NoUserName"); jsDescription = WebUtil.JsPostBack(this, "jsDescription"); } public void WebSheetLoadBegin() { if (!IsPostBack) { DwUserName.InsertRow(0); } else { this.RestoreContextDw(DwUserName); } } public void CheckJsPostBack(string eventArg) { if (eventArg == "jsSearch") { JsSearch(); } else if (eventArg == "jsresetpass") { Jsresetpass(); } else if (eventArg == "NoUserName") { NoHaveUserName(); } else if (eventArg == "jsDescription") { DescriptionCheck(); } } public void DescriptionCheck() { HdCkDes.Value = "1"; string user_n = DwUserName.GetItemString(1, "user_name"); string des = DwUserName.GetItemString(1, "full_name"); string sqlck = "select full_name from amsecusers where full_name ='" + des + "' and user_name <>'" + user_n + "'"; Sdt ckdes = WebUtil.QuerySdt(sqlck); if (ckdes.Next()) { LtServerMessage.Text = WebUtil.WarningMessage("ชื่อนี้มีอยู่แล้วในระบบ กรุณากรอกชื่อใหม่"); HdCkDes.Value = "0"; } } public void NoHaveUserName() { LtServerMessage.Text = WebUtil.ErrorMessage("กรุณาเลือกรหัสผู้ใช้"); } public void Jsresetpass() { //n_adminClient adminService = wcf.NAdmin; int result = 0; string user_name = DwUserName.GetItemString(1,"user_name"); string passEncrypt = Encryption.UserPassword("1234"); try { //result = adminService.of_resetuserpassword(state.SsWsPass, user_name); String sql = @"update amsecusers set password = {0} where user_name = {1} and coop_id='" + state.SsCoopId + "'"; sql = WebUtil.SQLFormat(sql, passEncrypt , user_name); Sdt dt = WebUtil.QuerySdt(sql); LtServerMessage.Text = WebUtil.CompleteMessage("รีเซต รหัสผ่านสำเร็จ"); } catch(Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } public void JsSearch() { string user_name = DwUserName.GetItemString(1,"user_name"); DwUtil.RetrieveDataWindow(DwUserName, "ad_user.pbl", null,user_name,state.SsCoopId); try { string a = DwUserName.GetItemString(1, "user_name"); // n_adminClient adminService = wcf.NAdmin; //resultpass = adminService.of_decodestring(state.SsWsPass, DwUserName.GetItemString(1,"password")); // DwUserName.SetItemString(1, "password", passDecryption); } catch { DwUserName.InsertRow(0); LtServerMessage.Text = WebUtil.ErrorMessage("ไม่พบข้อมูลผู้ใช้งาน"); } } public static String PassphraseBase64 { get { return "1627384950"; } } public String DecryptStrBase64(String str_message) { byte[] Results; System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding(); MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider(); byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(PassphraseBase64)); TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider(); TDESAlgorithm.Key = TDESKey; TDESAlgorithm.Mode = CipherMode.ECB; TDESAlgorithm.Padding = PaddingMode.PKCS7; byte[] DataToDecrypt = Convert.FromBase64String(str_message); try { ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor(); Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length); } finally { TDESAlgorithm.Clear(); HashProvider.Clear(); } return UTF8.GetString(Results); } public void SaveWebSheet() { n_adminClient adminService = wcf.NAdmin; string user_name = DwUserName.GetItemString(1,"user_name"); string full_name = DwUserName.GetItemString(1, "full_name"); int result=0; try { result = adminService.of_existinguser(state.SsWsPass, user_name, full_name); result = adminService.of_saveuserpassword(state.SsWsPass, user_name, DwUserName.GetItemString(1, "password")); } catch (Exception e) { LtServerMessage.Text = WebUtil.ErrorMessage(e); } if (result == 1 && HdCkDes.Value != "0") { String d_um_user_xml = DwUserName.Describe("Datawindow.data.XML"); try { DwUtil.UpdateDataWindow(DwUserName, "ad_user.pbl", "amsecusers"); LtServerMessage.Text = WebUtil.CompleteMessage("บันทึกสำเร็จ"); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } else { LtServerMessage.Text = WebUtil.ErrorMessage("ไม่พบผู้ใช้ในระบบ หรือ ชื่อผู้ใช้ซ้ำ"); } } public void WebSheetLoadEnd() { DwUtil.RetrieveDDDW(DwUserName, "apvlevel_id", "ad_user.pbl", null); DwUserName.SaveDataCache(); } } }