private async void BtnSave_Click(object sender, RoutedEventArgs e) { dhWait.IsOpen = true; KiaGallery.Common.Response result = await SaveAsync(); dhWait.IsOpen = false; }
public FrmMain() { // Common.Cache.CurrentUser = new Common.Model.User() { token = "0a22f4e9-af61-446f-8fc8-7f7f8ca821ed", lastName = "Manny" }; InitializeComponent(); System.Collections.Specialized.NameValueCollection col = new System.Collections.Specialized.NameValueCollection(); col.Add("token", Common.Cache.CurrentUser.token); KiaGallery.Common.Response rep = Common.Services.CallService(Common.Services.ServiceType.GetBaseData, col); }
private Task <KiaGallery.Common.Response> Login(string UserName, string Password) { return(Task.Run(() => { System.Collections.Specialized.NameValueCollection param = new System.Collections.Specialized.NameValueCollection { ["username"] = UserName, ["password"] = Password }; KiaGallery.Common.Response Response = Common.Services.CallService(Common.Services.ServiceType.Login, param); return Response; })); }
public static KiaGallery.Common.Response CallService(ServiceType serviceType, NameValueCollection Params) { string Prefix = ""; switch (serviceType) { case ServiceType.Login: Prefix = "account"; break; case ServiceType.GetBaseData: Prefix = "Home"; break; case ServiceType.Load: case ServiceType.Save: case ServiceType.SaveDraft: Prefix = "DailyReportt"; break; default: break; } WebClient req = new WebClient(); using (var wb = new WebClient()) { string URL = "http:" + $"//185.129.169.121:2007//api/dailyReportFinancial/{Prefix}/{serviceType.ToString()}"; try { byte[] responseByte = wb.UploadValues(URL, "POST", Params); string ResString = System.Text.UTF8Encoding.UTF8.GetString(responseByte); KiaGallery.Common.Response Response = Newtonsoft.Json.JsonConvert.DeserializeObject <KiaGallery.Common.Response>(ResString); return(Response); } catch (WebException wex) { // "Unable to connect to the remote server" return(null); } catch (Exception ex) { return(null); } } }
private Task <bool> LoadBaseData() { return(Task.Run(() => { KiaGallery.Common.Response response = Common.Services.CallService(Common.Services.ServiceType.GetBaseData, new System.Collections.Specialized.NameValueCollection() { ["token"] = Common.Cache.CurrentUser?.token ?? "f7bdb768-c11f-4443-b8d8-ba7d90f5e93e" /* Common.Cache.CurrentUser.token */ }); if (response?.status == 200) { Common.Model.Invoice invoice = Newtonsoft.Json.JsonConvert.DeserializeObject <Common.Model.Invoice>(response.data.ToString()); Common.Cache.CalendarDays = invoice.calendarList; Common.Cache.CurrencyList = invoice.currencyList; Common.Cache.BankList = invoice.bankList; return true; } else { return false; } })); //if (Common.Cache.BankList == null || Common.Cache.BankList?.Length == 0) //{ // Common.Cache.BankList = new Common.Model.Banklist[] { // new Common.Model.Banklist() { id = 1, order = 2, name = "بانک ملت" }, // new Common.Model.Banklist() { id = 2, order = 1, name = "بانک صادرات" }, // new Common.Model.Banklist() { id = 3, order = 3, name = "بانک پاسارکاد" } // }; //} //if (Common.Cache.CurrencyList == null || Common.Cache.CurrencyList?.Length == 0) //{ // Common.Cache.CurrencyList = new Common.Model.Currencylist[] { // new Common.Model.Currencylist() { id = 1, name = "دلار", order = 2 }, // new Common.Model.Currencylist() { id = 2, name = "یورو", order = 1 } , // new Common.Model.Currencylist() { id = 3, name = "لیر ترکیه", order = 3 } }; //} }
private Task <Web.Areas.DailyReportFinancial.Models.SaveDailyReportViewModel> LoadData(string Date) { return(Task.Run(() => { System.Collections.Specialized.NameValueCollection param = new System.Collections.Specialized.NameValueCollection { ["date"] = CalendarData.date, ["token"] = Common.Cache.CurrentUser.token }; KiaGallery.Common.Response response = Common.Services.CallService(Common.Services.ServiceType.Load, param); if (response.status == 200) { Web.Areas.DailyReportFinancial.Models.SaveDailyReportViewModel viewModel = Newtonsoft.Json.JsonConvert.DeserializeObject <Web.Areas.DailyReportFinancial.Models.SaveDailyReportViewModel>(response.data.ToString()); if (viewModel != null) { return viewModel; } } return null; })); }
private async void BtnEnter_Click(object sender, RoutedEventArgs e) { //KiaGallery.Common.Response response = await Login(TxtUserName.Text, TxtPassword.Password); if (TxtUserName.Text == "" || TxtPassword.Password == "") { MainSnackbar.MessageQueue.Enqueue("نام کاربری و گذرواژه را وارد کنید."); return; } dhWait.IsOpen = true; KiaGallery.Common.Response response = await Login(TxtUserName.Text, TxtPassword.Password); if (response.status == 200) { try { Common.Cache.CurrentUser = Newtonsoft.Json.JsonConvert.DeserializeObject <Common.Model.User>(response.data.ToString()); } catch (Exception) { MainSnackbar.MessageQueue.Enqueue("خطا در پردازش کاربر. به مدیر سیستم گزارش دهید."); } new FrmMain().Show(); Close(); } else { MainSnackbar.MessageQueue.Enqueue(response.message); } dhWait.IsOpen = false; //Task.Factory.StartNew(() => Login(TxtUserName.Text, TxtPassword.Password)); }