按钮控件

<Button Content="浏    览" Name="btnBrowse" Margin="4,0" VerticalAlignment="Center" Width="80"  Background="#6699CC" Click="btnBrowse_Click"/>

默认按钮

<Button x:Name="btn_login" Width="75" Height="25" Click="btn_login_Click" IsDefault="True">登    录ž</Button>

按下,抬起事件

PreviewMouseUp
PreviewMouseDown

背景色

m_cur_button.Background = Brushes.Gold;

While we can use OLE DB if we’re using the .NET Framework, Microsoft has stated that OLE DB won’t be supported for .NET Core.

.net core

使用 ODBC 来实现。

.net framework

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SPCAssist
{
/*
* Oledb.4.0在64位系统上不支持,需要使用 x86 目标平台
*/
public class AccessHelper
{
OleDbConnection conn;
DataTable dt;

/*
* dbPath 完整路径 d:/ddd/dd.mdb
*/
public int Open(string dbPath)
{
if (conn==null)
{
conn = new OleDbConnection();
}
conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + dbPath;

return 0;
}

public void Close()
{
conn.Close();
}

public DataTable Query(string sql)
{
OleDbCommand cmd = new OleDbCommand();
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = sql;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);

return dt;
}
public int Exec(string sql)
{
OleDbCommand cmd = new OleDbCommand();
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = sql;
int iRet = cmd.ExecuteNonQuery();

return iRet;
}

}
}

阅读全文 »

初始化,遍历

Dictionary<int, string> dict = new Dictionary<int, string>()
{
{1,"One"},
{2, "Two"},
{3,"Three"}
};

foreach (KeyValuePair<int, string> item in dict)
{
Console.WriteLine("Key: {0}, Value: {1}", item.Key, item.Value);
}

foreach (var it in nominalVals.Values)
{
sData[pos] = *((int*)&it);
pos += 1;
}

更新

如果是结构体的话
不能直接使用 x[‘x’] = xx 的方式更新,好奇怪。

加入一张图片,在图片的 Build Action 里面选择 SplashScreen 。重新编译就可以了

参考

.Net Framework 4.7.2 离线包安装时出现“无法建立到信任根颁发机构的证书链” 问题

证书链接

  • Win+R 打开运行,输入MMC,确定。

  • 文件→添加/删除管理单元

  • 添加证书

阅读全文 »

启动时显示位置

如果父窗口是 topmost 窗口,子窗口会被挡住,设成 CenterOwner 就可以了.

private void btnLogin_Click(object sender, RoutedEventArgs e)
{
Type type = this.GetType();
Assembly assembly = type.Assembly;
Window window = (Window)assembly.CreateInstance(type.Namespace + "." + "WinUserLogin");
((WinUserLogin)window).parentFunc = GetChildWinValue;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.Owner = this;
window.Show();
}
阅读全文 »

创建无边框的圆角窗口

<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d" Topmost="True" Background="Transparent" AllowsTransparency="True"
WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown"
Title="MainWindow" Height="100" Width="200">
<Grid>
<Border BorderThickness="1" BorderBrush="Gray" CornerRadius="15,15,15,15" Background="Azure">
<!--你窗体中要显示的内容-->
<StackPanel Orientation="Horizontal">
<Button Content="查询" Height="28" HorizontalAlignment="Left" Name="btnQuery" VerticalAlignment="Center" Width="48" Click="btnQuery_Click" />
</StackPanel>
</Border>

</Grid>
</Window>

private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}

// 最大化、最小化
WindowState = WindowState.Maximized;
WindowState = WindowState.Minimized;

目前发现使用 .net core 会有问题。暂时先使用 .net framework 项目来做

项目右键

问题

ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分

原因请在解决方案资源管理器界面找到App.config文件打开。查看是否bindings项有多个,确实有多个话,删掉没有使用的binding相关的信息,只保留一个,或者后期手动代码指定选择哪一个。

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebServiceSoap" />
<binding name="WebServiceSoap1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.29.68.32/WebService.asmx" binding="basicHttpBinding"
bindingConfiguration="WebServiceSoap" contract="ServiceReference.WebServiceSoap"
name="WebServiceSoap" />
<endpoint address="http://10.29.68.32/WebService.asmx" binding="basicHttpBinding"
bindingConfiguration="WebServiceSoap1" contract="ServiceReference.WebServiceSoap"
name="WebServiceSoap1" />
</client>
</system.serviceModel>

//所以删掉一个节点既可也可以在页面引用的时候指定bindingConfiguration名字:
ServiceReference.WebServiceSoap web = new WebServiceSoapClient("WebServiceSoap");
阅读全文 »

更改服务的 url,只需要更改 App.config 里面的 地址 就可以了

调试的时候使用的地址和生产地址不同。所以调试时添加的地址在 Properties- Settings.settings-Settings.Designer.cs 里面,修改这里可以改默认连接的地址

fwHYUpload.WSHYUpload.LPSWebService hyService = new fwHYUpload.WSHYUpload.LPSWebService();
// 动态修改路径
hyService.Url = App.db.m_config[0].ServicPath;

.net core

添加 web service 服务。
项目上右键-add-connected service-Microsoft WCF Web Service Reference Provider
输入 url 点击 go 在下面配置 namespace 然后 注意是使用同步接口还是异步接口(默认)。

阅读全文 »

SOAP(Simple Object Access Protocol)是一种基于 XML 的 web 服务协议。SOAP 是平台独立的,不依赖于特定的语言,例如,我们可以使用 C#,C/C++,或者 Java 语言来实现 SOAP web 服务。

SOAP 的优点有:

  • WS Security:SOAP 使用 WS Security 作为其安全的标准,安全性较高。
  • 语言与平台独立:可以使用多种语言来实现 SOAP web 服务,且可以运行在多种平台上面。

SOAP 的缺点有:

  • 速度较慢:SOAP 使用 XML 作为数据传输的格式,web 服务每次读取数据时都需要对 XML 进行解析,速度较慢。另外,SOAP 规定了 web 服务需要遵循的许多规范,这导致在传输过程中消耗较多的网络带宽。
  • 依赖于 WSDL:除了使用 WSDL 外,SOAP 并不提供其他的机制来让其他应用程序发现服务。