using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
using SQLHelper;
|
using Pub_Class;
|
|
namespace BLL
|
{
|
public partial class FrmLogin : Form
|
{
|
public string UserName;
|
public bool isOk;
|
public FrmLogin()
|
{
|
InitializeComponent();
|
}
|
|
private void SetCmbAccount(string sServer)//cmb中设置帐套 //Lock
|
{
|
ClsCNmaster oCn = new ClsCNmaster();
|
DataSet DS;
|
try
|
{
|
DS = oCn.RunProcReturn("select * from HDSystem_DataBases where YNuse=1 ", "HDSystem_DataBases", ref ClsPub.sExeReturnInfo);
|
if (DS == null)
|
{
|
MessageBox.Show("读取帐套信息失败2!" + ClsPub.sExeReturnInfo);
|
return;
|
}
|
cmbAccount.Items.Clear();
|
for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
|
{
|
cmbAccount.Items.Add(DS.Tables[0].Rows[i]["Number"].ToString() + "-" + DS.Tables[0].Rows[i]["CountingRoomName"].ToString());
|
}
|
if (cmbAccount.Items.Count > 0)
|
{
|
cmbAccount.SelectedIndex = 0;
|
ClsIni oIni = new ClsIni();
|
string sNumber = ClsIni.ReadIni("Erp", "DataBaseNumber", DBUtility.ClsPub.AppPath + @"/HXErp.ini");
|
for (int j = 0; j < cmbAccount.Items.Count; j++)
|
{
|
if (sNumber.Trim() == cmbAccount.Items[j].ToString().Trim())
|
cmbAccount.SelectedIndex = j;
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("读取帐套信息失败!" + e.Message);
|
}
|
}
|
|
private bool CheckServer()//检查服务器名正确性 //Lock
|
{
|
ClsCN oCn = new ClsCN();
|
if (oCn.CheckOpen())
|
{
|
lblStatus.Text = "服务器连接成功";
|
SetCmbAccount(oCn.sServer);
|
return true;
|
}
|
else
|
{
|
lblStatus.Text = "服务器连接失败";
|
return false;
|
}
|
//测试K3帐套1
|
|
|
|
//测试K3帐套2
|
|
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private bool AllowLogin() //Lock
|
{
|
if (cmbUser.Text == string.Empty)
|
{
|
MessageBox.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
cmbUser.Focus();
|
return false;
|
}
|
if (cmbAccount.Text == string.Empty)
|
{
|
MessageBox.Show("错误的帐套!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return false;
|
}
|
return true;
|
}
|
|
private void btnOK_Click(object sender, EventArgs e) //Lock
|
{
|
|
if (AllowLogin() != true)
|
return;
|
DataSet ds = null;
|
ClsCNmaster oCn = new ClsCNmaster();
|
ClsCN oCnLoc = new ClsCN();
|
string sDataBase;
|
string sDataBase_K3 = "";
|
string sDataBase_K32 = "";
|
string sDataBase_K33 = "";
|
sDataBase = oCn.GetDataBase(cmbAccount.Text.Trim(), ref sDataBase_K3);
|
ClsIni oIni = new ClsIni();
|
ClsIni.WriteIni("Erp", "DataBase", sDataBase.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("K3Erp", "DataBase", sDataBase_K3.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
DAL.ClsUser oUser = new DAL.ClsUser();
|
|
ds = oUser.CheckCzymc(cmbUser.Text.Trim(), ClsPub.StrToPsd(txtPsd.Text.Trim()));
|
if (ds == null)
|
{
|
MessageBox.Show("选择的帐套不存在!", "提示");
|
return;
|
}
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
ClsPub.CurUserID = ds.Tables[0].Rows[0]["Czybm"].ToString();
|
this.Close();
|
isOk = true;
|
}
|
else
|
{
|
MessageBox.Show("错误的用户密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return;
|
}
|
//得到当前会计期间
|
int sYear = 0;
|
int sPeriod = 0;
|
if (!ClsPub.Sub_GetCurPeriod(ref sYear, ref sPeriod))
|
{
|
MessageBox.Show("得到当前会计期间失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
isOk = false;
|
return;
|
}
|
//
|
this.Close();
|
isOk = true;
|
ClsIni.WriteIni("Erp", "DataBaseNumber", cmbAccount.Text.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
//存入用户名密码
|
//
|
UserName = cmbUser.Text.Trim() + "," + UserName;
|
string[] str = UserName.Split(',');
|
List<string> listStr = new List<string>();
|
foreach (string eachStr in str)
|
{
|
if (!listStr.Contains(eachStr))
|
listStr.Add(eachStr);
|
}
|
UserName = "";
|
if (listStr.Count > 10)
|
{
|
listStr.RemoveAt(10);
|
}
|
foreach (string eachStr in listStr)
|
{
|
UserName = UserName + eachStr + ",";
|
}
|
UserName = UserName.Remove(UserName.LastIndexOf(","), 1);
|
//
|
ClsIni.WriteIni("UserInfo", "UserName", UserName, DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "HOrgName", cmbHOrg.Text.ToString(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsPub.CurUserName = cmbUser.Text.Trim();
|
ClsPub.AppPath = System.Environment.CurrentDirectory;
|
ClsPub.HOrgID = ClsPub.get_ORGANIZATIONSIDByName(ClsPub.isStrNull(cmbHOrg.Text));
|
ClsPub.HOrgNumber = ClsPub.get_ORGANIZATIONSNOByName(ClsPub.isStrNull(cmbHOrg.Text));
|
ClsPub.HOrgName = ClsPub.isStrNull(cmbHOrg.Text);
|
if (chkRemember.Checked == true)
|
{
|
ClsIni.WriteIni("UserInfo", "UserPsd", "", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "Remember", "1", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
else
|
{
|
ClsIni.WriteIni("UserInfo", "UserPsd", "", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "Remember", "0", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
|
}
|
|
private void txtUser_KeyUp(object sender, KeyEventArgs e)
|
{
|
if (e.KeyValue == 13) txtPsd.Focus();
|
|
}
|
|
private void txtPsd_KeyUp(object sender, KeyEventArgs e)
|
{
|
if (e.KeyValue == 13)
|
this.btnOK_Click(sender, e);
|
}
|
|
private void timer1_Tick(object sender, EventArgs e)
|
{
|
timer1.Enabled = false;
|
if (!CheckServer())
|
{
|
MessageBox.Show("数据库测试失败,请在高级选项里设置正确的服务器信息!", "提示!");
|
}
|
ClsIni oIni = new ClsIni();
|
//
|
UserName = ClsIni.ReadIni("UserInfo", "UserName", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
|
string[] strArr = UserName.Split(',');
|
foreach (string str in strArr)
|
{
|
cmbUser.Items.Add(str);
|
}
|
cmbUser.SelectedIndex = 0;
|
//
|
txtUser.Text = ClsIni.ReadIni("UserInfo", "UserName", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
if (ClsIni.ReadIni("UserInfo", "Remember", DBUtility.ClsPub.AppPath + @"/HXERP.ini") == "1")
|
{
|
txtPsd.Text = ClsIni.ReadIni("UserInfo", "UserPsd", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
chkRemember.Checked = true;
|
}
|
else
|
{
|
txtPsd.Text = "";
|
chkRemember.Checked = false;
|
}
|
}
|
|
private void lblChangePsd_Click(object sender, EventArgs e)
|
{
|
if (AllowLogin() != true)
|
return;
|
DataSet ds = null;
|
ClsCNmaster oCn = new ClsCNmaster();
|
DAL.ClsUser oUser = new DAL.ClsUser();
|
ds = oUser.CheckCzymc(cmbUser.Text.Trim(), ClsPub.StrToPsd(txtPsd.Text.Trim()));
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
FrmChangePsd oChange = new FrmChangePsd();
|
oChange.UserCode = cmbUser.Text.Trim();
|
oChange.ShowDialog();
|
return;
|
}
|
else
|
{
|
MessageBox.Show("错误的用户密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
txtPsd.SelectAll();
|
return;
|
}
|
}
|
|
private void lblSetServer_Click(object sender, EventArgs e)
|
{
|
FrmSetServer oFrm = new FrmSetServer();
|
oFrm.ShowDialog();
|
timer1.Enabled = true;
|
}
|
|
private void FrmLogin_Load(object sender, EventArgs e)
|
{
|
lblVersion.Text = "服务器版本:" + Pub_Class.ClsPub.VersionNew;
|
lblVersion2.Text = "本地版本:" + Pub_Class.ClsPub.VersionOld;
|
lblIPAddress.Text = "IP:" + Pub_Class.ClsPub.IPAddress + " " + Pub_Class.ClsPub.ComputerName;
|
CheckUseOrgID();
|
textBox1.Focus();
|
string sCompName = ClsIni.ReadIni("Erp", "HCompName", DBUtility.ClsPub.AppPath + @"/HXErp.ini"); //系统配置文件 客户名称
|
if (sCompName == "奥邦")
|
{
|
textBox1.Visible = true;
|
button1.Visible = true;
|
textBox1.Focus();
|
}
|
else
|
{
|
textBox1.Visible = false;
|
button1.Visible = false;
|
}
|
}
|
|
//校验组织
|
private void CheckUseOrgID()
|
{
|
DataSet DS;
|
DS = get_ORGANIZATIONSList();
|
if (DS == null || DS.Tables[0].Rows.Count == 0)
|
{
|
MessageBox.Show("读取组织信息失败!");
|
return;
|
}
|
cmbHOrg.Items.Clear();
|
string HOrgName = "";
|
bool b = false;
|
HOrgName = ClsIni.ReadIni("UserInfo", "HOrgName", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
|
{
|
cmbHOrg.Items.Add(DS.Tables[0].Rows[i]["HName"].ToString());
|
if (HOrgName == DS.Tables[0].Rows[i]["HName"].ToString())
|
{
|
b = true;
|
}
|
|
}
|
if (cmbHOrg.Items.Count > 0)
|
{
|
if (b == false)
|
{
|
cmbHOrg.SelectedIndex = 0;
|
}
|
else
|
{
|
cmbHOrg.Text = HOrgName;
|
}
|
}
|
}
|
|
//获取组织列表
|
public DataSet get_ORGANIZATIONSList()
|
{
|
try
|
{
|
return ClsPub.get_ORGANIZATIONSList();
|
}
|
catch (Exception e)
|
{
|
return null;
|
}
|
}
|
|
private void lblStatus_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label4_Click(object sender, EventArgs e)
|
{
|
if (MessageBox.Show("确定要手动更新程序吗?本程序将自动关闭!", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
|
{
|
string strFileName = ClsPub.AppPath + @"/HX_Update.exe";
|
System.Diagnostics.Process.Start(strFileName);
|
Application.Exit();
|
}
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
{
|
//textBox1.Focus();
|
string HPassWord = textBox1.Text.Trim().ToString();
|
if (HPassWord == null || HPassWord == "")
|
{
|
MessageBox.Show("请刷卡");
|
return;
|
}
|
//MessageBox.Show(HPassWord);
|
SQLHelper.ClsCN oCn1 = new SQLHelper.ClsCN();
|
//1.查找数据库操作员管理表里面是否有对应这个加密字符串对应的记录
|
DataSet DSet = oCn1.RunProcReturn("select Czymc,Czmm from Gy_Czygl where HICNumber ='" + HPassWord + "'", "Gy_Czygl");
|
if (DSet == null || DSet.Tables[0].Rows.Count == 0)
|
//if (DSet == null|| DSet.Tables[0].Rows.Count == 0)
|
{
|
MessageBox.Show("没有找到对应职员信息,请重新刷卡" + DBUtility.ClsPub.sExeReturnInfo);
|
//textBox1.Text = "";
|
return;
|
}
|
else
|
{
|
cmbUser.Text = ClsPub.isStrNull(DSet.Tables[0].Rows[0]["Czymc"]);
|
|
if (AllowLogin() != true)
|
return;
|
DataSet ds = null;
|
ClsCNmaster oCn = new ClsCNmaster();
|
ClsCN oCnLoc = new ClsCN();
|
string sDataBase;
|
string sDataBase_K3 = "";
|
string sDataBase_K32 = "";
|
string sDataBase_K33 = "";
|
sDataBase = oCn.GetDataBase(cmbAccount.Text.Trim(), ref sDataBase_K3);
|
ClsIni oIni = new ClsIni();
|
ClsIni.WriteIni("Erp", "DataBase", sDataBase.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("K3Erp", "DataBase", sDataBase_K3.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
DAL.ClsUser oUser = new DAL.ClsUser();
|
|
ds = oUser.CheckCzymc_AB(cmbUser.Text.Trim(), textBox1.Text.Trim());
|
if (ds == null)
|
{
|
MessageBox.Show("选择的帐套不存在!", "提示");
|
return;
|
}
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
ClsPub.CurUserID = ds.Tables[0].Rows[0]["Czybm"].ToString();
|
this.Close();
|
isOk = true;
|
}
|
else
|
{
|
MessageBox.Show("错误的用户密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return;
|
}
|
//得到当前会计期间
|
int sYear = 0;
|
int sPeriod = 0;
|
if (!ClsPub.Sub_GetCurPeriod(ref sYear, ref sPeriod))
|
{
|
MessageBox.Show("得到当前会计期间失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
isOk = false;
|
return;
|
}
|
//
|
this.Close();
|
isOk = true;
|
ClsIni.WriteIni("Erp", "DataBaseNumber", cmbAccount.Text.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
//存入用户名密码
|
//
|
UserName = cmbUser.Text.Trim() + "," + UserName;
|
string[] str = UserName.Split(',');
|
List<string> listStr = new List<string>();
|
foreach (string eachStr in str)
|
{
|
if (!listStr.Contains(eachStr))
|
listStr.Add(eachStr);
|
}
|
UserName = "";
|
if (listStr.Count > 10)
|
{
|
listStr.RemoveAt(10);
|
}
|
foreach (string eachStr in listStr)
|
{
|
UserName = UserName + eachStr + ",";
|
}
|
UserName = UserName.Remove(UserName.LastIndexOf(","), 1);
|
//
|
ClsIni.WriteIni("UserInfo", "UserName", UserName, DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "HOrgName", cmbHOrg.Text.ToString(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsPub.CurUserName = cmbUser.Text.Trim();
|
ClsPub.AppPath = System.Environment.CurrentDirectory;
|
ClsPub.HOrgID = ClsPub.get_ORGANIZATIONSIDByName(ClsPub.isStrNull(cmbHOrg.Text));
|
ClsPub.HOrgNumber = ClsPub.get_ORGANIZATIONSNOByName(ClsPub.isStrNull(cmbHOrg.Text));
|
ClsPub.HOrgName = ClsPub.isStrNull(cmbHOrg.Text);
|
if (chkRemember.Checked == true)
|
{
|
ClsIni.WriteIni("UserInfo", "UserPsd", "", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "Remember", "1", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
else
|
{
|
ClsIni.WriteIni("UserInfo", "UserPsd", "", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "Remember", "0", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
}
|
}
|
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void textBox1_KeyDown(object sender, KeyEventArgs e)
|
{
|
string HPassWord = textBox1.Text.Trim().ToString();
|
if (HPassWord.Length < 10)
|
{
|
return;
|
}
|
//MessageBox.Show(HPassWord);
|
//演示视频用,平时屏蔽掉
|
if (HPassWord.Trim() == "3012460306-1" || HPassWord.Contains("3012460306-1") == true)
|
{
|
MessageBox.Show("您刷的员工卡,没有经过技能的培训,不能在本工站上岗!");
|
return;
|
}
|
//
|
SQLHelper.ClsCN oCn1 = new SQLHelper.ClsCN();
|
//1.查找数据库操作员管理表里面是否有对应这个加密字符串对应的记录
|
DataSet DSet = oCn1.RunProcReturn("select Czybm,Czmm from Gy_Czygl where HICNumber ='" + HPassWord + "'", "Gy_Czygl");
|
if (DSet == null || DSet.Tables[0].Rows.Count == 0)
|
//if (DSet == null|| DSet.Tables[0].Rows.Count == 0)
|
{
|
MessageBox.Show("没有找到对应职员信息,请重新刷卡" + DBUtility.ClsPub.sExeReturnInfo);
|
//textBox1.Text = "";
|
return;
|
}
|
else
|
{
|
cmbUser.Text = ClsPub.isStrNull(DSet.Tables[0].Rows[0]["Czybm"]);
|
|
if (AllowLogin() != true)
|
return;
|
//DataSet ds = null;
|
ClsCNmaster oCn = new ClsCNmaster();
|
ClsCN oCnLoc = new ClsCN();
|
string sDataBase;
|
string sDataBase_K3 = "";
|
string sDataBase_K32 = "";
|
string sDataBase_K33 = "";
|
sDataBase = oCn.GetDataBase(cmbAccount.Text.Trim(), ref sDataBase_K3);
|
ClsIni oIni = new ClsIni();
|
ClsIni.WriteIni("Erp", "DataBase", sDataBase.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("K3Erp", "DataBase", sDataBase_K3.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
DAL.ClsUser oUser = new DAL.ClsUser();
|
|
//ds = oUser.CheckCzymc(cmbUser.Text.Trim(), textBox1.Text.Trim());
|
//if (ds == null)
|
//{
|
// MessageBox.Show("选择的帐套不存在!", "提示");
|
// return;
|
//}
|
//if (ds.Tables[0].Rows.Count > 0)
|
//{
|
ClsPub.CurUserID = DSet.Tables[0].Rows[0]["Czybm"].ToString();
|
this.Close();
|
isOk = true;
|
//}
|
//else
|
//{
|
// MessageBox.Show("错误的用户密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
// return;
|
//}
|
//得到当前会计期间
|
int sYear = 0;
|
int sPeriod = 0;
|
if (!ClsPub.Sub_GetCurPeriod(ref sYear, ref sPeriod))
|
{
|
MessageBox.Show("得到当前会计期间失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
isOk = false;
|
return;
|
}
|
//
|
this.Close();
|
isOk = true;
|
ClsIni.WriteIni("Erp", "DataBaseNumber", cmbAccount.Text.Trim(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
//存入用户名密码
|
//
|
UserName = cmbUser.Text.Trim() + "," + UserName;
|
string[] str = UserName.Split(',');
|
List<string> listStr = new List<string>();
|
foreach (string eachStr in str)
|
{
|
if (!listStr.Contains(eachStr))
|
listStr.Add(eachStr);
|
}
|
UserName = "";
|
if (listStr.Count > 10)
|
{
|
listStr.RemoveAt(10);
|
}
|
foreach (string eachStr in listStr)
|
{
|
UserName = UserName + eachStr + ",";
|
}
|
UserName = UserName.Remove(UserName.LastIndexOf(","), 1);
|
//
|
ClsIni.WriteIni("UserInfo", "UserName", UserName, DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "HOrgName", cmbHOrg.Text.ToString(), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsPub.CurUserName = cmbUser.Text.Trim();
|
ClsPub.AppPath = System.Environment.CurrentDirectory;
|
ClsPub.HOrgID = ClsPub.get_ORGANIZATIONSIDByName(ClsPub.isStrNull(cmbHOrg.Text));
|
ClsPub.HOrgNumber = ClsPub.get_ORGANIZATIONSNOByName(ClsPub.isStrNull(cmbHOrg.Text));
|
ClsPub.HOrgName = ClsPub.isStrNull(cmbHOrg.Text);
|
if (chkRemember.Checked == true)
|
{
|
ClsIni.WriteIni("UserInfo", "UserPsd", "", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "Remember", "1", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
else
|
{
|
ClsIni.WriteIni("UserInfo", "UserPsd", "", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("UserInfo", "Remember", "0", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
}
|
}
|
}
|
}
|