C#的查看系统

using  System.Drawing;
using  System.Collections;
using  System.ComponentModel;
using  System.Windows.Forms;
using  System.Data;
using  System.Data.SqlClient;

namespace  Example_1
{
    
/// <summary>
    
/// Summary description for Form1.
    
/// </summary>

    public class frmProject : System.Windows.Forms.Form
    
{
        
private System.Windows.Forms.Button btnCreate;
        
private System.Windows.Forms.Button btnClose;
        
private System.Windows.Forms.ListBox lstProjectValues;
        
private System.Windows.Forms.Button btnView;
        
/// <summary>
        
/// Required designer variable.
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
//Data related variables
        private DataSet objDataSet;
        
private DataTable objProjectTable;
        
private DataRow objDataRow;
        
private System.Windows.Forms.HelpProvider HelpForForm;
        
private System.Windows.Forms.Button btnRemove;
        
        
public frmProject()
        
{
            
//
            
// Required for Windows Form Designer support
            
//
            InitializeComponent();

            
//
            
// TODO: Add any constructor code after InitializeComponent call
            
//
        }


        
/// <summary>
        
/// Clean up any resources being used.
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if (components != null
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }


        
Windows Form Designer generated code

        
/// <summary>
        
/// The main entry point for the application.
        
/// </summary>

        [STAThread]
        
static void Main() 
        
{
            Application.Run(
new frmProject());
        }


        
private void btnCreate_Click(object sender, System.EventArgs e)
        
{
            
//create dataset
            objDataSet = new DataSet();
            
//create a datatable
            objProjectTable = new DataTable("Project");
            
//adding the columns
            objProjectTable.Columns.Add(new DataColumn("ProjectID",typeof(int)));

            
//adding the primary key
            objProjectTable.PrimaryKey = new DataColumn[1]{objProjectTable.Columns["ProjectID"]};
            objProjectTable.Columns.Add(
new DataColumn("ProjectName",typeof(string)));
            objProjectTable.Columns.Add(
new DataColumn("ProjectDescription",typeof(string)));
            objProjectTable.Columns.Add(
new DataColumn("ClientID",typeof(string)));
            objProjectTable.Columns.Add(
new DataColumn("EmployeeID",typeof(string)));

            
//adding the table to dataset
            objDataSet.Tables.Add(objProjectTable);
        
            
//creating a new row
            objDataRow = objProjectTable.NewRow();
            objDataRow[
"ProjectID"]=101;
            objDataRow[
"ProjectName"]="Visual C# Inventory Project";
            objDataRow[
"ProjectDescription"]="For ABC Compnay";
            objDataRow[
"ClientID"]="C101";
            objDataRow[
"EmployeeID"]="E01";

            
//adding the row to the table
            objProjectTable.Rows.Add(objDataRow);
            
            
//creating a new row
            objDataRow = objProjectTable.NewRow();
            objDataRow[
"ProjectID"]=102;
            objDataRow[
"ProjectName"]="Funding Project";
            objDataRow[
"ProjectDescription"]="Developed in EJB, STRUTS";
            objDataRow[
"ClientID"]="C102";
            objDataRow[
"EmployeeID"]="E03";
            
//adding the row to the table
            objProjectTable.Rows.Add(objDataRow);

            MessageBox.Show(
"Project Table created with "+objProjectTable.Rows.Count.ToString() + " rows","Total Rows");

            
//enabling and disabling the controls
            this.btnView.Enabled = true;
            
this.lstProjectValues.Enabled = true;
            
this.btnCreate.Enabled = false;
            
        }


        
private void btnClose_Click(object sender, System.EventArgs e)
        
{
            
this.Close();
        }


        
private void btnView_Click(object sender, System.EventArgs e)
        
{
            
//displaying the rows in the List Box
            foreach(DataRow row in objDataSet.Tables["Project"].Rows)
            
{
                
foreach(DataColumn column in objDataSet.Tables["Project"].Columns)
                
{
                    
this.lstProjectValues.Items.Add(row[column].ToString());
                }

                
this.lstProjectValues.Items.Add("");
            }


            
this.btnView.Enabled=false;
            
this.btnRemove.Enabled = true;
            
        }


        
private void btnRemove_Click(object sender, System.EventArgs e)
        
{
            objProjectTable.Rows.Remove(objDataSet.Tables[
0].Rows[0]);
            
this.lstProjectValues.Items.Clear();
            MessageBox.Show(
"Project Table has "+objProjectTable.Rows.Count.ToString() + " rows",    " Total Rows");
            btnView_Click(sender,e);
        }

    }

}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值