private void btnSend_Click(object sender, RoutedEventArgs e)
 {
     if (this.lstScenarioName.SelectedItem != null)
     {
         this.DialogResult = true;
         this.SelectedScenarior = lstScenarioName.SelectedItem as Scenarior;
         this.Close();
     }
     else
         MessageBox.Show("必須選取範本!");
 }
예제 #2
0
        async void SendTemplate(Scenarior scene)
        {
            try
            {
                InCmdSending = true;

                foreach (UIElement element in grdDeviceLayer.Children)
                {

                    try
                    {
                        if (element is CheckBox)
                        {
                            if ((element as CheckBox).IsEnabled && (element as CheckBox).IsChecked == true)
                            {


                             //   bool isFinish = false;
                                //for (int i = 0; i < 3; i++)
                                //{
                                    try
                                    {
                                        StreetLightBindingData data = (element as CheckBox).DataContext as StreetLightBindingData;
                                        //StreetLightInfo[] backInfo = await coor_mgr.GetStreetLightListAsync(data.DevID);
                                        //await Task.Delay(100);
                                        coor_mgr.SetDeviceScheduleAsync(data.DevID, scene.Schedule.GetScheduleSegTimeString(), scene.Schedule.GetScheduleSegLevelString());

                                        await Task.Delay(100);
                                      
                                    }
                                    catch
                                    { ;}
                                //}
                                //if (!isFinish)
                                //{
                                //    MessageBox.Show(((element as CheckBox).DataContext as StreetLightBindingData).DevID + "," + "排程傳送失敗!");
                                //}

                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(((element as CheckBox).DataContext as StreetLightBindingData).DevID + "," + ex.Message);
                    }
                }

                //check data
                int trycnt = 0;
                int failcnt = 0;
                do
                {
                    trycnt++;
                   // int failcnt = 0;
                    failcnt = 0;
                    foreach (UIElement element in grdDeviceLayer.Children)
                    {
                        try
                        {
                            if (element is CheckBox)
                            {
                                if ((element as CheckBox).IsEnabled && (element as CheckBox).IsChecked == true)
                                {
                                    StreetLightBindingData data = (element as CheckBox).DataContext as StreetLightBindingData;
                                    StreetLightInfo[] backInfo = await coor_mgr.GetStreetLightListAsync(data.DevID);
                                    await Task.Delay(100);
                                    if (!backInfo[0].sch.IsEqual(scene.Schedule))
                                    {
                                        failcnt++;
                                        coor_mgr.SetDeviceScheduleAsync(data.DevID, scene.Schedule.GetScheduleSegTimeString(), scene.Schedule.GetScheduleSegLevelString());
                                        //  break;
                                        await Task.Delay(100);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                           
                        }
                    }
                } while (failcnt != 0 && trycnt < 4);
                if (failcnt == 0)
                    MessageBox.Show("ok!");
                else
                    MessageBox.Show("fail!");
                

            }
            catch { ;}
            finally
            {
                InCmdSending = false;
            }
        }
예제 #3
0
        async void SendTemplate(Scenarior scene)
        {

            #region open later
            foreach (UIElement element in  (this.map.Layers["grdDeviceLayer"] as ElementLayer).Children)
            {

                try
                {
                    if (element is CheckBox)
                    {
                        if ((element as CheckBox).IsEnabled && (element as CheckBox).IsChecked == true)
                        {
                            bool isFinish = false;
                            for (int i = 0; i < 3; i++)
                            {
                                try
                                {
                                    StreetLightBindingData data = (element as CheckBox).DataContext as StreetLightBindingData;

                                    coor_mgr.SetDeviceScheduleAsync(data.DevID, scene.Schedule.GetScheduleSegTimeString(), scene.Schedule.GetScheduleSegLevelString());

                                    await Task.Delay(100);
                                    StreetLightInfo[] backInfo = await coor_mgr.GetStreetLightListAsync(data.DevID);
                                    await Task.Delay(100);
                                    if (backInfo[0].sch.IsEqual(scene.Schedule))
                                    {
                                        isFinish = true;
                                        break;
                                    }

                                }
                                catch
                                { ;}
                                Task.Delay(5000);
                            }
                            if (!isFinish)
                            {
                                MessageBox.Show(((element as CheckBox).DataContext as StreetLightBindingData).DevID + "," + "排程傳送失敗!");
                            }

                        }

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(((element as CheckBox).DataContext as StreetLightBindingData).DevID + "," + ex.Message);
                }
            }
            MessageBox.Show("ok!");
            #endregion
        }