private void button_Login_Click(object sender, EventArgs e) { //String szYear = System.DateTime.Now.Year.ToString(); //int iMonth = System.DateTime.Now.Month; //if (System.DateTime.Now > DateTime.Parse("2018.12.31")) //{ // MessageBox.Show("读程序参数错误,请检查!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // return; //} DataSet ds = new DataSet(); string szErr = ""; string szSql = "select user_pwd,user_id,USER_APP,USER_NAME,USER_STAT from sys_users where user_login='******'";// and USER_STAT='STOP'"; int iRst = MyStart.oMyDb.ReadData(szSql, "tableA", ref ds, ref szErr); MyStart.oMyDb.Close(); if (iRst != 0) { MessageBox.Show("连接数据库失败(错误原因:" + szErr + ")", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MyIniFile.WriteLog("登录", "SQL=" + szSql + ",Err=" + szErr); return; } int iNum = ds.Tables[0].Rows.Count; if (iNum != 1) { MessageBox.Show("没有用户信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MyIniFile.WriteLog("登录", "SQL=" + szSql + ",Err=没有用户信息"); return; } DataRow dr = ds.Tables[0].Rows[0]; if (dr[4].ToString().ToUpper() == "STOP") { MessageBox.Show("该帐号已停用,请重新登录", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MyIniFile.WriteLog("登录", "SQL=" + szSql + ",Err=该帐号已停用,请重新登录"); textBox_Name.Focus(); return; } string szPwd = MyTools.HideString_To_OpenString(dr[0].ToString(), MyStart.gszPwdKey); if (textBox_PW.Text.Trim() == szPwd.Trim()) { MyStart.giUserID = Convert.ToInt16(dr[1]); MyStart.gszUserPwd = textBox_PW.Text.Trim(); MyStart.gszUserApp = dr[2].ToString(); MyStart.gszUsername = dr[3].ToString(); MyStart.UserCheckIn = true; string sIniFileName = Application.StartupPath + "\\YTB.ini"; int sI = 0; string sErrorMessage = ""; MyStart.gszSysLogin = textBox_Name.Text; sI = MyIniFile.SetIniKeyValue(sIniFileName, "Sys", "Login", MyStart.gszSysLogin); if (sI < 0) { sErrorMessage = "保存 " + sIniFileName + "文件的操作员信息" + " 项时出错"; MessageBox.Show("操作错误:" + sErrorMessage + "。", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); } else { MessageBox.Show("登录信息错误,请重新输入", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox_Name.Focus(); return; } }
private void button_Save_Click(object sender, EventArgs e) { string sIniFileName = Application.StartupPath + "\\YTB.ini"; int sI = 0; string sErrorMessage = ""; string sTmp; /* * if (textBox_Pwd1.Text.Trim() != textBox_Pwd2.Text.Trim()) * { * sI = -1; * sErrorMessage = "两次输入的系统登录密码不相等,请更正"; * goto Eend; * } * if (textBox_Pwd1.Text.Length > 8) * { * sI = -1; * sErrorMessage = "系统登录密码长度不能超过8个字节,请更正"; * goto Eend; * } * //if (textBox_SrvUserPass.Text.Length > 8) * //{ * // sI = -1; * // sErrorMessage = "数据库密码长度不能超过8个字节,请更正"; * // goto Eend; * //} */ sI = -1; MyStart.gszDbIp = textBox_SrvIP.Text.Trim(); MyStart.gszDbPort = textBox_SrvPort.Text.Trim(); MyStart.gszDbLogin = textBox_SrvUserName.Text.Trim(); MyStart.gszDbPwd = textBox_SrvUserPass.Text; MyStart.gszDbSrv = textBox_SrvDataBase.Text.Trim(); MyStart.gszYTBIp = textBox_YTB_IP.Text; MyStart.gszYTBPort = textBox_YTB_PORT.Text; MyStart.gszRdrPort = comboBox_Rdr_Comm.Text.Substring(4); MyStart.gszRdr2Port = comboBox_Rdr2_Comm.Text.Substring(4); MyStart.gszRdrBaud = comboBox_Rdr_Baud.Text; MyStart.gszPsPort = comboBox_PS_Comm.Text.Substring(4); MyStart.gszPsBaud = comboBox_PS_Baud.Text; /*sI = MyIniFile.SetIniKeyValue(sIniFileName, "Sys", "Login", MyStart.szSysLogin); * if (sI < 0) * { * sErrorMessage = "保存 " + sIniFileName + "文件的 Sys.Login" + " 项时出错"; * goto Eend; * } * * sTmp = MyTools.OpenString_To_HideString((textBox_Pwd1.Text + " ").Substring(0, 8)); * sI = MyIniFile.SetIniKeyValue(sIniFileName, "Sys", "Pwd", sTmp); * if (sI < 0) * { * sErrorMessage = "保存 " + sIniFileName + "文件的 Sys.Pwd" + " 项时出错"; * goto Eend; * }*/ sI = MyIniFile.SetIniKeyValue(sIniFileName, "Db", "IP", MyStart.gszDbIp); if (sI < 0) { sErrorMessage = "保存 " + sIniFileName + "文件的 Db.IP" + " 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "Db", "Port", MyStart.gszDbPort); if (sI < 0) { sErrorMessage = "保存 " + sIniFileName + "文件的 Db.Port" + " 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "Db", "Srv", MyStart.gszDbSrv); if (sI < 0) { sErrorMessage = "保存 " + sIniFileName + "文件的 Db.Srv" + " 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "Db", "Login", MyStart.gszDbLogin); if (sI < 0) { sErrorMessage = "保存 " + sIniFileName + "文件的 Db.Login" + " 项时出错"; goto Eend; } if (textBox_SrvUserPass.Text.Length <= 8) { sTmp = MyTools.OpenString_To_HideString((textBox_SrvUserPass.Text + " ").Substring(0, 8), MyIniFile.mszIniKey); } else { sTmp = MyTools.OpenString_To_HideString((textBox_SrvUserPass.Text.Substring(0, 8)), MyIniFile.mszIniKey); sTmp += MyTools.OpenString_To_HideString((textBox_SrvUserPass.Text.Substring(8) + " ").Substring(0, 8), MyIniFile.mszIniKey); } sI = MyIniFile.SetIniKeyValue(sIniFileName, "Db", "Pwd", sTmp); if (sI < 0) { sErrorMessage = "保存 " + sIniFileName + "文件的 Db.Pwd" + " 项时出错"; goto Eend; } string szErr = ""; sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "YTB_SRV", MyStart.gszYTBIp, ref szErr); if (sI < 0) { sErrorMessage = "保存益通宝平台.IP" + " 项时出错"; goto Eend; } sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "YTB_PORT", MyStart.gszYTBPort, ref szErr); if (sI < 0) { sErrorMessage = "保存益通宝平台.端口" + " 项时出错"; goto Eend; } sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "RDR_PORT", MyStart.gszRdrPort, ref szErr); if (sI < 0) { sErrorMessage = "保存读卡器.连接端口" + " 项时出错"; goto Eend; } sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "RDR2_PORT", MyStart.gszRdr2Port, ref szErr); if (sI < 0) { sErrorMessage = "保存后台用读卡器.连接端口" + " 项时出错"; goto Eend; } sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "RDR_BAUD", MyStart.gszRdrBaud, ref szErr); if (sI < 0) { sErrorMessage = "保存读卡器.连接波特率" + " 项时出错"; goto Eend; } sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "PS_PORT", MyStart.gszPsPort, ref szErr); if (sI < 0) { sErrorMessage = "保存磅秤.连接端口" + " 项时出错"; goto Eend; } sI = MyFunc.SetSysParaToDb(MyStart.oMyDb, "PS_BAUD", MyStart.gszPsBaud, ref szErr); if (sI < 0) { sErrorMessage = "保存磅秤.连接波特率" + " 项时出错"; goto Eend; } Eend: //string sUserTZM = MyTools.sGetMachineTZM(); //if (MyStart.sUserAuthCode == MyTools.sGetAuthCode(sUserTZM)) // MyStart.bAuthCodeIsOK = true; //else // MyStart.bAuthCodeIsOK = false; button_Edit.Enabled = true; button_Save.Enabled = false; button_Quit.Enabled = false; button_Exit.Enabled = true; groupBox_YTB.Enabled = false; groupBox_RDR.Enabled = false; groupBox_PS.Enabled = false; groupBox_Db.Enabled = false; if (sI < 0) { MessageBox.Show("操作错误:" + sErrorMessage + "。", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MyFunc.WriteToDbLog("修改系统参数", "", "MSG", MyStart.giUserID); //MessageBox.Show("Ini文件保存成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("保存成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } button_Exit.Select(); MyStart.oMyDb.Close(); }
/* * public static void GetIni(ref string szSysLogin, ref string szSysPwd, * ref string szDbIp, ref string szDbPort, ref string szDbSrv, * ref string szDbLogin, ref string szDbPwd) * { * string str = ""; * short sI; * string sIniFileName = Application.StartupPath + mszIniFile; * * sI = MyIniFile.GetIniKeyString(sIniFileName, "Sys", "Login", ref szSysLogin); * if (sI < 0) szSysLogin = "******"; * * sI = MyIniFile.GetIniKeyString(sIniFileName, "Sys", "Pwd", ref str); * if (sI < 0) * { * szSysPwd = "1234567890"; * } * else * { * if (str.Length == 16 && MyTools.StringIsHex(str)) * { * szSysPwd = MyTools.HideString_To_OpenString(str, mszIniKey); * szSysPwd = szSysPwd.Trim(); * } * else * szSysPwd = "1234567890"; * } * * // DB * sI = MyIniFile.GetIniKeyString(sIniFileName, "Db", "IP", ref szDbIp); * if (sI < 0) szDbIp = "rm-bp15ol05h0es8f5eco.mysql.rds.aliyuncs.com"; * sI = MyIniFile.GetIniKeyString(sIniFileName, "Db", "Port", ref szDbPort); * if (sI < 0) szDbPort = "3306"; * sI = MyIniFile.GetIniKeyString(sIniFileName, "Db", "Srv", ref szDbSrv); * if (sI < 0) szDbSrv = "zsmkt"; * sI = MyIniFile.GetIniKeyString(sIniFileName, "Db", "Srv", ref szDbLogin); * if (sI < 0) szDbLogin = "******"; * sI = MyIniFile.GetIniKeyString(sIniFileName, "Db", "Pwd", ref str); * if (sI < 0) * { * szDbPwd = "Ztb_1324"; * } * else * { * if (str.Length == 16 && MyTools.StringIsHex(str)) * { * szDbPwd = MyTools.HideString_To_OpenString(str, mszIniKey); * szDbPwd = szDbPwd.Trim(); * } * else * szDbPwd = "Ztb_1324"; * } * }*/ public static bool SetIni(string SysLogin_New, string SysPwd_New, string KM_IP_New, string KM_PORT_New, string DB_Addr_New, int iSamRd_New, int iRFRd_New) { string str = ""; short sI; string sIniFileName = Application.StartupPath + "\\SYS.ini"; sI = MyIniFile.SetIniKeyValue(sIniFileName, "Sys", "Login", SysLogin_New); if (sI < 0) { str = "保存 " + sIniFileName + " 文件的 Sys.Login 项时出错"; goto Eend; } str = MyTools.OpenString_To_HideString((SysPwd_New + " ").Substring(0, 8), mszIniKey); sI = MyIniFile.SetIniKeyValue(sIniFileName, "Sys", "Pwd", str); if (sI < 0) { str = "保存 " + sIniFileName + "文件的 Sys.Pwd 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "KM", "IP", KM_IP_New); if (sI < 0) { str = "保存 " + sIniFileName + " 文件的 KM.IP 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "KM", "Port", KM_PORT_New); if (sI < 0) { str = "保存 " + sIniFileName + " 文件的 KM.Port 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "DbSrv", "Addr", DB_Addr_New); if (sI < 0) { str = "保存 " + sIniFileName + " 文件的 DbSrv.Addr 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "Comm", "SAM_DEV", iSamRd_New.ToString()); if (sI < 0) { str = "保存 " + sIniFileName + " 文件的 Comm.SAM_DEV 项时出错"; goto Eend; } sI = MyIniFile.SetIniKeyValue(sIniFileName, "Comm", "RF_DEV", iRFRd_New.ToString()); if (sI < 0) { str = "保存 " + sIniFileName + " 文件的 Comm.RF_DEV 项时出错"; goto Eend; } return(true); Eend: MessageBox.Show(str, "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); }