Esempio n. 1
0
        void ColumnHeaderClicked(object sender, EventArgs e)
        {
            var ch   = sender as GridViewColumnHeader;
            var list = DependencyObjectHelper.FindAncestorType <FSExplorerList>(ch);

            list.ListColumnHeaderClicked((string)ch.Content);
        }
 private void SwagDataHeader_TextBoxKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         TextBox  txtText  = (TextBox)sender;
         MenuItem menuItem = (MenuItem)DependencyObjectHelper.TryFindParent <MenuItem>(txtText);
         Button   btn      = menuItem.FindLogicalChild <Button>();
         btn.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
     }
 }
        private void SelectedItemsListBox_DragOver(object sender, DragEventArgs e)
        {
            var sourceData = (DragDropData)e.Data.GetData(typeof(DragDropData));

            if (sourceData == null)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
                return;
            }
            var source = sourceData.SourceControl;

            ListBox control =
                DependencyObjectHelper.FindAncestorOrSelf <ListBox>(VisualTreeHelper.HitTest(this, e.GetPosition(this)).VisualHit);

            if (control == AvailableItemsListBox ||
                control == SelectedItemsListBox)
            {
                Point  point           = e.GetPosition(control);
                double topMoveRange    = control.ActualHeight / 5;
                double bottomMoveRange = control.ActualHeight - topMoveRange;
                var    sv = DependencyObjectHelper.FindVisualChild <ScrollViewer>(control);
                if (point.Y < topMoveRange)
                {
                    sv.ScrollToVerticalOffset(sv.VerticalOffset - (topMoveRange - point.Y));
                }
                else if (point.Y > bottomMoveRange)
                {
                    sv.ScrollToVerticalOffset(sv.VerticalOffset + (point.Y - bottomMoveRange));
                }
            }

            if (source == AvailableItemsListBox && control == AvailableItemsListBox)
            {
                e.Effects = DragDropEffects.None;
            }
            else if (source == AvailableItemsListBox && control == SelectedItemsListBox)
            {
                e.Effects = DragDropEffects.Copy;
            }
            else if (source == SelectedItemsListBox && control == AvailableItemsListBox)
            {
                e.Effects = DragDropEffects.Move;
            }
            else if (source == SelectedItemsListBox && control == SelectedItemsListBox)
            {
                e.Effects = DragDropEffects.Move;
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }

            e.Handled = true;
        }
Esempio n. 4
0
        FSExplorerItem GetTreeExplorerItem(DependencyObject d)
        {
            var ti = DependencyObjectHelper.FindAncestorType <ExplorerTreeViewItem>(d);

            if (ti == null || ti.HasHeader == false || ti.Header == null)
            {
                return(null);
            }

            return(ti.Header as FSExplorerItem);
        }
Esempio n. 5
0
        private void SelectCombox(object[] obj)
        {
            ComboBox                cmb     = obj[0] as ComboBox;
            PasswordBox             Psb     = obj[1] as PasswordBox;
            List <WaterMarkTextBox> TextBox = DependencyObjectHelper.FindVisualChild <WaterMarkTextBox>(cmb);

            string[] SplitStr = cmb.SelectedValue.ToString().Split('*');
            string   _pwd     = RsaHelper.RSADecrypt(SplitStr[0], SplitStr[1]);

            Psb.Password = _pwd;
        }
Esempio n. 6
0
        FSExplorerItem GetListExplorerItem(DependencyObject d)
        {
            var li = DependencyObjectHelper.FindAncestorType <ListViewItem>(d);

            if (li == null || li.Content == null)
            {
                return(null);
            }

            return(li.Content as FSExplorerItem);
        }
        private void SwagColumnHeader_FillEmptyInputClick(object sender, RoutedEventArgs e)
        {
            Button         btnFill        = (Button)sender;
            MenuItem       miParent       = (MenuItem)((MenuItem)((Grid)btnFill.Parent).Parent).Parent;
            SwagDataColumn swagDataColumn = (SwagDataColumn)btnFill.DataContext;
            SwagDataTable  swagDataTable  = swagDataColumn.SwagDataTable;
            ContextMenu    contextMenu    = DependencyObjectHelper.TryFindParent <ContextMenu>(btnFill);
            String         colName        = swagDataColumn.ColumnName;
            Type           targetType     = swagDataColumn.DataType;

            Grid   grid             = miParent.FindLogicalChild <Grid>("gridFillEmptyInput");
            String defaultValueText = grid.FindVisualChild <TextBox>().Text;

            SwagLogger.LogStart(this, "Fill Column with Input |col={Column}|inpt={Input}|", swagDataColumn.ColumnName, defaultValueText);

            if (defaultValueText != "")
            {
                #region Resolve defaultValue
                Object defaultValue = DBNull.Value;
                if (targetType.GetTypeCode() != TypeCode.String)
                {
                    try
                    {
                        defaultValue = Convert.ChangeType(defaultValueText, targetType);
                    }
                    catch
                    {
                        defaultValue = DBNull.Value;
                    }
                }
                else
                {
                    defaultValue = defaultValueText;
                }
                #endregion Resolve defaultValue

                swagDataTable.DelaySave = true;
                using (var scope = swagDataTable.GetFreezeListScope())
                {
                    foreach (DataRowView drv in swagDataTable.DataTable.DefaultView)
                    {
                        if (drv[colName] == null || drv[colName] == DBNull.Value || drv[colName].ToString() == "")
                        {
                            drv[colName] = defaultValue;
                        }
                    }
                }
                swagDataTable.DelaySave = false;
            }

            contextMenu.IsOpen = false;
            SwagLogger.LogEnd(this, "Fill Column with Input |col={Column}|inpt={Input}|", swagDataColumn.ColumnName, defaultValueText);
        }
Esempio n. 8
0
        public void OnLVPreviewKeyDown(object sender, KeyEventArgs e)
        {
            ListView lv   = sender as ListView;
            var      list = DependencyObjectHelper.FindAncestorType <FSExplorerList>(lv);

            if (list != null && list is FSExplorerList)
            {
                if (list.Explorer != null)
                {
                    list.OnLVPreviewKeyDown(sender, e);
                }
            }
        }
Esempio n. 9
0
        //Routing events to their intended handler in a resource dictionary. Is it possible any other way?
        public void OnTVPreviewKeyDown(object sender, KeyEventArgs e)
        {
            TreeView tv   = sender as TreeView;
            var      tree = DependencyObjectHelper.FindAncestorType <FSExplorerTree>(tv);

            if (tree != null && tree is FSExplorerTree)
            {
                if (tree.Explorer != null)
                {
                    tree.Explorer.OnTVPreviewKeyDown(sender, e);
                }
            }
        }
 private void DgDataFormTemplateDesigner_Selected(object sender, RoutedEventArgs e)
 {
     if (e.OriginalSource.GetType() == typeof(DataGridCell))
     {
         DataGrid g = (DataGrid)sender;
         g.BeginEdit(e);
         DataGridCell   cell      = e.OriginalSource as DataGridCell;
         List <TextBox> textBoxes = DependencyObjectHelper.FindChildrenByType <TextBox>(cell);
         if (textBoxes.Count > 0)
         {
             textBoxes[0].Focus();
             textBoxes[0].SelectAll();
         }
     }
 }
        private void SwagDataHeader_RenameClick(object sender, RoutedEventArgs e)
        {
            Button      btnRename   = (Button)sender;
            MenuItem    miParent    = (MenuItem)((MenuItem)((Grid)btnRename.Parent).Parent).Parent;
            SwagData    swagData    = (SwagData)btnRename.DataContext;
            ContextMenu contextMenu = DependencyObjectHelper.TryFindParent <ContextMenu>(btnRename);

            Grid   grid         = miParent.FindLogicalChild <Grid>("gridRename");
            String newColName   = grid.FindVisualChild <TextBox>().Text;
            String originalName = swagData.Display;

            SwagLogger.LogStart(this, "SwagData Rename |orig={Column}|new={NewColName}|", originalName, newColName);
            swagData.Rename(newColName);
            contextMenu.IsOpen = false;
            SwagLogger.LogEnd(this, "SwagData Rename |orig={Column}|new={NewColName}|", originalName, newColName);
        }
Esempio n. 12
0
        private void ClearCheckedCalendarTimeslots()
        {
            var checkedTimeslots = DependencyObjectHelper
                                   .FindVisualChildren <CalendarTimeslotItem>(this)
                                   .Where(x => x.IsChecked == true)
                                   .OrderBy(x => x.TimeslotDate)
                                   .ThenBy(x => x.TimeslotStart)
                                   .ToList();

            if (checkedTimeslots != null)
            {
                foreach (var timeslot in checkedTimeslots)
                {
                    timeslot.IsChecked = false;
                }
            }
        }
Esempio n. 13
0
        private void SwagColumnHeader_SelectColumnValueClick(object sender, RoutedEventArgs e)
        {
            MenuItem             menuItem             = (MenuItem)sender;
            ContextMenu          contextMenu          = DependencyObjectHelper.TryFindParent <ContextMenu>(menuItem);
            FrameworkElement     placementTarget      = (FrameworkElement)contextMenu.PlacementTarget;
            DataGridColumnHeader dataGridColumnHeader = DependencyObjectHelper.TryFindParent <DataGridColumnHeader>(placementTarget);
            SwagDataColumn       swagDataColumn       = (SwagDataColumn)menuItem.DataContext;
            SwagDataTable        swagDataTable        = swagDataColumn.SwagDataTable;

            SwagLogger.LogStart(this, "Select Column |col={Column}|", swagDataColumn.ColumnName);

            DataGrid.SelectedCellsChanged -= DataGrid_SelectedCellsChanged;
            DataGrid.SelectedCells.Clear();
            foreach (DataRowView drv in swagDataTable.DataTable.DefaultView)
            {
                DataGrid.SelectedCells.Add(new DataGridCellInfo(drv, dataGridColumnHeader.Column));
            }
            DataGrid.SelectedCellsChanged += DataGrid_SelectedCellsChanged;
            DataGrid_SelectedCellsChanged(null, null);
            SwagLogger.LogStart(this, "Select Column |col={Column}|", swagDataColumn.ColumnName);
        }
Esempio n. 14
0
        void SelectPhone(object[] x)
        {
            ComboBox    cmbBox   = x[0] as ComboBox;
            Button      phoneBtn = x[1] as Button;
            PasswordBox Psb      = x[2] as PasswordBox;

            Page     loginPage = x[3] as Page;
            CheckBox isKeepPwd = loginPage.FindName("IsKeepPwd") as CheckBox;

            isKeepPwd.IsChecked = true;

            List <WaterMarkTextBox> TextBox = DependencyObjectHelper.FindVisualChild <WaterMarkTextBox>(cmbBox);
            int index = JObjectHelper.GetStrNum(phoneBtn.Tag.ToString()) - 1;

            //cmbBox.Text = LocalUserInfo[index].Phone;
            TextBox[0].Text       = LocalUserInfo[index].Phone;
            cmbBox.IsDropDownOpen = false;
            string[] SplitStr = LocalUserInfo[index].Pwd.Split('*');
            string   _pwd     = RsaHelper.RSADecrypt(SplitStr[0], SplitStr[1]);

            Psb.Password = _pwd;
        }
Esempio n. 15
0
        /// <summary>
        /// Helper method for binding controls to a property that has the EditProp attribute.
        /// </summary>
        /// <param name="editPropAttr"></param>
        /// <param name="prop"></param>
        private StackPanel BindEditPropHelper(IEditProp editPropAttr, PropertyInfo prop)
        {
            //first, create the label and control associated with this property.
            TextBlock label = new TextBlock();

            label.TextTrimming = TextTrimming.CharacterEllipsis;
            label.Text         = editPropAttr.Label;
            label.Width        = editPropAttr.LabelWidth;
            label.Margin       = new Thickness(2);
            if (editPropAttr.ToolTip != null && editPropAttr.ToolTip.Length > 0)
            {
                label.ToolTip = editPropAttr.ToolTip;
            }

            Control con = Activator.CreateInstance(editPropAttr.ControlType) as Control;

            con.Width     = editPropAttr.Width;
            con.Height    = editPropAttr.Height;
            con.Margin    = new Thickness(2);
            con.IsEnabled = editPropAttr.IsEnabled;
            if (editPropAttr.ToolTip != null && editPropAttr.ToolTip.Length > 0)
            {
                con.ToolTip = editPropAttr.ToolTip;
            }

            //stack 'em
            StackPanel stack = new StackPanel();

            stack.FlowDirection = FlowDirection.LeftToRight;
            if (editPropAttr.VerticalStacking)
            {
                stack.Orientation = Orientation.Vertical;
            }
            else
            {
                stack.Orientation = Orientation.Horizontal;
            }
            stack.Children.Add(label);
            stack.Children.Add(con);

            //bind the control to the property
            //ALERT: We are NOT handling exceptions here because we want them to throw
            //during develoment so that we can find invalid property names.
            //TODO: Decide a proper development macro to use to enable/disable this
            DependencyProperty dependency = DependencyObjectHelper.GetDependencyProperty(
                editPropAttr.ControlType,
                editPropAttr.DependencyProperty);
            Binding bindVal = new Binding(prop.Name);

            bindVal.Source = this;
            bindVal.Mode   = editPropAttr.BindingMode;
            bindVal.UpdateSourceTrigger = editPropAttr.UpdateTrigger;
            if (editPropAttr.Converter != null)
            {
                bindVal.Converter = Activator.CreateInstance(editPropAttr.Converter) as IValueConverter;
            }
            BindingOperations.SetBinding(con, dependency, bindVal);

            //check for additional binding info
            Type type           = this.GetType();
            var  keysProperty   = (editPropAttr.KeysSourcePath == null) ? null : type.GetProperty(editPropAttr.KeysSourcePath, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance);
            var  valuesProperty = (editPropAttr.ValuesSourcePath == null) ? null : type.GetProperty(editPropAttr.ValuesSourcePath, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance);

            System.Collections.IEnumerable keys   = (keysProperty == null) ? null : keysProperty.GetValue(this) as System.Collections.IEnumerable;
            System.Collections.IEnumerable values = (valuesProperty == null) ? null : valuesProperty.GetValue(this) as System.Collections.IEnumerable;
            IList <Pair> pairs = null;

            //combine keys and values (if available) into a single paired ItemsSource list
            if (keys != null && values != null)
            {
                System.Collections.IEnumerator keysEnum   = keys.GetEnumerator();
                System.Collections.IEnumerator valuesEnum = values.GetEnumerator();
                pairs = new List <Pair>();
                do
                {
                    if (!keysEnum.MoveNext())
                    {
                        break;
                    }
                    if (!valuesEnum.MoveNext())
                    {
                        break;
                    }
                    pairs.Add(new Pair(keysEnum.Current, valuesEnum.Current));
                } while (true);
            }

            //if the control exposes an items list then we will fill it out
            //either using the ItemsSource property of the attribute or a
            // a list of paired values (see above) if available
            ItemsControl itemsCon = con as ItemsControl;

            if (itemsCon != null)
            {
                //setting a paired source
                if (pairs != null)
                {
                    itemsCon.ItemsSource       = pairs;
                    itemsCon.DisplayMemberPath = editPropAttr.DisplayMemberPath;
                }
                else
                {
                    var itemsProperty = (editPropAttr.ItemsSourcePath == null) ? null : type.GetProperty(editPropAttr.ItemsSourcePath, BindingFlags.Public | BindingFlags.Instance);
                    System.Collections.IEnumerable items = (itemsProperty == null) ? null : itemsProperty.GetValue(this) as System.Collections.IEnumerable;
                    itemsCon.ItemsSource = items;
                }
            }

            //if the control exposes a selector that will be set as well.
            Selector selector = con as Selector;

            if (selector != null)
            {
                if (pairs != null)
                {
                    selector.SelectedValuePath = editPropAttr.SelectedValuePath;
                }
                if (editPropAttr.SelectedValuePath != null)
                {
                    PropertyInfo p = type.GetProperty(editPropAttr.SelectedValuePath);
                    if (p != null)
                    {
                        selector.SelectedValue = p.GetValue(this);
                    }
                    if (selector.SelectedValue == null)
                    {
                        selector.SelectedValue = editPropAttr.SelectedValue;
                    }
                }
                else
                {
                    selector.SelectedValue = editPropAttr.SelectedValue;
                }
            }

            return(stack);
        }
Esempio n. 16
0
        //private MyCommand _clickCommand;

        //public MyCommand<object[]> LoginCommand
        //{
        //    get
        //    {
        //        return  new MyCommand<object[]>(x=> Login_Click(x));
        //    }
        //}
        //窗口登录操作

        #region 方法
        private void Login_Click(object[] obj)
        {
            #region

            RunState = true;

            UseComboBox             cmb     = obj[0] as UseComboBox;
            List <WaterMarkTextBox> TextBox = DependencyObjectHelper.FindVisualChild <WaterMarkTextBox>(cmb);
            string Phone = TextBox[0].Text;

            PasswordBox pwd    = obj[1] as PasswordBox;
            string      Pwd    = pwd.Password;
            Page        page   = obj[2] as Page;
            Window      window = Window.GetWindow(page);//获取当前页的母窗体(LoginWindow)
            CheckBox    ch     = obj[3] as CheckBox;

            Task.Factory.StartNew(new Action(delegate
            {
                string LoginCallBack    = account.Account_Login(Phone, Pwd);
                JObject LoginCallBackJo = (JObject)JsonConvert.DeserializeObject(LoginCallBack);
                if (JObjectHelper.GetStrNum(LoginCallBackJo["code"].ToString()) == 200)
                {
                    if (LoginCallBackJo["dataList"]["enterpriseUserFlag"].GetInt() == 0)
                    {
                        DispatcherHelper.CheckBeginInvokeOnUI(() =>
                        {
                            RunState = false;
                            MessageBox.Show("您还未进行企业认证,请至移动端申请企业认证后登陆");
                        });
                        return;
                    }
                    Bo = true;
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        if ((bool)ch.IsChecked)
                        {
                            SaveUserLoginInfo(Phone, Pwd);
                        }
                        bool bo = LoginHelper.LoginCallBack(LoginCallBackJo);
                        if (bo)
                        {
                            Bo = true;
                            ViewModelLocator.Win_Content.Show();
                            //new ContentWindow().Show(); //contentwindow打开
                            //var cc= ViewModelLocator.Pipe;
                            Thread thread = new Thread(LoginHelper.AddPrinter);
                            thread.Start();
                            window.Close();
                        }
                    });
                }
                else
                {
                    Bo       = false;
                    RunState = false;
                    DispatcherHelper.CheckBeginInvokeOnUI(() => { MessageBox.Show(LoginCallBackJo["message"].ToString()); });
                }
            }));

            #endregion
        }
Esempio n. 17
0
        //static object boundTo = null;
        /// <summary>
        /// WPF converter to convert a FieldMapperGridViewModel DataContext to a ListView
        /// </summary>
        /// <param name="value">The source value (FieldMapperGridViewModel)</param>
        /// <param name="targetType">Not used</param>
        /// <param name="parameter">Not used</param>
        /// <param name="culture">Not used</param>
        /// <returns>A list of MenuItems</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var fmgvm = value as IFieldMapperGridViewModel;

            if (fmgvm != null)
            {
                var mainGrid = new Grid();
                mainGrid.ColumnDefinitions.Add(new ColumnDefinition());
                mainGrid.RowDefinitions.Add(new RowDefinition());

                var dataGrid = new DataGrid();
                VirtualizingStackPanel.SetScrollUnit(dataGrid, ScrollUnit.Pixel);
                dataGrid.AutoGenerateColumns     = false;
                dataGrid.EnableRowVirtualization = true;
                VirtualizingStackPanel.SetVirtualizationMode(dataGrid, VirtualizationMode.Standard);
                VirtualizingStackPanel.SetIsVirtualizing(dataGrid, true);
                dataGrid.CanUserReorderColumns    = false;
                dataGrid.CanUserAddRows           = false;
                dataGrid.CanUserDeleteRows        = false;
                dataGrid.IsReadOnly               = true;
                dataGrid.DataContext              = fmgvm;
                dataGrid.VerticalContentAlignment = VerticalAlignment.Top;
                dataGrid.GridLinesVisibility      = DataGridGridLinesVisibility.All;
                dataGrid.HorizontalGridLinesBrush = new SolidColorBrush(Color.FromRgb(224, 224, 255));
                dataGrid.VerticalGridLinesBrush   = new SolidColorBrush(Color.FromRgb(224, 224, 255));
                //RoutedEventHandler rowHandler = (o,a) =>
                //    {
                //        var row = a.Source as DataGridRow;
                //        foreach (var col in dataGrid.Columns)
                //        {
                //            col.GetCellContent(row).Tag = fmgvm.GetValueOf(row.DataContext, col.SortMemberPath);
                //        }
                //        Console.WriteLine(a.ToString());
                //    };
//                EventHandler<DataGridRowEventArgs> func = (o,a) =>
//                    {
//                        BindingOperations.SetBinding(a.Row, DataGridRow.FontWeightProperty, new Binding("FontWeight"));
////                        a.Row.Loaded += rowHandler;
//                    };
                //dataGrid.LoadingRow += func;
                //dataGrid.Unloaded += (o, a) => { dataGrid.LoadingRow -= func; };

                PropertyDescriptor pd = DependencyPropertyDescriptor.FromProperty(DataGridColumn.WidthProperty, typeof(DataGridColumn));

                BindingExpressionBase itemsSourceBindingExpression = BindingOperations.SetBinding(
                    dataGrid, DataGrid.ItemsSourceProperty,
                    new Binding("Elements"));

                dataGrid.Loaded += (o, a) =>
                {
                    var host = DependencyObjectHelper.FindAncestor <FieldMapperGridControl>(dataGrid);

                    host.InnerControl = dataGrid;
                    fmgvm.MetaData    = host;

                    BindingOperations.SetBinding(dataGrid, DataGrid.SelectedItemProperty,
                                                 new Binding("SelectedItem")
                    {
                        Source = host, Mode = BindingMode.TwoWay, Converter = new StripFieldExposerConverter(fmgvm)
                    });

                    RebuildDataGridColumns(fmgvm, dataGrid, pd, host, true);

                    foreach (var item in fmgvm.InternalSelectedElements)
                    {
                        dataGrid.SelectedItems.Add(item);
                    }
                    dataGrid.SelectionChanged += SelectionChanged;
                };

                ((INotifyPropertyChanged)fmgvm).PropertyChanged += (o, a) =>
                {
                    if (fmgvm.MetaData == null)
                    {
                        return;
                    }

                    if (a.PropertyName == "Columns")
                    {
                        var host = (FieldMapperGridControl)fmgvm.MetaData;
                        RebuildDataGridColumns(fmgvm, dataGrid, pd, host);
                    }
                };
                fmgvm.Columns.CollectionChanged += (o, a) =>
                {
                    if (fmgvm.MetaData == null)
                    {
                        return;
                    }

                    var host = (FieldMapperGridControl)fmgvm.MetaData;
                    RebuildDataGridColumns(fmgvm, dataGrid, pd, host);
                };

                mainGrid.Children.Add(dataGrid);
                Grid.SetRow(dataGrid, 0);
                Grid.SetColumn(dataGrid, 0);
                return(mainGrid);
            }
            return(Binding.DoNothing);
        }