{"id":590,"date":"2011-11-11T15:45:50","date_gmt":"2011-11-11T15:45:50","guid":{"rendered":"http:\/\/nestor.nestasoft.fr\/?p=590"},"modified":"2012-03-22T16:17:07","modified_gmt":"2012-03-22T16:17:07","slug":"parcourir-un-datagrid-et-sauvegarde-des-donnees-silverlight-5-service-web","status":"publish","type":"post","link":"https:\/\/nestasoft.fr\/?p=590","title":{"rendered":"Parcourir un Datagrid et sauvegarde des donn\u00e9es (Silverlight 5 + Service Web)&#8230;"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignleft\" src=\"http:\/\/www.nestor.nestasoft.fr\/wp-content\/uploads\/2011\/07\/silverlight.bmp\"\/><br \/>\nBonjour.<br \/>\nNous verrons comment parcourir un Datagrid et sauvegarder les donn\u00e9es tout en maintenant le busy actif lors de la sauvegarde.<\/p>\n<p>Soit la m\u00e9thode <strong>btnOK_Click<\/strong> appel\u00e9e lors d&rsquo;un clic sur un bouton du formulaire : <\/p>\n<pre class=\"brush:csharp\"> private void btnOK_Click(object sender, RoutedEventArgs e)\r\n        {\r\n            \/\/ on lance la sauvegarde des donn\u00e9es\r\n            \/\/IList<DataGridRow> rows = _viewModel.GetRows(dgAffectation);\r\n            _viewModel.GetRows(dgAffectation);\r\n        }\r\n<\/pre>\n<p><!--more--><br \/>\n<strong>M\u00e9thode GetRows<\/strong> : <\/p>\n<pre class=\"brush:csharp\">\r\n  public  IList<DataGridRow> GetRows(DataGrid grid)\r\n        {\r\n            List<DataGridRow> rows = new List<DataGridRow>();\r\n\r\n            foreach (var rowItem in grid.ItemsSource)\r\n            {\r\n                Save(rowItem as AffectationNum);\r\n\r\n                \/\/ Se rassurer que toutes les lignes sont parcourues.\r\n                grid.ScrollIntoView(rowItem, grid.Columns.Last());\r\n\r\n                \/\/ Obtenir la valeur de la cellule.\r\n                FrameworkElement el = grid.Columns.Last().GetCellContent(rowItem);\r\n\r\n                \/\/ Extraire la rang\u00e9e parent de l'\u00e9l\u00e9ment donn\u00e9.\r\n                DataGridRow row = DataGridRow.GetRowContainingElement(el.Parent as FrameworkElement);\r\n\r\n                \/\/ Certaines lignes peuvent \u00eatre nulles.\r\n                if (row != null)\r\n                    rows.Add(row);\r\n            }\r\n\r\n            return rows;\r\n        }\r\n<\/pre>\n<p><strong>M\u00e9thode Save<\/strong><br \/>\nTerminons avec la m\u00e9thode <strong>Save<\/strong><\/p>\n<pre class=\"brush:csharp\">\r\npublic void Save(AffectationNum affectNumber)\r\n        {\r\n            \/\/ on sauvegarde les donn\u00e9es dans la base de donn\u00e9es\r\n            \/\/ on appelle le web service\r\n            try\r\n            {\r\n                \/\/ on active le busy\r\n                Model.IsBusy = true;\r\n\r\n                \/\/ on se connecte au webservice\r\n                CommonServiceClient webServ = WcfHelper.CreateCommonClient();\r\n\r\n                \/\/ on appelle le webService\r\n                webServ.UpdateCompleted += new EventHandler<UpdateCompletedEventArgs>(webServ_UpdateCompleted);\r\n\r\n                    webServ.UpdateAsync(new AffectCasse()\r\n                    {\r\n                        EmplID = affectCase.CaseID,\r\n                        EmplName = affectCase.CaseNom,\r\n                        FournisseurID = affectCase.FournisseurID,\r\n                        LogicielID = affectCase.LogicielID\r\n                    });\r\n\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                \/\/ gestion des erreurs\r\n                OnErrorOccured(ex);\r\n                \/\/ fin du traitement\r\n                Model.IsBusy = false;\r\n            }\r\n        }\r\n<\/pre>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_590\" class=\"pvc_stats all  \" data-element-id=\"590\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bonjour. Nous verrons comment parcourir un Datagrid et sauvegarder les donn\u00e9es tout en maintenant le busy actif lors de la sauvegarde. Soit la m\u00e9thode btnOK_Click appel\u00e9e lors d&rsquo;un clic sur un bouton du formulaire : private void btnOK_Click(object sender, RoutedEventArgs e) { \/\/ on lance la sauvegarde des donn\u00e9es \/\/IList rows = _viewModel.GetRows(dgAffectation); _viewModel.GetRows(dgAffectation); }<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_590\" class=\"pvc_stats all  \" data-element-id=\"590\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-590","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=590"}],"version-history":[{"count":11,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/590\/revisions"}],"predecessor-version":[{"id":869,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/590\/revisions\/869"}],"wp:attachment":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}