📄 sellasset.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace AssetManagement
{
/// <summary>
/// sellAsset 的摘要说明。
/// </summary>
public class sellAsset : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.CheckedListBox checkedListBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public sellAsset()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.AllowDrop = true;
this.listBox1.HorizontalScrollbar = true;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(272, 40);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(176, 292);
this.listBox1.TabIndex = 1;
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(200, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 2;
this.button1.Text = "> >";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(168, 408);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "确定";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(272, 408);
this.button3.Name = "button3";
this.button3.TabIndex = 4;
this.button3.Text = "取消";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(368, 408);
this.button4.Name = "button4";
this.button4.TabIndex = 5;
this.button4.Text = "退出";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// checkedListBox1
//
this.checkedListBox1.AllowDrop = true;
this.checkedListBox1.CheckOnClick = true;
this.checkedListBox1.HorizontalScrollbar = true;
this.checkedListBox1.Location = new System.Drawing.Point(8, 40);
this.checkedListBox1.Name = "checkedListBox1";
this.checkedListBox1.Size = new System.Drawing.Size(184, 292);
this.checkedListBox1.TabIndex = 0;
//
// sellAsset
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(456, 462);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.checkedListBox1);
this.Name = "sellAsset";
this.Text = "sellAsset";
this.Load += new System.EventHandler(this.sellAsset_Load);
this.ResumeLayout(false);
}
#endregion
private void sellAsset_Load(object sender, System.EventArgs e)
{
string str = "";
Connection s = new Connection();
SqlConnection conn = new SqlConnection(s.getConnectionString);
conn.Open();
string str1 = "select * from asset where statusNo != '6'";
SqlCommand cmd = new SqlCommand(str1,conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
str = "资产号" + Convert.ToString(dr["assetNo"]) + "当前价值" + Convert.ToString(dr["currentValue"]) + "买进价格" + Convert.ToString(dr["purchasePrice"]);
this.checkedListBox1.Items.Add(str);
}
this.button2.Enabled = false;
dr.Close();
conn.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
string s = "";
//string s1 = "";
this.listBox1.Items.Clear();
bool check = false;
for (int i = 0; i < this.checkedListBox1.Items.Count;i++)
{
if (checkedListBox1.GetItemChecked(i))
{
s = this.checkedListBox1.Items[i].ToString();
if (!this.listBox1.Items.Contains(s))
{
this.listBox1.Items.Add(s);
check = true;
}
}
}
if (check)
{
this.button2.Enabled = true;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
string [] list =new string[20];
//string s = "";
string s1 = "";
bool check = false;
Connection trt= new Connection();
SqlConnection conn = new SqlConnection(trt.getConnectionString);
conn.Open();
int length = 0;
for (int i = 0; i < this.listBox1.Items.Count; i++)
{
string s2= "";
s1 = this.listBox1.Items[i].ToString();
for (int j = 3;j < s1.Length;j++)
{
if (s1[j] == '当')
break;
else
{
s2 += s1[j];
}
}
list[i] = s2;
length = i;
}
//MessageBox.Show(s);
//string sqlstr = "update asset set statusNo = '6' where assetNo = '" + s + "'";
//SqlCommand cmd = new SqlCommand(sqlstr,conn);
for (int j = 0;j <= length ;j++)
{
string sqlstr = "update asset set statusNo = '6' where assetNo = '" + list[j].ToString() + "'";
SqlCommand cmd = new SqlCommand(sqlstr,conn);
try
{
cmd.ExecuteNonQuery();
check = true;
}
catch
{
MessageBox.Show("error");
check = false;
}
}
if (check)
{
this.checkedListBox1.Items.Clear();
string add = "";
string sqlstr1 = "select * from asset where statusNo != '6'";
SqlCommand cmdquery = new SqlCommand(sqlstr1,conn);
SqlDataReader dr = cmdquery.ExecuteReader();
while (dr.Read())
{
add = "资产号" + Convert.ToString(dr["assetNo"]) + "当前价值" + Convert.ToString(dr["currentValue"]) + "买进价格" + Convert.ToString(dr["purchasePrice"]);
this.checkedListBox1.Items.Add(add);
}
dr.Close();
this.button2.Enabled = false;
this.listBox1.Items.Clear();
for (int k = 0;k < this.checkedListBox1.Items.Count;k++)
{
this.checkedListBox1.SetItemChecked(k,false);
}
}
conn.Close();
} //s = "";
private void button3_Click(object sender, System.EventArgs e)
{
this.listBox1.Items.Clear();
for (int k = 0;k < this.checkedListBox1.Items.Count;k++)
{
this.checkedListBox1.SetItemChecked(k,false);
}
this.button2.Enabled = false;
}
private void button4_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -