⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdlgstat.cs

📁 功能设计:平台管理、收费点维护、收费项目管理、缴费管理
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OracleClient;
using GlobleUtility;
using System.Data;

namespace Charge
{
	/// <summary>
	/// CdlgStat 的摘要说明。
	/// </summary>
	public class CdlgStat : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.ComboBox cbbItem;//收费项目下拉框
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.RadioButton rbtPay;//"交费记录"单选钮
		private System.Windows.Forms.RadioButton rbtArr;//"欠费记录"单选钮
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label lbtag;
		private System.Windows.Forms.Label lbMoney;//累计金额标签
		private System.Windows.Forms.Button btnStat;//"查看"按钮

		private System.Collections.ArrayList ArrItemID = null;
		private System.Windows.Forms.ListView lvUser;//用来装载项目ID号
		int itemid;//项目ID
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public CdlgStat()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
           ArrItemID=new ArrayList();
		}

		/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
			this.cbbItem = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.rbtPay = new System.Windows.Forms.RadioButton();
			this.rbtArr = new System.Windows.Forms.RadioButton();
			this.lvUser = new System.Windows.Forms.ListView();
			this.lbtag = new System.Windows.Forms.Label();
			this.lbMoney = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.btnStat = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.groupBox2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.cbbItem);
			this.groupBox1.Location = new System.Drawing.Point(0, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(424, 144);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "选择查看项目";
			// 
			// cbbItem
			// 
			this.cbbItem.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbbItem.Location = new System.Drawing.Point(136, 40);
			this.cbbItem.Name = "cbbItem";
			this.cbbItem.Size = new System.Drawing.Size(128, 20);
			this.cbbItem.TabIndex = 0;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(64, 40);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "收费项目";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.rbtArr);
			this.groupBox2.Controls.Add(this.rbtPay);
			this.groupBox2.Location = new System.Drawing.Point(0, 80);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(424, 64);
			this.groupBox2.TabIndex = 2;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "选择查看方式";
			// 
			// rbtPay
			// 
			this.rbtPay.Location = new System.Drawing.Point(56, 24);
			this.rbtPay.Name = "rbtPay";
			this.rbtPay.TabIndex = 0;
			this.rbtPay.Text = "交费记录";
			// 
			// rbtArr
			// 
			this.rbtArr.Location = new System.Drawing.Point(264, 24);
			this.rbtArr.Name = "rbtArr";
			this.rbtArr.TabIndex = 1;
			this.rbtArr.Text = "欠费记录";
			// 
			// lvUser
			// 
			this.lvUser.BackColor = System.Drawing.SystemColors.Info;
			this.lvUser.Location = new System.Drawing.Point(0, 192);
			this.lvUser.Name = "lvUser";
			this.lvUser.Size = new System.Drawing.Size(424, 152);
			this.lvUser.TabIndex = 1;
			// 
			// lbtag
			// 
			this.lbtag.Location = new System.Drawing.Point(40, 360);
			this.lbtag.Name = "lbtag";
			this.lbtag.TabIndex = 2;
			this.lbtag.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lbMoney
			// 
			this.lbMoney.Location = new System.Drawing.Point(152, 360);
			this.lbMoney.Name = "lbMoney";
			this.lbMoney.TabIndex = 3;
			this.lbMoney.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(264, 360);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(32, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "元";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// btnStat
			// 
			this.btnStat.Location = new System.Drawing.Point(168, 160);
			this.btnStat.Name = "btnStat";
			this.btnStat.TabIndex = 5;
			this.btnStat.Text = "查看";
			this.btnStat.Click += new System.EventHandler(this.btnStat_Click);
			// 
			// CdlgStat
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(424, 397);
			this.Controls.Add(this.btnStat);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.lbMoney);
			this.Controls.Add(this.lbtag);
			this.Controls.Add(this.lvUser);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "CdlgStat";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "统计";
			this.Load += new System.EventHandler(this.CdlgStat_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		private void CdlgStat_Load(object sender, System.EventArgs e)
		{
			//页面载入事件导入当前在用的收费项目
			System.Data.OracleClient.OracleConnection myconn = Connection.DBConnection;
			if(myconn==null)
			{
				return;
			}
			string mysql="select ItemID,ItemName from Charge_Items where useable=1";
			OracleCommand mycommand=new OracleCommand(mysql, myconn);
			OracleDataReader myreader=null;
			try
			{
				myreader = mycommand.ExecuteReader();
			}
			catch(Exception ee)
			{
				MessageBox.Show("数据库查询出错,消息如下:\r\n"+ee.Message,"消息:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return;
			}
			ArrItemID.Clear();
			while(myreader.Read())
			{
				ArrItemID.Add(myreader.GetInt32(0));
				cbbItem.Items.Add(myreader.GetString(1));
			}
			myreader.Close();
			myreader.Dispose();
			myconn.Close();
			//默认查看交费
			rbtPay.Checked=true;
		}
        //"统计"按钮单击事件函数
		private void btnStat_Click(object sender, System.EventArgs e)
		{
			if(cbbItem.SelectedIndex<0)//未选择项目
			{
				MessageBox.Show("未选择项目!");
				return ;
            }
			else
			{
				itemid=Convert.ToInt32(ArrItemID[cbbItem.SelectedIndex]);
                Init();
				if(rbtPay.Checked)//查看交费记录
				{
					if(!ViewPay(itemid,ref lvUser))
					{
						MessageBox.Show("数据库操作出错!");
						return;
					}
					
				}
				else//查看欠费记录
				{
					if(!ViewArr(itemid,ref lvUser))
					{
						MessageBox.Show("数据库操作出错!");
						return;
					}
				}
				
              
			}
		}
		//在ListView中显示交费记录
		private bool ViewPay(int itemid,ref ListView lv)
		{
			System.Data.OracleClient.OracleConnection myconn = Connection.DBConnection;
			if(myconn==null)
			{
				return false;
			}
			string mysql="select username,decode(usertype,1,'学生',2,'教工') type, money/100 money "+
				         "from charge_payrecord "+
				         " where itemid="+itemid;
			OracleCommand mycommand=new OracleCommand(mysql, myconn);
			OracleDataReader myreader=null;
			try
			{
				myreader=mycommand.ExecuteReader();
			}
			catch(Exception ee)
			{
				MessageBox.Show("数据库查询出错,消息如下:\r\n"+ee.Message,"消息:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return false;
			}
			//逐项加入ListView
			double sum=0;//项目累计收费金额
			lv.BeginUpdate();//防止闪烁
			//往ListView中逐条加入交费记录
			while(myreader.Read())
			{
				ListViewItem lvi=null;
				lvi=lv.Items.Add(myreader.GetString(0));//用户姓名
				lvi.SubItems.Add(myreader.GetString(1));//用户类别
				lvi.SubItems.Add(myreader.GetDouble(2).ToString());//交费金额
                double money=myreader.GetDouble(2);
				sum=sum+money;
			}
			lv.EndUpdate();
			myreader.Close();
			myreader.Dispose();
			myconn.Close();
			lbMoney.Text=sum.ToString();
			return true;

		}
		//在ListView中显示欠费记录
		private bool ViewArr(int itemid,ref ListView lv)
		{
			System.Data.OracleClient.OracleConnection myconn = Connection.DBConnection;
			if(myconn==null)
			{
				return false;
			}
			string mysql="select object.username,decode(object.userclass,1,'学生',2,'教工') type,relation.money/100 money"+
				         " from charge_object object,charge_io relation"+
				        " where relation.itemid="+itemid+" and relation.charged=0"+
				        " and relation.userid=object.userid";
			OracleCommand mycommand=new OracleCommand(mysql, myconn);
			OracleDataReader myreader=null;
			try
			{
				myreader=mycommand.ExecuteReader();
			}
			catch(Exception ee)
			{
				MessageBox.Show("数据库查询出错,消息如下:\r\n"+ee.Message,"消息:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return false;
			}
			//逐项加入ListView
			double sum=0;
			lv.BeginUpdate();
			while(myreader.Read())
			{
				ListViewItem lvi=null;
				lvi=lv.Items.Add(myreader.GetString(0));
				lvi.SubItems.Add(myreader.GetString(1));
				lvi.SubItems.Add(myreader.GetDouble(2).ToString());
				double money=myreader.GetDouble(2);
				sum=sum+money;
			}
			lv.EndUpdate();
			myreader.Close();
			myreader.Dispose();
			myconn.Close();
			lbMoney.Text=sum.ToString();
			return true;
		}
		//初始化ListView显示格式
		private void Init()
		{
			//设置ListView控件显示属性
			lvUser.BeginUpdate();//防止闪烁
			lvUser.FullRowSelect =true;  //整行选择
			lvUser.HideSelection = false; //当listview没有焦点时,选定项是否仍然突出显示
			lvUser.View=View.Details;  
			lvUser.GridLines=true; 
			lvUser.Clear();
            string Type;
			if(rbtPay.Checked)//交费
			{
				Type="交费金额";
				lbtag.Text="累计交费";
			}
			else  //欠费
			{
				Type="欠费金额";
				lbtag.Text="累计欠费";
			}
			string[] Field = {"姓名","类别",Type};
			for (int i = 0; i <= 2; i++)
			{
				lvUser.Columns.Add(Field[i], 80, HorizontalAlignment.Center);
			}
			//设定各列长度
			lvUser.Columns[0].Width =80;
			lvUser.Columns[1].Width =100;
			lvUser.Columns[2].Width =80;
			lvUser.EndUpdate();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -