private async void Grid_KeyDown(object sender, KeyRoutedEventArgs e) { if (IsEnterKeyDown()) { ProgRing.IsActive = true; SaveConStr(); //Flag should be true if successful connect try { var tempFlag = await ConnHolder.CheckConAsync(); if (tempFlag) { SuccessBlock.Text = "Successful"; } else { SuccessBlock.Text = "Failed"; } ProgRing.IsActive = false; SuccessBlock.Visibility = Visibility.Visible; } catch (Exception) { throw; } } }
private async void DeleteBtn_Click(object sender, RoutedEventArgs e) { var item = (Model)TestDataGrid.SelectedItem; var Query = $"Delete from Merc_xs where S.CodM={item.CodeFil} and S.CodM={item.CodePred}S"; await ConnHolder.NonQueryAsyncConnect(Query); }
private async void SaveChanges_Click(object sender, RoutedEventArgs e) { foreach (var item in Info) { var Query = $"Update Merc_xs set Name=\'{item.NameOfPlace}\', Login = \'{item.APILogin}\', Passw = \'{item.APIPass}\', GUID = \'{item.CompanyGuid}\', GUIDP = \'{item.PlaceGuid}\', Initiator = \'{item.User}\', APIKey = \'{item.APIKey}\' where CodM= {item.CodeFil} and CodB= {item.CodePred}"; await ConnHolder.NonQueryAsyncConnect(Query); } }
public static async Task <ObservableCollection <Model> > GetProductsAsync() { var connectionString = ConnHolder.GetConnStr(); const string GetProductsQuery = "Select S.CodM,M.Master,S.CodB,K.Title,S.Login,S.Passw,S.GUID,S.GUIDP,S.APIKey,S.AppID,S.Initiator,S.Name" + " From Merc_xs S,Master M, Skls K" + " Where S.CodM = M.CodM and S.CodB = K.Skl and S.Login <> '' and S.Passw <> '' and S.GUID <> '' and S.GUIDP <> '' and S.APIKey <> ''" + " Order by M.Master,K.Title"; var products = new ObservableCollection <Model>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); if (conn.State == ConnectionState.Open) { using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = GetProductsQuery; using (SqlDataReader reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var product = new Model(); product.CodeFil = reader.GetInt16(0); product.Master = SafeGetString(reader, 1); product.CodePred = reader.GetInt16(2); product.Title = SafeGetString(reader, 3); product.APILogin = SafeGetString(reader, 4); product.APIPass = SafeGetString(reader, 5); product.CompanyGuid = SafeGetString(reader, 6); product.PlaceGuid = SafeGetString(reader, 7); product.APIKey = SafeGetString(reader, 8); product.AppId = SafeGetString(reader, 9); product.User = SafeGetString(reader, 10); product.NameOfPlace = SafeGetString(reader, 11); products.Add(product); } } } } } return(products); } catch (Exception eSql) { Debug.WriteLine("Exception: " + eSql.Message); } return(null); }
private async void TestDataGrid_RowEditEnding(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridRowEditEndingEventArgs e) { if (e.EditAction == DataGridEditAction.Commit) { Model item = e.Row.DataContext as Model; var Query = $"Update Merc_xs set Name=\'{item.NameOfPlace}\', Login = \'{item.APILogin}\', Passw = \'{item.APIPass}\', GUID = \'{item.CompanyGuid}\', GUIDP = \'{item.PlaceGuid}\', Initiator = \'{item.User}\', APIKey = \'{item.APIKey}\' where CodM= {item.CodeFil} and CodB= {item.CodePred}"; await ConnHolder.NonQueryAsyncConnect(Query); //Debug.WriteLine(item.NameOfPlace); } }
public static async Task <class1.Envelope> GetXML(Model selectedOne, ObservableCollection <Model> Info) { var response = await HttpRest.InfoPostAsync(IenumerationPaths.PostFirstTime, selectedOne); var filledModel = XmlParser.Desirialize(response); var xml = new class1.Envelope(); //string text = "No Data"; if (filledModel.Body.submitApplicationResponse != null) { if (filledModel.Body.submitApplicationResponse.application.status == "ACCEPTED") { foreach (var elem in Info) { if (elem == selectedOne) { elem.AppId = filledModel.Body.submitApplicationResponse.application.applicationId; var Query = $"Update Merc_xs set AppID=\'{elem.AppId}\' where CodM= {elem.CodeFil} and CodB= {elem.CodePred}"; await ConnHolder.NonQueryAsyncConnect(Query); Debug.WriteLine("Updated"); } } // = filledModel.Body.submitApplicationResponse.application.applicationId; xml = XmlParser.DesirializeBig(await HttpRest.InfoPostAsync(IenumerationPaths.PostToCheck, selectedOne)); Debug.WriteLine(xml.Body.ReceiveApplicationResultResponse.Application.Status); while (xml.Body.ReceiveApplicationResultResponse.Application.Status == "IN_PROCESS") { xml = XmlParser.DesirializeBig(await HttpRest.InfoPostAsync(IenumerationPaths.PostToCheck, selectedOne)); System.Threading.Thread.Sleep(2000); //Debug.WriteLine(xml.Body.ReceiveApplicationResultResponse.Application.Status); } //Debug.WriteLine(xml.Body.ReceiveApplicationResultResponse.Application.Status); //XmlParser.Serialize(xml); //xmlFinish(); //text = File.ReadAllText(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\" + "Out.xml"); } } else { ContentDialog dialog = new ContentDialog() { Title = "Error", Content = "Failed to parse answer. This may means, you send wrong data or XML file is damaged.", PrimaryButtonText = "ОК", }; await dialog.ShowAsync(); } return(xml); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { ConnHolder.SetConnStr(@"Data Source=78.140.21.18;Initial Catalog=td010119; User Id=tdmerc; Password=tdmerc123;"); var info = await CommandsToWorkWithDB.GetProductsAsync(); Info = info; List <Microsoft.UI.Xaml.Controls.NavigationViewItem> navigationViewItems = new List <Microsoft.UI.Xaml.Controls.NavigationViewItem>(); for (int i = 0; i < info.Count; i++) { navigationViewItems.Add(new Microsoft.UI.Xaml.Controls.NavigationViewItem { Tag = info[i].NameOfPlace, Content = info[i].NameOfPlace }); } Microsoft.UI.Xaml.Controls.NavigationViewItem Places = new Microsoft.UI.Xaml.Controls.NavigationViewItem(); Places.Tag = "Places"; Places.Content = "Площадки"; Places.MenuItemsSource = navigationViewItems; nvSample.MenuItems.Add(Places); }
public void SaveConStr() { var connectionString = @"Data Source=" + Server.Text + ";Initial Catalog=" + DBName.Text + "; User Id=" + Login.Text + "; Password="******";"; ConnHolder.SetConnStr(connectionString); }