📄 盘点.cs
字号:
#region Using directives
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
#endregion
namespace AIFACE
{
public partial class 盘点 : Form
{
private SqlCeConnection connection = null;
private SqlCeCommand command = null;
private SqlCeResultSet resultSet = null;
private String DefaultUnit = "0000 全部";
public 盘点()
{
InitializeComponent();
if (null == this.connection)
{
string strCon = GetConnectionString();
this.connection = new SqlCeConnection(strCon);
this.connection.Open();
};
}
private string GetConnectionString()
{
return String.Format(System.Globalization.CultureInfo.InvariantCulture,
@"Data Source = {0}\AIFACE.sdf;password=wiseyes", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase));
}
/// <summary>
/// Displays the Details of a SqlCeException
/// </summary>
public static void ShowErrors(SqlCeException e)
{
SqlCeErrorCollection errorCollection = e.Errors;
StringBuilder bld = new StringBuilder();
Exception inner = e.InnerException;
foreach (SqlCeError err in errorCollection)
{
bld.Append("\n Error Code: " + err.HResult.ToString("X",
System.Globalization.CultureInfo.CurrentCulture));
bld.Append("\n Message : " + err.Message);
bld.Append("\n Minor Err.: " + err.NativeError);
bld.Append("\n Source : " + err.Source);
foreach (int numPar in err.NumericErrorParameters)
{
if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);
}
foreach (string errPar in err.ErrorParameters)
{
if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar);
}
}
MessageBox.Show(bld.ToString());
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{
if (TextBox1.Text.Length == 8)
{
try
{
String substr = TextBox1.Text.Substring(0, 8);
Boolean onRow = this.resultSet.Seek(DbSeekOptions.FirstEqual, substr);
if (onRow)
{
this.resultSet.Read();
仪器编号.Text = this.resultSet.GetString(0);
仪器名称.Text = this.resultSet.GetString(1);
分类号.Text = this.resultSet.GetString(2);
分类名称.Text = this.resultSet.GetString(3);
使用部门.Text = this.resultSet.GetString(4);
安置地点.Text = this.resultSet.GetString(5);
单价.Text = this.resultSet.GetString(6);
数量.Text = this.resultSet.GetString(7);
总价.Text = this.resultSet.GetString(8);
if (this.resultSet.GetBoolean(9))
{
MessageBox.Show("您当前扫描的固定资产已经盘点过!");
//this.resultSet.SetBoolean(10, true);
//this.resultSet.Update();
}
else
{
this.resultSet.SetBoolean(9, true);
this.resultSet.Update();
}
this.resultSet.SetString(12, comboBox1.Text.Substring(0, 4));
this.resultSet.Update();
}
else
MessageBox.Show("没有找到该资产。");
}
catch (InvalidCastException ex)
{
}
catch (SqlCeException ex)
{
MessageBox.Show("没有找到该资产,或发生了其他错误。");
}
TextBox1.SelectAll();
}
}
private void menuItem1_Click(object sender, EventArgs e)
{
//同步
this.DefaultUnit = "0000 全部";
同步 同步 = new 同步();
同步.Visible = true;
}
private void menuItem3_Click(object sender, EventArgs e)
{
//浏览
浏览 浏览 = new 浏览();
浏览.Visible = true;
}
private void menuItem4_Click(object sender, EventArgs e)
{
//关于
关于 关于 = new 关于();
关于.Visible = true;
}
private void 盘点_GotFocus(object sender, EventArgs e)
{
String query = "sb_zjk";
this.command.CommandText = query;
command.CommandType = CommandType.TableDirect;
command.IndexName = "PK_sb_zjk";
ResultSetOptions options = ResultSetOptions.Scrollable | ResultSetOptions.Sensitive | ResultSetOptions.Updatable;
if (this.resultSet.IsClosed)
this.resultSet = this.command.ExecuteResultSet(options);
else
{
this.resultSet.Close();
this.resultSet = this.command.ExecuteResultSet(options);
}
}
private void 盘点_Load(object sender, EventArgs e)
{
this.MinimizeBox = false;
仪器编号.Text = "";
仪器名称.Text = "";
分类号.Text = "";
分类名称.Text = "";
使用部门.Text = "";
安置地点.Text = "";
单价.Text = "";
数量.Text = "";
总价.Text = "";
try
{
if (null != this.resultSet)
this.resultSet.Dispose(); //释放Dataset
this.command = this.connection.CreateCommand();
String query = "sb_zjk";
this.command.CommandText = query;
command.CommandType = CommandType.TableDirect;
command.IndexName = "PK_sb_zjk";
ResultSetOptions options = ResultSetOptions.Scrollable | ResultSetOptions.Sensitive | ResultSetOptions.Updatable;
this.resultSet = this.command.ExecuteResultSet(options);
}
catch (InvalidOperationException ex)
{
MessageBox.Show(String.Format(System.Globalization.CultureInfo.CurrentCulture,
"连接数据库发生错误: \n {0}", ex.ToString()));
}
catch (SqlCeException ex)
{
ShowErrors(ex);
}
}
private void 盘点_Activated(object sender, EventArgs e)
{
comboBox1.Items.Clear();
SqlCeResultSet presultSet = null;
SqlCeCommand pcommand = null;
pcommand = this.connection.CreateCommand();
String query = "dm_sydw";
pcommand.CommandText = query;
pcommand.CommandType = CommandType.TableDirect;
ResultSetOptions options = ResultSetOptions.Scrollable | ResultSetOptions.Sensitive | ResultSetOptions.Updatable;
presultSet = pcommand.ExecuteResultSet(options);
while (presultSet.Read())
{
try
{
comboBox1.Items.Add(presultSet.GetString(0) + " " + presultSet.GetString(1));
}
catch (Exception ex)
{
};
}
comboBox1.Text = this.DefaultUnit;
presultSet.Dispose();
pcommand.Dispose();
TextBox1.Focus();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DefaultUnit = comboBox1.Text;
TextBox1.Focus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -