(2)主要代码设计
private void btnLogin_Click(object sender, EventArgs e)
{
BaseClass.ClsComm.Str_IP = ""; //服务器IP -- 默认是本机
if (TxtUserName.Text == string.Empty)
{
MessageBox.Show("用户名称不能为空!", "提示...", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//获取用户名与IP
BaseClass.ClsComm.Str_UserName = TxtUserName.Text.Trim(); //保存-- 用户名
BaseClass.ClsComm.Str_IP = CmbIP.Text.Trim(); //保存-- 服务器IP
DataSet ds = null;
MyPower.MySysUser = TxtUserName.Text.Trim();
MyPower.MyPassWord = TxtPwd.Text.Trim();
ds = MySQL.Login(MyPower);
if (ds.Tables[0].Rows.Count > 0)
{
FrmMain Frm_Main = new FrmMain(); //启动主窗口
Frm_Main.Show();
//获取用户权限
if (Convert.ToBoolean(ds.Tables[0].Rows[0]["SysPower"])) //系统管理权
{
BaseClass.ClsComm.Int_SysPower = 1; // 1 – 有权限
}
else
{
BaseClass.ClsComm.Int_SysPower = 0; // 0 – 无权限
}
if (Convert.ToBoolean(ds.Tables[0].Rows[0]["AddPower"])) // 增加权限
{
BaseClass.ClsComm.Int_AddPower = 1;
}
else
{
BaseClass.ClsComm.Int_AddPower = 0;
}
//注:此处省略了类似的语句
this.Visible = false; //登录窗口不可见
//设置自动编号---- 注意:保存数据时,才生成新ID 号
DataSet ds2 = null;
int NewId_Int = 1;
ds2 = MySQL.Get_Login_Info("tb_Login"); //登录表-- 升序
if (ds2.Tables[0].Rows.Count == 0)
{
MyLogin.MyId = NewId_Int;
}
else
{
for (int i = 1; i <= ds2.Tables[0].Rows.Count; i++) //Id号回收算法
{
NewId_Int = Convert.ToInt32(ds2.Tables[0].Rows[i - 1]["Id"]); //转化为位符号整数
if (NewId_Int == i)
{
NewId_Int = i + 1;
}
else
{
NewId_Int = i;
break;
}
}
MyLogin.MyId = NewId_Int;
}
BaseClass.ClsComm.Login_Id = MyLogin.MyId; //保存-- Login_Id(全局变量)
MyLogin.MyLogName = BaseClass.ClsComm.Str_UserName; //用户名
MyLogin.MyLogTime = DateTime.Now.ToString(); //登录时间
MyLogin.MyLogOut = "";
MyLogin.MyLogYN = "N";
MyLogin.MyLogMemo = "正在使用";
int Id = MySQL.Add_Login_Data(MyLogin); //保存登录信息
}
else
{
MessageBox.Show("用户姓名或密码不正确!", "提示...", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
2.整本图册管理设计
整本图册管理模块,主要用来添加、编辑、删除和查询整本图的基本信息,并且通过DataGridView控件显示整本图的信息。
(1)整本图册管理运行结果如图6所示。

图5 整本图册管理窗体
(2)主要代码设计
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
1)声明全局业务层ClsSQL类对象,整本图数据结构FrmScrFile5类对象和定义全局变量G_Int_AddOrUpdate用来识别添加整本图信息还是修改整本图信息。
namespace DrawingSys.BaseInfo
{
public partial class FrmScrFile5 : Form
{
BaseClass.ClsSQL MySQL = new DrawingSys.BaseClass.ClsSQL(); BaseClass.ClsDefaultNO MyDefaultNO = new DrawingSys.BaseClass.ClsDefaultNO();
BaseClass.ClsScroll MyScroll = new DrawingSys.BaseClass.ClsScroll();
int G_Int_AddOrUpdate = 0;
public FrmScrFile5()
{
InitializeComponent();
}
……..其他功能事件代码……..
}
}
2)退出,关闭当前窗体
private void tlBtnExit_Click(object sender, EventArgs e)
{
this.Close();
}
3)窗体加载,检索整本图所有信息,并通过DataGridView控件显示出来。
private void FrmScrFile5_Load(object sender, EventArgs e) //窗体加载
{
this.ClearText(); //文本清空
this.BtnEnabledTrue(); //屏蔽控件-- True
dgvStockList.DataSource = MySQL.GetAll_Scroll_Data_5("tb_Scroll").Tables[0].DefaultView; //表格赋值-- 升序
this.SetdgvStockListHeadText(); //表头标题处理. 注意:先表格赋值
this.BackColorSet_1(); //背景颜色设定
this.TxtScl_1.Focus(); //定位焦点
this.SetColumnsWith(); //设定列宽
}
|