Click here to Skip to main content
15,917,455 members
Home / Discussions / C#
   

C#

 
AnswerRe: Arraylist Goes Null after Passing information back to Main Page from Window. Pin
PDTUM24-May-10 9:01
PDTUM24-May-10 9:01 
QuestionParsing plain Win32 PE File (Exe/DLL) in C#.NET Pin
glitteringsound23-May-10 4:30
glitteringsound23-May-10 4:30 
AnswerRe: Parsing plain Win32 PE File (Exe/DLL) in C#.NET Pin
Luc Pattyn23-May-10 5:07
sitebuilderLuc Pattyn23-May-10 5:07 
AnswerRe: Parsing plain Win32 PE File (Exe/DLL) in C#.NET Pin
Dave Kreskowiak23-May-10 18:22
mveDave Kreskowiak23-May-10 18:22 
Questionlistview last sorting [modified] Pin
teknolog12323-May-10 4:02
teknolog12323-May-10 4:02 
AnswerRe: listview last sorting Pin
Dr.Walt Fair, PE23-May-10 4:52
professionalDr.Walt Fair, PE23-May-10 4:52 
AnswerRe: listview last sorting Pin
Abhinav S23-May-10 4:59
Abhinav S23-May-10 4:59 
Questiondatabase connection problems about C# ,unable to connect database Pin
Make Up Forever23-May-10 2:34
Make Up Forever23-May-10 2:34 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 用户管理
{
public partial class ChangestaffPwd : Form
{
public int flag;
public string str;
public ChangestaffPwd()
{
InitializeComponent();
}
//-----------在DataGridView控件下面textBox控件显示内容-----------
private void show()
{
try
{
this.textBox1.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
this.textBox2.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show("错误描述如下:\r\n" + ex.Message, "不能对列进行排序");
}
}
//---------------DataGridView控件随着选中行的不同,显示不同的内容-------------------
private void alternate()
{
if (this.dataGridView1.Rows.Count != 0)
{
for (int i = 0; i < this.dataGridView1.Rows.Count; )
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Orange;
i += 2;
}
}
}
private void ChangestaffPwd_Load(object sender, EventArgs e)
{
SqlConnection con = DBCon.createCon();
SqlDataAdapter sda = new SqlDataAdapter("select StaffID as 用户名,Password as 密码 from Staff ", con);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
show();
}

private void button3_Click(object sender, EventArgs e)
{
if (button3.Text == "添加")
{
this.textBox1.Enabled = true;
if ((str = this.textBox1.Text.ToString()) != "")
{
if (MessageBox.Show("您确定要添加本条记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
flag = 1;
MessageBox.Show("请输入用户名和密码并且按确定按钮,才能添加成功!");
return;
}
}

}
}
private void button2_Click(object sender, EventArgs e)
{
if (button2.Text == "修改")
{
if ((str = this.textBox1.Text.ToString()) != "")
{
if (MessageBox.Show("您确定要修改本条记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
flag = 2;
MessageBox.Show("请按确定按钮,才能修改成功!");
return;
}
}
}
}
private void button4_Click(object sender, EventArgs e)
{
if (button4.Text == "删除")
{
if ((str = this.textBox1.Text.ToString()) != "")
{
if (MessageBox.Show("您确定要删除本条记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
flag = 3;
MessageBox.Show("请按确定按钮,才能删除成功!");
return;
}
}
}
}
private void button5_Click(object sender, EventArgs e)
{
if (button5.Text == "确定")
{
if (flag == 1)
{
SqlConnection con = DBCon.createCon();
con.Open();
//在原表中新建一个新行,然后再数据添加到新行中
SqlCommand cmd = new SqlCommand("insert into Staff values(@StaffID,@Password)", con);
cmd.Parameters.Add("@StaffID", SqlDbType.Char, 10).Value = textBox1.Text;
cmd.Parameters.Add("@Password ", SqlDbType.Char, 20).Value = textBox2.Text;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter sda = new SqlDataAdapter("select StaffID as 用户名,Password as 密码 from Staff", con);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
this.textBox1.Enabled = false;
MessageBox.Show("添加记录成功!");
this.textBox1.Enabled = false;
try
{
show();
}
catch (Exception ex)
{
MessageBox.Show("错误描述如下:\r\n" + ex.Message, "没有记录显示!");
}
flag = 0;
}
if (flag == 2 && str != "")
{
SqlConnection con = DBCon.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("update Staff set Password ='" + textBox2.Text.ToString() + "' where UserName='" + str + "'", con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter sda = new SqlDataAdapter("select StaffID as 用户名,Password as 密码 from Staff", con);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
try
{
show();
}
catch (Exception ex)
{
MessageBox.Show("错误描述如下:\r\n" + ex.Message, "没有记录显示!");
}
MessageBox.Show("修改成功!");
flag = 0;
}
if (flag == 3 && str != "")
{
SqlConnection con = DBCon.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from Staff where StaffID='" + str + "'", con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter sda = new SqlDataAdapter("select Staff as 用户名,Password as 密码 from Staff", con);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
try
{
show();
}
catch (Exception ex)
{
MessageBox.Show("错误描述如下:\r\n" + ex.Message, "没有记录显示!");
}
MessageBox.Show("删除成功!");
}
flag = 0;
}
}
private void button10_Click(object sender, EventArgs e)
{
if (button10.Text == "退出")
{

this.Close(); //退出普通用户密码管理维护

}
}
private void dataGridView1_SelectionChanged_1(object sender, EventArgs e)
{
show();
}
private void button1_Click(object sender, EventArgs e)
{

SqlConnection con = DBCon.createCon();
SqlDataAdapter sda = new SqlDataAdapter("select StaffID as 用户名,Password as 密码 from Staff where Username like'" + "%'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
try //有时找不到匹配的记录,有异常
{
show();
}
catch (Exception ex) //对异常进行处理
{
MessageBox.Show("错误描述如下:\r\n" + ex.Message, "没有找到匹配的记录");
return;
}
}


}


}
AnswerRe: database connection problems about C# ,unable to connect database Pin
Abhinav S23-May-10 2:35
Abhinav S23-May-10 2:35 
AnswerRe: database connection problems about C# ,unable to connect database Pin
Luc Pattyn23-May-10 2:38
sitebuilderLuc Pattyn23-May-10 2:38 
QuestionRead access on class local fields from multiple threads Pin
Chesnokov Yuriy22-May-10 23:36
professionalChesnokov Yuriy22-May-10 23:36 
AnswerRe: Read access on class local fields from multiple threads Pin
DaveyM6923-May-10 0:47
professionalDaveyM6923-May-10 0:47 
QuestionBackgroundWorker.IsBusy failure!? Pin
Chesnokov Yuriy22-May-10 23:32
professionalChesnokov Yuriy22-May-10 23:32 
AnswerRe: BackgroundWorker.IsBusy failure!? Pin
DaveyM6923-May-10 0:58
professionalDaveyM6923-May-10 0:58 
QuestionRe: BackgroundWorker.IsBusy failure!? Pin
Chesnokov Yuriy23-May-10 1:32
professionalChesnokov Yuriy23-May-10 1:32 
AnswerRe: BackgroundWorker.IsBusy failure!? Pin
DaveyM6923-May-10 2:10
professionalDaveyM6923-May-10 2:10 
AnswerRe: BackgroundWorker.IsBusy failure!? Pin
Chesnokov Yuriy23-May-10 4:04
professionalChesnokov Yuriy23-May-10 4:04 
GeneralRe: BackgroundWorker.IsBusy failure!? Pin
DaveyM6923-May-10 4:24
professionalDaveyM6923-May-10 4:24 
GeneralRe: BackgroundWorker.IsBusy failure!? Pin
Luc Pattyn23-May-10 5:09
sitebuilderLuc Pattyn23-May-10 5:09 
AnswerRe: BackgroundWorker.IsBusy failure!? Pin
DaveyM6923-May-10 3:36
professionalDaveyM6923-May-10 3:36 
AnswerRe: BackgroundWorker.IsBusy failure!? Pin
Luc Pattyn23-May-10 2:24
sitebuilderLuc Pattyn23-May-10 2:24 
GeneralRe: BackgroundWorker.IsBusy failure!? Pin
Chesnokov Yuriy23-May-10 3:55
professionalChesnokov Yuriy23-May-10 3:55 
GeneralRe: timer ticks overlap [modified] Pin
Luc Pattyn23-May-10 4:23
sitebuilderLuc Pattyn23-May-10 4:23 
QuestionPreventing DataGridView column from auto-resizing when double-clicking the column header divider Pin
eyalbi00722-May-10 22:23
eyalbi00722-May-10 22:23 
QuestionAnybody? Please, I'm so stuck here... Pin
eyalbi00723-May-10 3:53
eyalbi00723-May-10 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.