-
C# 利用聚合函数MIN求销售额、利润最少的商品
C# 利用聚合函数MIN求销售额、利润最少的商品,具体来说是查询利润最少的商品信息,查询销售额最少的商品信息,查询结果将绑定显示于DataGridView数据网格控件中。
下面以查询销售额最少的商品信息为例,帖出具体的代码实现:
private DataTable GetMoney()
{
string P_Str_ConnectionStr = string.Format(//创建数据库连接字符串
@"server=WIN-GI7E47AND9RLS;database=db_TomeTwo;uid=sa;pwd=");
string P_Str_SqlStr = string.Format(//创建SQL查询字符串
"SELECT * FROM tb_Ware WHERE 销价 IN(SELECT MIN(销价) FROM tb_Ware)");
SqlDataAdapter P_SqlDataAdapter = new SqlDataAdapter(//创建数据适配器
P_Str_SqlStr, P_Str_ConnectionStr);
DataTable P_dt = new DataTable();//创建数据表
P_SqlDataAdapter.Fill(P_dt);//填充数据表
return P_dt;//返回数据表
}
其它部分的查询请下载本源码包。
- 2022-07-25 21:11:39下载
- 积分:1
-
Zigbee智能家居完整的源代码
Zigbee智能家居完整的源代码,含有终端和协调器工程并带有汉语注释。非常适合Zigbee开发。-Zigbee Smart Home complete source code, containing the terminal and the coordinator works with Chinese comments. Very suitable for the Zigbee development.
- 2022-03-05 18:50:08下载
- 积分:1
-
visual C# 基本的用户名密码登录判断示例
一个else if结构的用户登录判断模块,这个是基于C#版的,代码超简单,没有使用数据库,只是交待出了完整的判断过程,后续使用数据库时,原理基本差不多,只不过这里的用户名和密码是从数据库中读取出来,下面是基本的判断过程:
if (textBox1.Text == "")//判断是否输入的用户名
{
MessageBox.Show("用户名不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (textBox1.Text.ToLower() == "tsoft" && textBox2.Text == "111")//判断用户名和密码是否正确
{
MessageBox.Show("登录成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("用户名或密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}结合数据库实现时,先建立数据库连接,读取出用户名和密码赋值到变量中,然后使用上述代码即可判断。
- 2022-07-21 04:48:54下载
- 积分:1
-
C# 指定主机和端口发消息的实现
Visual C# 指定主机和端口发消息的实现例子,支持和远程主机发送消息,本例子可学习到很多实用的网络方法的用法,以下代码是本功能的核心实现:
richTextBox1.Text = string.Empty;
//实例化UdpClient对象
UdpClient udpclient = new UdpClient(Convert.ToInt32(textBox2.Text));
//调用UdpClient对象的Connect建立默认远程主机
udpclient.Connect(textBox1.Text, Convert.ToInt32(textBox2.Text));
//定义一个字节数组,用来存放发送到远程主机的信息
Byte[] sendBytes = Encoding.Default.GetBytes(textBox3.Text);
//调用UdpClient对象的Send方法将Udp数据报发送到远程主机
udpclient.Send(sendBytes, sendBytes.Length);
//实例化IPEndPoint对象,用来显示响应主机的标识
IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Any, 0);
//调用UdpClient对象的Receive方法获得从远程主机返回的Udp数据报
Byte[] receiveBytes = udpclient.Receive(ref ipendpoint);
//将获得的Udp数据报转换为字符串形式
string returnData = Encoding.Default.GetString(receiveBytes);
richTextBox1.Text = "接收到的信息:" + returnData.ToString();
//使用IPEndPoint对象的Address和Port属性获得响应主机的IP地址和端口号
richTextBox1.Text += "
这条信息来自主机" + ipendpoint.Address.ToString()
+ "上的" + ipendpoint.Port.ToString() + "端口";
//关闭UdpClient连接
- 2022-02-10 10:21:19下载
- 积分:1
-
7Zip
This file is part of SevenZipSharp. SevenZipSharp is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SevenZipSharp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with SevenZipSharp. If not, see .
- 2022-07-20 00:09:31下载
- 积分:1
-
C# 从RichTextBox 控件中提取文本内容
C# 从RichTextBox 控件中提取文本内容,并设置RichTextBox 控件中的字体大小-附完整源代码,
private void button1_Click(object sender, RoutedEventArgs e)
{//从RichTextBox 控件中提取文本内容
TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);
MessageBox.Show(MyText.Text, "RichTextBox控件中的文本内容",MessageBoxButton.OK);
}
private void button2_Click(object sender, RoutedEventArgs e)
{//设置RichTextBox 控件中的字体大小
TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);
MyText.ApplyPropertyValue(TextElement.FontSizeProperty, 36.00);
MyText.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
- 2022-09-21 17:55:02下载
- 积分:1
-
C# FileInfo获取文件的各种属性
C# 创建FileInfo对象,获取文件的各种属性,可以获取到以下的文件信息:创建时间、上次访问时间、上次写入时间、文件名称、完整目录、完整路径、是否只读、文件长度。
具体的实现过程:
textBox1.Text = openFileDialog1.FileName;
FileInfo finfo = new FileInfo(textBox1.Text); //实例化FileInfo对象
string strCTime, strLATime, strLWTime, strName, strFName, strDName, strISRead;
long lgLength;
strCTime = finfo.CreationTime.ToShortDateString(); //获取文件创建时间
strLATime = finfo.LastAccessTime.ToShortDateString(); //获取上次访问该文件的时间
strLWTime = finfo.LastWriteTime.ToShortDateString(); //获取上次写入文件的时间
strName = finfo.Name; //获取文件名称
strFName = finfo.FullName;//获取文件的完整目录
strDName = finfo.DirectoryName;//获取文件的完整路径
strISRead = finfo.IsReadOnly.ToString(); //获取文件是否只读
lgLength = finfo.Length; //获取文件长度
MessageBox.Show("文件信息:
创建时间:" + strCTime + " 上次访问时间:" + strLATime + "
上次写入时间:" + strLWTime + " 文件名称:" + strName + "
完整目录:" + strFName + "
完整路径:" + strDName + "
是否只读:" + strISRead + " 文件长度:" + lgLength);
以上代码段请写入一个按钮事件中,这样当用户单击按钮时,执行上述代码。
- 2023-02-14 12:35:03下载
- 积分:1
-
C#使用SqlDataAdapter对象的Fill方法填充DataSet
C#使用SqlDataAdapter对象的Fill方法填充DataSet,具体是调用DataSet的Copy方法复制DataSet中的内容,完成填充的功能:
private void Form1_Load(object sender, EventArgs e)
{
//实例化SqlConnection变量conn,连接数据库
conn = new SqlConnection("server=.;database=db_14;uid=sa;pwd=");
//创建一个SqlCommand对象
SqlCommand cmd = new SqlCommand("select * from tb_test", conn);
SqlDataAdapter sda = new SqlDataAdapter();//创建一个SqlDataAdapter对象
//设置SqlDataAdapter对象的SelectCommand属性,设置执行的SQL语句
sda.SelectCommand = cmd;
ds = new DataSet(); //实例化DataSet
sda.Fill(ds, "test");//使用SqlDataAdapter对象的Fill方法填充DataSet
dataGridView1.DataSource = ds.Tables[0];//设置dataGridView1的数据源
}
private void button1_Click(object sender, EventArgs e)
{
DataSet ds1 = ds.Copy();//调用DataSet的Copy方法复制ds中的内容
dataGridView2.DataSource = ds1.Tables[0];//将ds1作为dataGridView2的数据源
}
- 2022-11-04 09:50:03下载
- 积分:1
-
C#打造自己的智能屏幕取色工具
C#打造自己的智能屏幕取色工具,自动鼠标坐标点的颜色值,取色窗口会自动躲闪鼠标的位置,取色模块从一个继承自Image类的对象中创建Graphics对象,颜色值可以转换为十进制和十六进制,部分初始化源码如下:
[DllImport("gdi32")]
private static extern IntPtr CreateDC(
string lpszDriver, // 驱动名称
string lpszDevice, // 设备名称
string lpszOutput, // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
);
[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // 目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
int dwRop // 光栅的操作值
- 2022-02-26 10:33:42下载
- 积分:1
-
C# 以WrapWithOverflow方式、Wrap方式、NoWrap方式显示文字
C#以三种方式显示文字,分别以WrapWithOverflow方式、Wrap方式、NoWrap方式将文字显示在窗口中,这三种方式实现的代码请看以下代码:
private void button1_Click(object sender, RoutedEventArgs e)
{//WrapWithOverflow方式
this.MyTextBlock.TextWrapping = System.Windows.TextWrapping.WrapWithOverflow;
}
private void button3_Click(object sender, RoutedEventArgs e)
{//Wrap方式
this.MyTextBlock.TextWrapping = System.Windows.TextWrapping.Wrap;
}
private void button2_Click(object sender, RoutedEventArgs e)
{//NoWrap方式
this.MyTextBlock.TextWrapping = System.Windows.TextWrapping.NoWrap;
}
- 2022-01-25 20:43:04下载
- 积分:1