using System;
namespace TSMS.Model
{
/// <summary>
/// 描述员工的在职状态
/// </summary>
[Serializable]
public partial class tb_potential
{
public tb_potential()
{}
#region Model
private int _potstuid;
private string _stuname;
private string _stupho;
private string _stuparentpho;
private string _stuadress;
private string _sturemarks;
/// <summary>
///
/// </summary>
public int potstuid
{
set{ _potstuid=value;}
get{return _potstuid;}
}
/// <summary>
///
/// </summary>
public string stuname
{
set{ _stuname=value;}
get{return _stuname;}
}
/// <summary>
///
/// </summary>
public string stupho
{
set{ _stupho=value;}
get{return _stupho;}
}
/// <summary>
///
/// </summary>
public string stuparentpho
{
set{ _stuparentpho=value;}
get{return _stuparentpho;}
}
/// <summary>
///
/// </summary>
public string stuadress
{
set{ _stuadress=value;}
get{return _stuadress;}
}
/// <summary>
///
/// </summary>
public string sturemarks
{
set{ _sturemarks=value;}
get{return _sturemarks;}
}
#endregion Model
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMS.Model;
using TSMS.Common;
using System.Data.SqlClient;
using System.Data;
namespace TSMS.DAL
{
public class Dalpotential:IDalData<tb_potential>
{
SqlHelper _sqlhelper = new SqlHelper();
/// <summary>
/// 添加潜在学生
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool InsertItem(tb_potential t)
{
SqlParameter[] parameters =
{
new SqlParameter("@stuname",SqlDbType.NVarChar,12),
new SqlParameter("@stupho",SqlDbType.VarChar,11),
new SqlParameter("@stuparentpho",SqlDbType.VarChar,11),
new SqlParameter("@stuadress",SqlDbType.NVarChar,50),
new SqlParameter("@sturemarks",SqlDbType.NVarChar,120)
};
parameters[0].Value = t.stuname;
parameters[1].Value = t.stupho;
parameters[2].Value = t.stuparentpho;
parameters[3].Value = t.stuadress;
parameters[4].Value = t.sturemarks;
string sql = @"INSERT INTO [tb_potential] ([stuname],[stupho],[stuparentpho],[stuadress],[sturemarks])
VALUES (@stuname,@stupho,@stuparentpho,@stuadress,@sturemarks)";
return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text, parameters);
}
/// <summary>
/// 修改潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool UpdateItem(tb_potential t)
{
SqlParameter[] parameters =
{
new SqlParameter("@stuname",SqlDbType.NVarChar,12),
new SqlParameter("@stupho",SqlDbType.VarChar,11),
new SqlParameter("@stuparentpho",SqlDbType.VarChar,11),
new SqlParameter("@stuadress",SqlDbType.NVarChar,50),
new SqlParameter("@sturemarks",SqlDbType.NVarChar,120),
new SqlParameter("@potstuid",SqlDbType.Int)
};
parameters[0].Value = t.stuname;
parameters[1].Value = t.stupho;
parameters[2].Value = t.stuparentpho;
parameters[3].Value = t.stuadress;
parameters[4].Value = t.sturemarks;
parameters[5].Value = t.potstuid;
string sql = @"UPDATE tb_potential SET stuname=@stuname,stupho =@stupho,
stuparentpho= @stuparentpho,stuadress =@stuadress,sturemarks = @sturemarks
WHERE potstuid = @potstuid";
return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text, parameters);
}
/// <summary>
/// 删除潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool DeleteItem(string strSelected)
{
strSelected = strSelected.Trim(new char[] { ',' });//重要细节,慢慢研究
string sql = @"DELETE FROM [TSMS].[dbo].[tb_potential]
WHERE [potstuid] in (" + strSelected + ")";
return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text);
}
public List<tb_potential> GetListModel()
{
throw new NotImplementedException();
}
public tb_potential GetModel(int id)
{
throw new NotImplementedException();
}
/// <summary>
/// 分页按钮
/// </summary>
/// <param name="condition"></param>
/// <param name="pageCount"></param>
/// <returns></returns>
public DataTable GetAllVacation(Condition condition, out int pageCount)
{
SqlParameter[] parameters =
{
new SqlParameter("@pageSize",SqlDbType.Int),
new SqlParameter("@pageIndex",SqlDbType.Int),
new SqlParameter("@tableName",SqlDbType.VarChar,50),
new SqlParameter("@priKey",SqlDbType.VarChar,20),
new SqlParameter("@condition",SqlDbType.VarChar,2000),
new SqlParameter("@sort",SqlDbType.VarChar,4),
new SqlParameter("@pageCount",SqlDbType.Int )
};
parameters[0].Value = condition.PageSize;
parameters[1].Value = condition.PageIndex;
parameters[2].Value = condition.TableName;
parameters[3].Value = condition.Prikye;
parameters[4].Value = condition.Condtion;
parameters[5].Value = condition.Pagesort;
parameters[6].Direction = ParameterDirection.Output;
string sql = @"exec proc_CommonSinglePage @pageSize,@pageIndex,@tableName,@priKey,@condition,@sort,@pagecount out";
DataTable db = _sqlhelper.GetDataTable(sql, CommandType.Text, parameters);
pageCount = (int)parameters[6].Value;
return db;
}
public bool DeleteItem(tb_potential t)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMS.DAL;
using TSMS.Model;
using System.Data;
namespace TSMS.BLL
{
public class Bllpotential
{
private Dalpotential dalpot = new Dalpotential();
/// <summary>
/// 新增一个潜在学生
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool InsertItem(tb_potential t)
{
return dalpot.InsertItem(t);
}
/// <summary>
/// 更新潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool UpdateItem(tb_potential t)
{
return dalpot.UpdateItem(t);
}
/// <summary>
/// 删除潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool DeleteItem(string strSelected)
{
return dalpot.DeleteItem(strSelected);
}
public DataTable GetAllVacation(Condition condition, out int pageCount)
{
return dalpot.GetAllVacation(condition, out pageCount);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;//对于SQLServer数据库的封装操作
using System.Collections;//因为要用到集合的存储,所以我们采用的是集合的命名空间
using TSMS.Model;
using TSMS.BLL;
namespace TSMS
{
public partial class Faddpotstus : DevExpress.XtraEditors.XtraForm
{
int pageCount = 0;//总页数
int pageIndex = 1;//首页
private int row = 0;//点击的行号
private int pronum = 0;//点击的行号对应的id
Bllpotential potential = new Bllpotential();
public Faddpotstus()
{
InitializeComponent();
this.uCpaging1.PageEvent += new EventHandler<WFCL.UCpaging.PageEventArgs>(uCpaging1_PageEvent);
GetVacationList(GetCondition(), out pageCount);
this.uCpaging1.pageCount = pageCount;
}
void uCpaging1_PageEvent(object sender, WFCL.UCpaging.PageEventArgs e)
{
pageIndex = e.PageIndex;//把分页控件中的主页传到当前主页
GetVacationList(GetCondition(), out pageCount);
this.uCpaging1.pageCount = pageCount;
}
/// <summary>
/// 获取学生实体
/// </summary>
/// <returns></returns>
public tb_potential GetPotModel()
{
tb_potential potential = new tb_potential();
potential.stuname = txe_potstuname.Text;
potential.stupho = txe_potstupho.Text;
potential.stuparentpho = txe_potstuparentpho.Text;
potential.stuadress = txe_potstuadress.Text;
potential.sturemarks = txe_potsturemarks.Text;
potential.potstuid = Convert.ToInt32(lbl_potentialid.Text);
return potential;
}
/// <summary>
/// 获得查询条件
/// </summary>
/// <returns></returns>
public Condition GetCondition()
{
Condition condition = new Condition();
condition.PageIndex = pageIndex;
condition.Pagecount = pageCount;
condition.PageSize = 2;
condition.Prikye = "potstuid";
condition.TableName = "tb_potential";
condition.Condtion = "";
condition.Pagesort = "desc";
return condition;
}
/// <summary>
/// 新增潜在学生按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_add_Click(object sender, EventArgs e)
{
if (potential.InsertItem(GetPotModel()))
{
GetVacationList(GetCondition(), out pageCount);
XtraMessageBox.Show("新增学生成功");
}
}
/// <summary>
/// 更新潜在学生信息按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_amend_Click(object sender, EventArgs e)
{
if (potential.UpdateItem(GetPotModel()))
{
GetVacationList(GetCondition(), out pageCount);
XtraMessageBox.Show("更新学生信息成功");
}
}
/// <summary>
/// 删除学生信息按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_delete_Click(object sender, EventArgs e)
{
string value = "";
string strSelected = "";
for (int i = 0; i < gridView1.RowCount; i++)
{
value = gridView1.GetDataRow(i)["check"].ToString();
if (value == "True")
{
strSelected += gridView1.GetRowCellValue(i, "potstuid");
strSelected += ",";
}
}
MessageBox.Show("删除学生信息成功");
strSelected = strSelected.Remove(strSelected.LastIndexOf(","), 1); //删除最后一个逗号
potential.DeleteItem(strSelected);
GetVacationList(GetCondition(), out pageCount);
}
/// <summary>
/// 选中的行数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridView1_Click(object sender, EventArgs e)
{
//获取这一行
int row = this.gridView1.FocusedRowHandle;
//没有选中
if (row < 0)
return;
pronum = Convert.ToInt32(this.gridView1.GetRowCellValue(row, "potstuid"));
lbl_potentialid.Text = pronum.ToString();
this.txe_potstuname.Text = this.gridView1.GetRowCellValue(row, "stuname").ToString();
this.txe_potstupho.Text = this.gridView1.GetRowCellValue(row, "stupho").ToString();
this.txe_potstuparentpho.Text = this.gridView1.GetRowCellValue(row, "stuparentpho").ToString();
this.txe_potstuadress.EditValue = this.gridView1.GetRowCellValue(row, "stuadress").ToString();
this.txe_potsturemarks.EditValue = this.gridView1.GetRowCellValue(row, "sturemarks").ToString();
}
public void GetVacationList(Condition condition, out int pageCount)
{
//新建一个数据表
DataTable db = potential.GetAllVacation(condition, out pageCount);
//在表中增加一个列 add(列名,列类型)
db.Columns.Add("check", typeof(bool));
//给每一行的该列赋值
for (int i = 0; i < db.Rows.Count; i++)
{
db.Rows[i]["check"] = "false";
}
this.gridControl1.DataSource = db;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace TSMS.Common
{
public class XmlHelper
{
#region 对节点操作
/// <summary>
/// 增加一个新节点
/// </summary>
/// <param name="filePath">xml文件名</param>
/// <param name="xPath"></param>
/// <param name="xmlNode">新增加的节点</param>
/// <returns></returns>
public static bool AppendChild(string filePath, string xPath, XmlNode xmlNode)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
xmldoc.Load(filePath);//从xPath路径中加载一个xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找匹配第一个xml节点
XmlNode n = xmldoc.ImportNode(xmlNode, true);//把节点导入新节点
xn.AppendChild(n);
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 删除指定节点下所有的子节点
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <returns></returns>
public static bool DeleteAllChild(string filePath, string xPath)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
XmlElement root = xmldoc.DocumentElement;
xmldoc.Load(filePath);//从xPath路径中加载一个xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找匹配第一个xml节点
xn.RemoveAll();
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 移除指定节点的子节点
/// </summary>
/// <param name="filePath">xml文件名</param>
/// <param name="xPath">被删除节点的父节点xPath路径</param>
/// <param name="xPathChi">被删除节点的的xPath路径</param>
/// <returns></returns>
public static bool DeleteChild(string filePath, string xPath, string xPathChi)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
XmlElement root = xmldoc.DocumentElement;
xmldoc.Load(filePath);//从xPath路径中加载一个xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找匹配第一个xml节点
XmlNode n = xmldoc.SelectSingleNode(xPathChi);//查找匹配xml子节点
xn.RemoveChild(n);
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
#endregion
/// <summary>
/// 获取指定路径节点中所有子节点的值
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <returns></returns>
public static List<string> GetListValues(string filePath, string xPath)
{ List<string> list = new List<string>();
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
xmldoc.Load(filePath);
XmlNode xn = xmldoc.SelectSingleNode(xPath);
XmlElement newNode = (XmlElement)xn;//要读取的节点转换为元素
foreach (XmlNode tempNode in newNode)
{
XmlNode Node = tempNode.ChildNodes[0];
string nodeName = Node.InnerText;//取子节点的值
string u = nodeName;
list.Add(u);
}
}
catch (Exception)
{
return null;
}
return list;
}
/// <summary>
/// 获取指定节点的指定属性
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <param name="attName">属性集合</param>
/// <returns></returns>
public static List<string> GetListAttribute(string filePath, string xPath,params string[] attName)
{
List<string> list = new List<string>();
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
xmldoc.Load(filePath);
XmlNode xn = xmldoc.SelectSingleNode(xPath);
XmlElement newNode = (XmlElement)xn;//要读取的节点转换为元素
for (int i = 0; i < attName.Length; i++)
{
string stratt = newNode.GetAttribute(attName[i]);
list.Add(stratt);
}
}
catch (Exception)
{
return null;
}
return list;
}
/// <summary>
/// 给节点增加(修改)属性
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <param name="attName">string</param>
/// <param name="attValue">string</param>
/// <returns></returns>
public static bool UpdateAttribute(string filePath, string xPath,string attName, string attValue)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化xml文件
xmldoc.Load(filePath);//根据路径加载xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找一个xml节点
XmlAttribute xa = xmldoc.CreateAttribute(attName);
xa.InnerText = attValue;
xn.Attributes.Append(xa);
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 删除指定名称的属性
/// </summary>
/// <param name="filePath"></param>
/// <param name="attName">节点名称</param>
/// <returns></returns>
public static bool DeleteAttribute(string filePath,string attName)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlElement root = doc.DocumentElement;//获取根节点
XmlNodeList nodelist = root.ChildNodes;//获取所有节点列表
XmlNode node = null;
foreach (XmlNode tempNode in nodelist)
{
if (tempNode.NodeType == XmlNodeType.Element)
{
if (tempNode.ChildNodes[0].InnerText == attName)
{
node = tempNode;
break;
}
}
}
if (node != null)
{
root.RemoveChild(node);
doc.Save(filePath);
}
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 更新(增加 修改)节点内容
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool UpateNodeInnerText(string filePath, string xPath, string value)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlNode xn = doc.SelectSingleNode(xPath);//根据路径选择节点
XmlElement xe = (XmlElement)xn;
xe.InnerText = value;
doc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace TSMS.Common
{
/// <summary>
/// 负责对于ADO.NET的封装。
/// </summary>
public class SqlHelper : AbstractSqlHelper
{
/// <summary>
/// 执行非查询
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public override bool ExecuteNonQurey(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql, cmdtype, parameters);
int reuslt =cmd.ExecuteNonQuery();
CloseConnection();
return reuslt > 0 ? true : false;
}
/// <summary>
/// 获取数据表
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public override DataTable GetDataTable(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql, cmdtype, parameters);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet dataset = new DataSet();
sda.Fill(dataset);
return dataset.Tables[0];
}
/// <summary>
///
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public override object GetSingleData(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql, cmdtype,parameters);
object o = cmd.ExecuteScalar();
CloseConnection();
return o;
}
/// <summary>
/// 获取数据流
/// </summary>
/// <param name="sql"></param>
public override SqlDataReader GetDataReader(string sql,CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql,cmdtype, parameters);
SqlDataReader sdr = cmd.ExecuteReader();
CloseConnection();
return sdr;
}
/// <summary>
///获取缓存中数据表
/// </summary>
public override DataSet GetDataSet(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql,cmdtype ,parameters);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet dataset = new DataSet();
sda.Fill(dataset);
return dataset;
}
public override DataSet GetDataSet(string sql, CommandType cmdtype, List<SqlParameter> list)
{
SqlCommand cmd = GetCommand(sql, cmdtype,list);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
}
}
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Configuration;
namespace TSMS.Common
{ //定义一个抽象类
public abstract class AbstractSqlHelper
{
private SqlConnection conn = null;//初始化一个sql连接
/// <summary>
/// 获取连接字符串并打开
/// </summary>
public void GetConnection()
{ //private static string conStr = ConfigurationManager.ConnectionStrings["sqlstr"].ConnectionString;
string strCon = ConfigurationManager.ConnectionStrings["sqlstr"].ConnectionString;
conn = new SqlConnection(strCon);
conn.Open();
if (conn.State!=ConnectionState.Open)
{
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 关闭连接
/// </summary>
public void CloseConnection()
{
if (conn!=null)
{
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 设置需要执行的存储过程或语句
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="pars"></param>
/// <returns></returns>
#region 设置需要执行的存储过程或语句
public SqlCommand GetCommand(string sql, CommandType cmdtype, params SqlParameter[] pars)
{
GetConnection();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = cmdtype;
cmd.CommandText = sql;
if (pars != null)
{
cmd.Parameters.AddRange(pars);
}
return cmd;
}
public SqlCommand GetCommand(string sql, CommandType cmdtype, List<SqlParameter> pars)
{
GetConnection();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = cmdtype;
cmd.CommandText = sql;
foreach (SqlParameter s in pars)
{
cmd.Parameters.Add(s);
}
return cmd;
}
#endregion
/// <summary>
/// 执行非查询
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public abstract bool ExecuteNonQurey(string sql, CommandType cmdtype, params SqlParameter[] parameters);
/// <summary>
/// 查询表通过参数
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns>DataSet</returns>
public abstract DataSet GetDataSet(string sql, CommandType cmdtype, params SqlParameter[] parameters);
/// <summary>
/// 查询表通过list泛型集合
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="list"></param>
/// <returns></returns>
public abstract DataSet GetDataSet(string sql, CommandType cmdtype, List<SqlParameter> list);
/// <summary>
/// 查询表通过参数
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns>DataTable</returns>
public abstract DataTable GetDataTable(string sql, CommandType cmdtype, params SqlParameter[] parameters);
public abstract object GetSingleData(string sql, CommandType cmdtype, params SqlParameter[] parameters);
public abstract SqlDataReader GetDataReader(string sql,CommandType cmdtype,params SqlParameter[] parameters);
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Linq;
namespace TSMS.Common
{
public class Com
{ //检查是否为整数
public bool CheckInt(string str)
{
int num;
return int.TryParse(str, out num);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
namespace TSMS.WFCL
{
public partial class UCpaging : UserControl
{
//定义一个分页的事件
public event EventHandler<PageEventArgs> PageEvent;
public int pageCount = 0; //默认总页数
public int pageIndex = 1; //默认显示页数
public UCpaging()
{
InitializeComponent();
SibIsEnable();
}
public class PageEventArgs : EventArgs
{
private int pageSize;
private int pageIndex;
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
public int PageIndex
{
get { return pageIndex; }
set { pageIndex = value; }
}
}
/// <summary>
/// 首页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_homepage_Click(object sender, EventArgs e)
{
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pargs.PageIndex = 1;
pageIndex = pargs.PageIndex;
this.txe_nowpage.Text = "1";
this.lbl_nowpage.Text = "/" + pageCount + "页";
SibIsEnable();
PageEvent(sender, pargs);
}
}
/// <summary>
/// 上一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_propage_Click(object sender, EventArgs e)
{
PageEventArgs pargs = new PageEventArgs();
pageIndex = pageIndex == 1 ? pageIndex : pageIndex - 1;
pargs.PageIndex = pageIndex;
this.txe_nowpage.Text = pageIndex.ToString();
this.lbl_nowpage.Text = "/" + pageCount + "页";
PageEvent(sender, pargs);
SibIsEnable();
}
/// <summary>
/// 下一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sim_nextpage_Click(object sender, EventArgs e)
{
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pageIndex = pageIndex == pageCount ? pageCount : pageIndex + 1;
pargs.PageIndex = pageIndex;
this.txe_nowpage.Text = pageIndex.ToString();
this.lbl_nowpage.Text = "/" + pageCount + "页";
PageEvent(sender, pargs);
SibIsEnable();
}
}
/// <summary>
/// 末页
/// </summary> <param name="sender"></param>
/// <param name="e"></param>
private void sib_endpage_Click(object sender, EventArgs e)
{
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pargs.PageIndex = pageCount;
pageIndex = pageCount;
this.txe_nowpage.Text = pageCount.ToString();
this.lbl_nowpage.Text = "/" + pageCount + "页";
SibIsEnable();
PageEvent(sender, pargs);
}
}
/// <summary>
/// 跳转
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_jump_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(this.txe_nowpage.Text.ToString())==0)
{
this.txe_nowpage.Text= "1";
}
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pageIndex = Convert.ToInt32(this.txe_nowpage.Text.ToString());
pageIndex = pageIndex > pageCount ? pageCount : pageIndex;
pargs.PageIndex = pageIndex;
PageEvent(sender, pargs);
SibIsEnable();
}
}
public void SibIsEnable()
{
#region 分页按钮是否可用
this.lbl_nowpage.Text = "/" + pageCount + "页";
if (pageIndex <= 1)
{
sib_homepage.Enabled = false;
sib_endpage.Enabled = true;
sib_prepage.Enabled = false;
sib_nextpage.Enabled = true;
}
else if (pageIndex >= pageCount)
{
sib_homepage.Enabled = true;
sib_endpage.Enabled = false;
sib_prepage.Enabled = true;
sib_nextpage.Enabled = false;
}
else
{
sib_homepage.Enabled = true;
sib_endpage.Enabled = true;
sib_prepage.Enabled = true;
sib_nextpage.Enabled = true;
}
#endregion
}
private void UCpaging_Load(object sender, EventArgs e)
{
this.lbl_nowpage.Text = "/" + pageCount + "页";
this.txe_nowpage.Text = pageIndex.ToString();
SibIsEnable();
}
#region 文本框限制输入
//private string pattern = @"^[0-9]*$";
private string param1 = null;
//private void txe_nowpage_EditValueChanged(object sender, EventArgs e)
//{
// Match m = Regex.Match(this.txe_nowpage.Text, pattern); // 匹配正则表达式
// if (!m.Success) // 输入的不是数字
// {
// this.txe_nowpage.Text = null; //textBox内容清空
// // 将光标定位到文本框的最后
// //this.txe_nowpage.SelectionStart = this.txe_nowpage.Text.Length;
// }
// //else // 输入的是数字
// //{
// // param1 = this.txe_nowpage.Text; // 将现在textBox的值保存下
// //}
//}
#endregion
}
}
using System;
namespace TSMS.Model
{
/// <summary>
/// 描述员工的在职状态
/// </summary>
[Serializable]
public partial class tb_potential
{
public tb_potential()
{}
#region Model
private int _potstuid;
private string _stuname;
private string _stupho;
private string _stuparentpho;
private string _stuadress;
private string _sturemarks;
/// <summary>
///
/// </summary>
public int potstuid
{
set{ _potstuid=value;}
get{return _potstuid;}
}
/// <summary>
///
/// </summary>
public string stuname
{
set{ _stuname=value;}
get{return _stuname;}
}
/// <summary>
///
/// </summary>
public string stupho
{
set{ _stupho=value;}
get{return _stupho;}
}
/// <summary>
///
/// </summary>
public string stuparentpho
{
set{ _stuparentpho=value;}
get{return _stuparentpho;}
}
/// <summary>
///
/// </summary>
public string stuadress
{
set{ _stuadress=value;}
get{return _stuadress;}
}
/// <summary>
///
/// </summary>
public string sturemarks
{
set{ _sturemarks=value;}
get{return _sturemarks;}
}
#endregion Model
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMS.Model;
using TSMS.Common;
using System.Data.SqlClient;
using System.Data;
namespace TSMS.DAL
{
public class Dalpotential:IDalData<tb_potential>
{
SqlHelper _sqlhelper = new SqlHelper();
/// <summary>
/// 添加潜在学生
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool InsertItem(tb_potential t)
{
SqlParameter[] parameters =
{
new SqlParameter("@stuname",SqlDbType.NVarChar,12),
new SqlParameter("@stupho",SqlDbType.VarChar,11),
new SqlParameter("@stuparentpho",SqlDbType.VarChar,11),
new SqlParameter("@stuadress",SqlDbType.NVarChar,50),
new SqlParameter("@sturemarks",SqlDbType.NVarChar,120)
};
parameters[0].Value = t.stuname;
parameters[1].Value = t.stupho;
parameters[2].Value = t.stuparentpho;
parameters[3].Value = t.stuadress;
parameters[4].Value = t.sturemarks;
string sql = @"INSERT INTO [tb_potential] ([stuname],[stupho],[stuparentpho],[stuadress],[sturemarks])
VALUES (@stuname,@stupho,@stuparentpho,@stuadress,@sturemarks)";
return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text, parameters);
}
/// <summary>
/// 修改潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool UpdateItem(tb_potential t)
{
SqlParameter[] parameters =
{
new SqlParameter("@stuname",SqlDbType.NVarChar,12),
new SqlParameter("@stupho",SqlDbType.VarChar,11),
new SqlParameter("@stuparentpho",SqlDbType.VarChar,11),
new SqlParameter("@stuadress",SqlDbType.NVarChar,50),
new SqlParameter("@sturemarks",SqlDbType.NVarChar,120),
new SqlParameter("@potstuid",SqlDbType.Int)
};
parameters[0].Value = t.stuname;
parameters[1].Value = t.stupho;
parameters[2].Value = t.stuparentpho;
parameters[3].Value = t.stuadress;
parameters[4].Value = t.sturemarks;
parameters[5].Value = t.potstuid;
string sql = @"UPDATE tb_potential SET stuname=@stuname,stupho =@stupho,
stuparentpho= @stuparentpho,stuadress =@stuadress,sturemarks = @sturemarks
WHERE potstuid = @potstuid";
return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text, parameters);
}
/// <summary>
/// 删除潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool DeleteItem(string strSelected)
{
strSelected = strSelected.Trim(new char[] { ',' });//重要细节,慢慢研究
string sql = @"DELETE FROM [TSMS].[dbo].[tb_potential]
WHERE [potstuid] in (" + strSelected + ")";
return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text);
}
public List<tb_potential> GetListModel()
{
throw new NotImplementedException();
}
public tb_potential GetModel(int id)
{
throw new NotImplementedException();
}
/// <summary>
/// 分页按钮
/// </summary>
/// <param name="condition"></param>
/// <param name="pageCount"></param>
/// <returns></returns>
public DataTable GetAllVacation(Condition condition, out int pageCount)
{
SqlParameter[] parameters =
{
new SqlParameter("@pageSize",SqlDbType.Int),
new SqlParameter("@pageIndex",SqlDbType.Int),
new SqlParameter("@tableName",SqlDbType.VarChar,50),
new SqlParameter("@priKey",SqlDbType.VarChar,20),
new SqlParameter("@condition",SqlDbType.VarChar,2000),
new SqlParameter("@sort",SqlDbType.VarChar,4),
new SqlParameter("@pageCount",SqlDbType.Int )
};
parameters[0].Value = condition.PageSize;
parameters[1].Value = condition.PageIndex;
parameters[2].Value = condition.TableName;
parameters[3].Value = condition.Prikye;
parameters[4].Value = condition.Condtion;
parameters[5].Value = condition.Pagesort;
parameters[6].Direction = ParameterDirection.Output;
string sql = @"exec proc_CommonSinglePage @pageSize,@pageIndex,@tableName,@priKey,@condition,@sort,@pagecount out";
DataTable db = _sqlhelper.GetDataTable(sql, CommandType.Text, parameters);
pageCount = (int)parameters[6].Value;
return db;
}
public bool DeleteItem(tb_potential t)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMS.DAL;
using TSMS.Model;
using System.Data;
namespace TSMS.BLL
{
public class Bllpotential
{
private Dalpotential dalpot = new Dalpotential();
/// <summary>
/// 新增一个潜在学生
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool InsertItem(tb_potential t)
{
return dalpot.InsertItem(t);
}
/// <summary>
/// 更新潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool UpdateItem(tb_potential t)
{
return dalpot.UpdateItem(t);
}
/// <summary>
/// 删除潜在学生信息
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public bool DeleteItem(string strSelected)
{
return dalpot.DeleteItem(strSelected);
}
public DataTable GetAllVacation(Condition condition, out int pageCount)
{
return dalpot.GetAllVacation(condition, out pageCount);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;//对于SQLServer数据库的封装操作
using System.Collections;//因为要用到集合的存储,所以我们采用的是集合的命名空间
using TSMS.Model;
using TSMS.BLL;
namespace TSMS
{
public partial class Faddpotstus : DevExpress.XtraEditors.XtraForm
{
int pageCount = 0;//总页数
int pageIndex = 1;//首页
private int row = 0;//点击的行号
private int pronum = 0;//点击的行号对应的id
Bllpotential potential = new Bllpotential();
public Faddpotstus()
{
InitializeComponent();
this.uCpaging1.PageEvent += new EventHandler<WFCL.UCpaging.PageEventArgs>(uCpaging1_PageEvent);
GetVacationList(GetCondition(), out pageCount);
this.uCpaging1.pageCount = pageCount;
}
void uCpaging1_PageEvent(object sender, WFCL.UCpaging.PageEventArgs e)
{
pageIndex = e.PageIndex;//把分页控件中的主页传到当前主页
GetVacationList(GetCondition(), out pageCount);
this.uCpaging1.pageCount = pageCount;
}
/// <summary>
/// 获取学生实体
/// </summary>
/// <returns></returns>
public tb_potential GetPotModel()
{
tb_potential potential = new tb_potential();
potential.stuname = txe_potstuname.Text;
potential.stupho = txe_potstupho.Text;
potential.stuparentpho = txe_potstuparentpho.Text;
potential.stuadress = txe_potstuadress.Text;
potential.sturemarks = txe_potsturemarks.Text;
potential.potstuid = Convert.ToInt32(lbl_potentialid.Text);
return potential;
}
/// <summary>
/// 获得查询条件
/// </summary>
/// <returns></returns>
public Condition GetCondition()
{
Condition condition = new Condition();
condition.PageIndex = pageIndex;
condition.Pagecount = pageCount;
condition.PageSize = 2;
condition.Prikye = "potstuid";
condition.TableName = "tb_potential";
condition.Condtion = "";
condition.Pagesort = "desc";
return condition;
}
/// <summary>
/// 新增潜在学生按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_add_Click(object sender, EventArgs e)
{
if (potential.InsertItem(GetPotModel()))
{
GetVacationList(GetCondition(), out pageCount);
XtraMessageBox.Show("新增学生成功");
}
}
/// <summary>
/// 更新潜在学生信息按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_amend_Click(object sender, EventArgs e)
{
if (potential.UpdateItem(GetPotModel()))
{
GetVacationList(GetCondition(), out pageCount);
XtraMessageBox.Show("更新学生信息成功");
}
}
/// <summary>
/// 删除学生信息按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_delete_Click(object sender, EventArgs e)
{
string value = "";
string strSelected = "";
for (int i = 0; i < gridView1.RowCount; i++)
{
value = gridView1.GetDataRow(i)["check"].ToString();
if (value == "True")
{
strSelected += gridView1.GetRowCellValue(i, "potstuid");
strSelected += ",";
}
}
MessageBox.Show("删除学生信息成功");
strSelected = strSelected.Remove(strSelected.LastIndexOf(","), 1); //删除最后一个逗号
potential.DeleteItem(strSelected);
GetVacationList(GetCondition(), out pageCount);
}
/// <summary>
/// 选中的行数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridView1_Click(object sender, EventArgs e)
{
//获取这一行
int row = this.gridView1.FocusedRowHandle;
//没有选中
if (row < 0)
return;
pronum = Convert.ToInt32(this.gridView1.GetRowCellValue(row, "potstuid"));
lbl_potentialid.Text = pronum.ToString();
this.txe_potstuname.Text = this.gridView1.GetRowCellValue(row, "stuname").ToString();
this.txe_potstupho.Text = this.gridView1.GetRowCellValue(row, "stupho").ToString();
this.txe_potstuparentpho.Text = this.gridView1.GetRowCellValue(row, "stuparentpho").ToString();
this.txe_potstuadress.EditValue = this.gridView1.GetRowCellValue(row, "stuadress").ToString();
this.txe_potsturemarks.EditValue = this.gridView1.GetRowCellValue(row, "sturemarks").ToString();
}
public void GetVacationList(Condition condition, out int pageCount)
{
//新建一个数据表
DataTable db = potential.GetAllVacation(condition, out pageCount);
//在表中增加一个列 add(列名,列类型)
db.Columns.Add("check", typeof(bool));
//给每一行的该列赋值
for (int i = 0; i < db.Rows.Count; i++)
{
db.Rows[i]["check"] = "false";
}
this.gridControl1.DataSource = db;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace TSMS.Common
{
public class XmlHelper
{
#region 对节点操作
/// <summary>
/// 增加一个新节点
/// </summary>
/// <param name="filePath">xml文件名</param>
/// <param name="xPath"></param>
/// <param name="xmlNode">新增加的节点</param>
/// <returns></returns>
public static bool AppendChild(string filePath, string xPath, XmlNode xmlNode)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
xmldoc.Load(filePath);//从xPath路径中加载一个xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找匹配第一个xml节点
XmlNode n = xmldoc.ImportNode(xmlNode, true);//把节点导入新节点
xn.AppendChild(n);
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 删除指定节点下所有的子节点
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <returns></returns>
public static bool DeleteAllChild(string filePath, string xPath)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
XmlElement root = xmldoc.DocumentElement;
xmldoc.Load(filePath);//从xPath路径中加载一个xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找匹配第一个xml节点
xn.RemoveAll();
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 移除指定节点的子节点
/// </summary>
/// <param name="filePath">xml文件名</param>
/// <param name="xPath">被删除节点的父节点xPath路径</param>
/// <param name="xPathChi">被删除节点的的xPath路径</param>
/// <returns></returns>
public static bool DeleteChild(string filePath, string xPath, string xPathChi)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
XmlElement root = xmldoc.DocumentElement;
xmldoc.Load(filePath);//从xPath路径中加载一个xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找匹配第一个xml节点
XmlNode n = xmldoc.SelectSingleNode(xPathChi);//查找匹配xml子节点
xn.RemoveChild(n);
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
#endregion
/// <summary>
/// 获取指定路径节点中所有子节点的值
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <returns></returns>
public static List<string> GetListValues(string filePath, string xPath)
{ List<string> list = new List<string>();
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
xmldoc.Load(filePath);
XmlNode xn = xmldoc.SelectSingleNode(xPath);
XmlElement newNode = (XmlElement)xn;//要读取的节点转换为元素
foreach (XmlNode tempNode in newNode)
{
XmlNode Node = tempNode.ChildNodes[0];
string nodeName = Node.InnerText;//取子节点的值
string u = nodeName;
list.Add(u);
}
}
catch (Exception)
{
return null;
}
return list;
}
/// <summary>
/// 获取指定节点的指定属性
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <param name="attName">属性集合</param>
/// <returns></returns>
public static List<string> GetListAttribute(string filePath, string xPath,params string[] attName)
{
List<string> list = new List<string>();
try
{
XmlDocument xmldoc = new XmlDocument();//实例化一个xml文件类
xmldoc.Load(filePath);
XmlNode xn = xmldoc.SelectSingleNode(xPath);
XmlElement newNode = (XmlElement)xn;//要读取的节点转换为元素
for (int i = 0; i < attName.Length; i++)
{
string stratt = newNode.GetAttribute(attName[i]);
list.Add(stratt);
}
}
catch (Exception)
{
return null;
}
return list;
}
/// <summary>
/// 给节点增加(修改)属性
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <param name="attName">string</param>
/// <param name="attValue">string</param>
/// <returns></returns>
public static bool UpdateAttribute(string filePath, string xPath,string attName, string attValue)
{
try
{
XmlDocument xmldoc = new XmlDocument();//实例化xml文件
xmldoc.Load(filePath);//根据路径加载xml文件
XmlNode xn = xmldoc.SelectSingleNode(xPath);//查找一个xml节点
XmlAttribute xa = xmldoc.CreateAttribute(attName);
xa.InnerText = attValue;
xn.Attributes.Append(xa);
xmldoc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 删除指定名称的属性
/// </summary>
/// <param name="filePath"></param>
/// <param name="attName">节点名称</param>
/// <returns></returns>
public static bool DeleteAttribute(string filePath,string attName)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlElement root = doc.DocumentElement;//获取根节点
XmlNodeList nodelist = root.ChildNodes;//获取所有节点列表
XmlNode node = null;
foreach (XmlNode tempNode in nodelist)
{
if (tempNode.NodeType == XmlNodeType.Element)
{
if (tempNode.ChildNodes[0].InnerText == attName)
{
node = tempNode;
break;
}
}
}
if (node != null)
{
root.RemoveChild(node);
doc.Save(filePath);
}
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// 更新(增加 修改)节点内容
/// </summary>
/// <param name="filePath"></param>
/// <param name="xPath"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool UpateNodeInnerText(string filePath, string xPath, string value)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlNode xn = doc.SelectSingleNode(xPath);//根据路径选择节点
XmlElement xe = (XmlElement)xn;
xe.InnerText = value;
doc.Save(filePath);
}
catch (Exception)
{
return false;
}
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace TSMS.Common
{
/// <summary>
/// 负责对于ADO.NET的封装。
/// </summary>
public class SqlHelper : AbstractSqlHelper
{
/// <summary>
/// 执行非查询
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public override bool ExecuteNonQurey(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql, cmdtype, parameters);
int reuslt =cmd.ExecuteNonQuery();
CloseConnection();
return reuslt > 0 ? true : false;
}
/// <summary>
/// 获取数据表
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public override DataTable GetDataTable(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql, cmdtype, parameters);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet dataset = new DataSet();
sda.Fill(dataset);
return dataset.Tables[0];
}
/// <summary>
///
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public override object GetSingleData(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql, cmdtype,parameters);
object o = cmd.ExecuteScalar();
CloseConnection();
return o;
}
/// <summary>
/// 获取数据流
/// </summary>
/// <param name="sql"></param>
public override SqlDataReader GetDataReader(string sql,CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql,cmdtype, parameters);
SqlDataReader sdr = cmd.ExecuteReader();
CloseConnection();
return sdr;
}
/// <summary>
///获取缓存中数据表
/// </summary>
public override DataSet GetDataSet(string sql, CommandType cmdtype, params SqlParameter[] parameters)
{
SqlCommand cmd = GetCommand(sql,cmdtype ,parameters);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet dataset = new DataSet();
sda.Fill(dataset);
return dataset;
}
public override DataSet GetDataSet(string sql, CommandType cmdtype, List<SqlParameter> list)
{
SqlCommand cmd = GetCommand(sql, cmdtype,list);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
}
}
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Configuration;
namespace TSMS.Common
{ //定义一个抽象类
public abstract class AbstractSqlHelper
{
private SqlConnection conn = null;//初始化一个sql连接
/// <summary>
/// 获取连接字符串并打开
/// </summary>
public void GetConnection()
{ //private static string conStr = ConfigurationManager.ConnectionStrings["sqlstr"].ConnectionString;
string strCon = ConfigurationManager.ConnectionStrings["sqlstr"].ConnectionString;
conn = new SqlConnection(strCon);
conn.Open();
if (conn.State!=ConnectionState.Open)
{
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 关闭连接
/// </summary>
public void CloseConnection()
{
if (conn!=null)
{
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 设置需要执行的存储过程或语句
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="pars"></param>
/// <returns></returns>
#region 设置需要执行的存储过程或语句
public SqlCommand GetCommand(string sql, CommandType cmdtype, params SqlParameter[] pars)
{
GetConnection();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = cmdtype;
cmd.CommandText = sql;
if (pars != null)
{
cmd.Parameters.AddRange(pars);
}
return cmd;
}
public SqlCommand GetCommand(string sql, CommandType cmdtype, List<SqlParameter> pars)
{
GetConnection();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = cmdtype;
cmd.CommandText = sql;
foreach (SqlParameter s in pars)
{
cmd.Parameters.Add(s);
}
return cmd;
}
#endregion
/// <summary>
/// 执行非查询
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public abstract bool ExecuteNonQurey(string sql, CommandType cmdtype, params SqlParameter[] parameters);
/// <summary>
/// 查询表通过参数
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns>DataSet</returns>
public abstract DataSet GetDataSet(string sql, CommandType cmdtype, params SqlParameter[] parameters);
/// <summary>
/// 查询表通过list泛型集合
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="list"></param>
/// <returns></returns>
public abstract DataSet GetDataSet(string sql, CommandType cmdtype, List<SqlParameter> list);
/// <summary>
/// 查询表通过参数
/// </summary>
/// <param name="sql"></param>
/// <param name="cmdtype"></param>
/// <param name="parameters"></param>
/// <returns>DataTable</returns>
public abstract DataTable GetDataTable(string sql, CommandType cmdtype, params SqlParameter[] parameters);
public abstract object GetSingleData(string sql, CommandType cmdtype, params SqlParameter[] parameters);
public abstract SqlDataReader GetDataReader(string sql,CommandType cmdtype,params SqlParameter[] parameters);
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Linq;
namespace TSMS.Common
{
public class Com
{ //检查是否为整数
public bool CheckInt(string str)
{
int num;
return int.TryParse(str, out num);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
namespace TSMS.WFCL
{
public partial class UCpaging : UserControl
{
//定义一个分页的事件
public event EventHandler<PageEventArgs> PageEvent;
public int pageCount = 0; //默认总页数
public int pageIndex = 1; //默认显示页数
public UCpaging()
{
InitializeComponent();
SibIsEnable();
}
public class PageEventArgs : EventArgs
{
private int pageSize;
private int pageIndex;
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
public int PageIndex
{
get { return pageIndex; }
set { pageIndex = value; }
}
}
/// <summary>
/// 首页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_homepage_Click(object sender, EventArgs e)
{
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pargs.PageIndex = 1;
pageIndex = pargs.PageIndex;
this.txe_nowpage.Text = "1";
this.lbl_nowpage.Text = "/" + pageCount + "页";
SibIsEnable();
PageEvent(sender, pargs);
}
}
/// <summary>
/// 上一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_propage_Click(object sender, EventArgs e)
{
PageEventArgs pargs = new PageEventArgs();
pageIndex = pageIndex == 1 ? pageIndex : pageIndex - 1;
pargs.PageIndex = pageIndex;
this.txe_nowpage.Text = pageIndex.ToString();
this.lbl_nowpage.Text = "/" + pageCount + "页";
PageEvent(sender, pargs);
SibIsEnable();
}
/// <summary>
/// 下一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sim_nextpage_Click(object sender, EventArgs e)
{
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pageIndex = pageIndex == pageCount ? pageCount : pageIndex + 1;
pargs.PageIndex = pageIndex;
this.txe_nowpage.Text = pageIndex.ToString();
this.lbl_nowpage.Text = "/" + pageCount + "页";
PageEvent(sender, pargs);
SibIsEnable();
}
}
/// <summary>
/// 末页
/// </summary> <param name="sender"></param>
/// <param name="e"></param>
private void sib_endpage_Click(object sender, EventArgs e)
{
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pargs.PageIndex = pageCount;
pageIndex = pageCount;
this.txe_nowpage.Text = pageCount.ToString();
this.lbl_nowpage.Text = "/" + pageCount + "页";
SibIsEnable();
PageEvent(sender, pargs);
}
}
/// <summary>
/// 跳转
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void sib_jump_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(this.txe_nowpage.Text.ToString())==0)
{
this.txe_nowpage.Text= "1";
}
if (PageEvent != null)
{
PageEventArgs pargs = new PageEventArgs();
pageIndex = Convert.ToInt32(this.txe_nowpage.Text.ToString());
pageIndex = pageIndex > pageCount ? pageCount : pageIndex;
pargs.PageIndex = pageIndex;
PageEvent(sender, pargs);
SibIsEnable();
}
}
public void SibIsEnable()
{
#region 分页按钮是否可用
this.lbl_nowpage.Text = "/" + pageCount + "页";
if (pageIndex <= 1)
{
sib_homepage.Enabled = false;
sib_endpage.Enabled = true;
sib_prepage.Enabled = false;
sib_nextpage.Enabled = true;
}
else if (pageIndex >= pageCount)
{
sib_homepage.Enabled = true;
sib_endpage.Enabled = false;
sib_prepage.Enabled = true;
sib_nextpage.Enabled = false;
}
else
{
sib_homepage.Enabled = true;
sib_endpage.Enabled = true;
sib_prepage.Enabled = true;
sib_nextpage.Enabled = true;
}
#endregion
}
private void UCpaging_Load(object sender, EventArgs e)
{
this.lbl_nowpage.Text = "/" + pageCount + "页";
this.txe_nowpage.Text = pageIndex.ToString();
SibIsEnable();
}
#region 文本框限制输入
//private string pattern = @"^[0-9]*$";
private string param1 = null;
//private void txe_nowpage_EditValueChanged(object sender, EventArgs e)
//{
// Match m = Regex.Match(this.txe_nowpage.Text, pattern); // 匹配正则表达式
// if (!m.Success) // 输入的不是数字
// {
// this.txe_nowpage.Text = null; //textBox内容清空
// // 将光标定位到文本框的最后
// //this.txe_nowpage.SelectionStart = this.txe_nowpage.Text.Length;
// }
// //else // 输入的是数字
// //{
// // param1 = this.txe_nowpage.Text; // 将现在textBox的值保存下
// //}
//}
#endregion
}
}
三层及winform前台页面 XmlHelper.cs Sqlhelper.cs AbstractSqlHelper.cs Com.cs 分页控件的后台代码
最新推荐文章于 2019-10-23 16:24:07 发布