随笔 - 24  文章 - 2  评论 - 0  阅读 - 27723

WPF 自动化上位机客户端用到的一些控件和样式

最近用WPF用来写了一些上位机用到的一些功能 做了一些总结

用到 MVVMLight框架 然后样式用的MaterialDesign

登录功能

1.能调用处理键盘

 

 

private void TextBox_MouseEnter(object sender, MouseEventArgs e)
        {
            System.Diagnostics.Process.Start(@"C:\Windows\System32\osk.exe");
            //System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
            //OskHelper.OpenOsk();
        }

 

2.可以切换中英文

复制代码
private void LoginTRMode_Click(object sender, RoutedEventArgs e)
        {
            bool check = LoginTRMode.IsChecked == true ? true : false;
            if (check)
            {
                App.UpdateLanguage("zh-cn");
            }
            else
            {
                App.UpdateLanguage("en-us");
            }
        }
复制代码
复制代码
public static void UpdateLanguage(string lan)
        {
            // 获取配置
            string requestedLanguage = $"Source/{lan}.xaml";
            ResourceDictionary resourceDictionary = Application.Current.Resources.MergedDictionaries.Where(s => s.Source != null).FirstOrDefault(d => d.Source.OriginalString.Equals(requestedLanguage));
            //ResourceDictionary resourceDictionary = temp[6];
            Current.Resources.MergedDictionaries.Remove(resourceDictionary);
            Current.Resources.MergedDictionaries.Add(resourceDictionary);

            // 保存配置
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConfigurationManager.AppSettings["Language"] = lan;
            config.Save(ConfigurationSaveMode.Modified);
            //刷新
            ConfigurationManager.RefreshSection("appSettings");
        }
复制代码

主界面

主要功能:

1.状态Remote,Local,Offline的切换

2.Notification刷新,删除

3.配置页面的渐出渐入

4.页面Layout实现可手动配置

5.全局样式明亮切换(选的框架自带的)

6.菜单的选择

 生产信息

1.主要时分页功能

2.到出为csv文件

 

 

 

复制代码
public void ExportDataGrid(DataGrid dGrid)
        {
            SaveFileDialog objSFD = new SaveFileDialog()
            {
                DefaultExt = "csv",
                Filter = "CSV Files (*.csv)|*.csv|xml Files (*.xml)|*.xml|All files (*.*)|*.*",
                FilterIndex = 1
            };
            if (objSFD.ShowDialog() == true)
            {
                string strFormat = objSFD.SafeFileName.Substring(objSFD.SafeFileName.IndexOf('.') + 1).ToUpper();
                StringBuilder strBuilder = new StringBuilder();
                List<string> lstFields = new List<string>();
                if (dGrid.ItemsSource != null)
                {
                    if (dGrid.HeadersVisibility == DataGridHeadersVisibility.Column || dGrid.HeadersVisibility == DataGridHeadersVisibility.All)
                    {
                        foreach (DataGridColumn dgcol in dGrid.Columns)
                        {
                            lstFields.Add(FormatField(dgcol.SortMemberPath.ToString(), strFormat));
                        }
                        foreach (object data in dGrid.ItemsSource)
                        {
                            if (data is ProcessDataInfo)
                            {
                                var temp = data as ProcessDataInfo;
                                lstFields.Add(FormatField("APDInfo", strFormat));
                                break;
                            }
                        }
                        BuildStringOfRow(strBuilder, lstFields, strFormat);
                    }
                    if (dGrid.ItemsSource is DataView)
                    {
                        foreach (DataRowView data in dGrid.ItemsSource)
                        {
                            lstFields.Clear();
                            foreach (DataGridColumn col in dGrid.Columns)
                            {
                                string strValue = data[col.SortMemberPath.ToString()].ToString();
                                //double trygetDouble = 0;
                                //if (double.TryParse(strValue,out trygetDouble))
                                //{
                                //    strValue = string.Format("{0} ({1}%)", ((int)trygetDouble).ToString(), ((int)(trygetDouble*100 / (24 * 60))).ToString());
                                //}
                                lstFields.Add(FormatField(strValue, strFormat));
                            }
                            BuildStringOfRow(strBuilder, lstFields, strFormat);
                        }
                    }
                    else
                    {
                        foreach (object data in dGrid.ItemsSource)
                        {
                            lstFields.Clear();
                            if (data is string)
                            {
                                string str = data as string;
                                lstFields.Add(FormatField(str, strFormat));
                            }
                            else
                            {
                                foreach (DataGridColumn col in dGrid.Columns)
                                {
                                    string strValue = "";
                                    Binding objBinding = null;
                                    if (col is DataGridBoundColumn)
                                    {
                                        objBinding = (col as DataGridBoundColumn).Binding as Binding;
                                    }
                                    if (col is DataGridTemplateColumn)
                                    {
                                        DependencyObject objDO = (col as DataGridTemplateColumn).CellTemplate.LoadContent();
                                        FrameworkElement oFE = (FrameworkElement)objDO;
                                        FieldInfo oFI = oFE.GetType().GetField("TextProperty");
                                        if (oFI != null)
                                        {
                                            if (oFI.GetValue(null) != null)
                                            {
                                                if (oFE.GetBindingExpression((DependencyProperty)oFI.GetValue(null)) != null)
                                                {
                                                    objBinding = oFE.GetBindingExpression((DependencyProperty)oFI.GetValue(null)).ParentBinding;
                                                }
                                            }
                                        }
                                    }
                                    if (objBinding != null)
                                    {
                                        if (objBinding.Path.Path != "")
                                        {
                                            PropertyInfo pi = data.GetType().GetProperty(objBinding.Path.Path);
                                            if (pi != null)
                                            {
                                                if (col.SortMemberPath.ToString() == "AlarmCode")
                                                {
                                                    object value = pi.GetValue(data, null);
                                                    strValue = value == null ? "" : Convert.ToInt32(value).ToString();
                                                }
                                                else if (col.SortMemberPath.ToString() == "AlarmLevel")
                                                {
                                                    object value = pi.GetValue(data, null);
                                                    strValue = value == null ? "" : Convert.ToInt32(value).ToString();
                                                }
                                                else
                                                {
                                                    object value = pi.GetValue(data, null);
                                                    strValue = value == null ? "" : value.ToString().Trim();
                                                }
                                            }
                                        }
                                        if (objBinding.Converter != null)
                                        {
                                            if (strValue != "")
                                            {
                                                strValue = objBinding.Converter.Convert(strValue, typeof(string), objBinding.ConverterParameter, objBinding.ConverterCulture).ToString();
                                            }
                                            else
                                            {
                                                strValue = objBinding.Converter.Convert(data, typeof(string), objBinding.ConverterParameter, objBinding.ConverterCulture).ToString();
                                            }
                                        }
                                    }
                                    lstFields.Add(FormatField(strValue, strFormat));
                                }
                            }
                            //if (data is ProcessDataInfo)
                            //{
                            //    var tmp = data as ProcessDataInfo;
                            //    if (tmp.APData.Data != null)
                            //    {
                            //        string str = null;
                            //        foreach (var item in tmp.APData.Data)
                            //        {
                            //            str += string.Format("{0}={1}", item.Name, item.Value) + ";";
                            //        }
                            //        lstFields.Add(FormatField(str, strFormat));
                            //    }
                            //}
                            BuildStringOfRow(strBuilder, lstFields, strFormat);
                        }
                    }
                }
                StreamWriter sw = new StreamWriter(objSFD.OpenFile());
                SetStreamWriter(sw, strBuilder, strFormat);
            }
        }
复制代码

 

打印功能

 1.流水号打印

2.条形码打印

3.二维码打印

4.打印预览

 

邮件编辑发送功能

 

 PDF阅读器

 

 拖拽功能

 

 

自定义弹框提示

 

 

分页样式

详情页

 

posted on   java不白吃  阅读(152)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示