Files
lserp_cs_6.0/其他程序/Lserp_UpdateEmp_jwd/Lserp_UpdateEmp/config.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

110 lines
4.6 KiB
C#

using Lserp_UpdateServer;
using Lskj.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lserp_UpdateDepart
{
public partial class config : Form
{
IniFiles ini = new IniFiles(Application.StartupPath + @"\MyConfig.INI");
bool fg = false;
public config()
{
InitializeComponent();
if (ini.ExistINIFile())
{
txt_domainN.Text = ini.IniReadValue("同步人员", "DomainN");
txt_port.Text = ini.IniReadValue("同步人员", "Port");
txt_timer.Text = ini.IniReadValue("同步人员", "Timer");
txt_Deptnumber.Text = ini.IniReadValue("同步人员", "Deptnumber");
txt_Key.Text = ini.IniReadValue("同步人员", "Key");
}
}
private void btn_ToConfig_Click(object sender, EventArgs e)
{
//将ini文件清空
ini.IniWriteValue(null, null, null);
//判断是否输入的值是否为空
if (string.IsNullOrEmpty(txt_domainN.Text) || string.IsNullOrEmpty(txt_port.Text) || string.IsNullOrEmpty(txt_timer.Text) || string.IsNullOrEmpty(txt_Deptnumber.Text) || string.IsNullOrEmpty(txt_Key.Text))
{
MessageBox.Show("数据有空值请重新输入!");
return;
}
else
{
//判断数据库是否有该配置列
DataTable DT = SqlHelper.ExecuteDataTable(string.Format("select name from syscolumns where id=object_id('P_EmployeeTab') and name='{0}'", txt_Deptnumber.Text));
bool flag = DT.Rows.Count > 0;
if (!flag)
{
MessageBox.Show("保存失败,原因:数据库内无配置的列!");
fg = false;
return;
}
//调用添加接口添加管理员验证配置信息是否可用
DataTable datable = SqlHelper.ExecuteDataTable(string.Format("select LoginAccount as pin,p_emp_EmployeeName as name,SpeciesNo as deptnumber from P_EmployeeTab where p_emp_EmployeeName='管理员'"));
string jsonObj = JsonUtil.ToJsonArray(datable);
string url = string.Format("http://" + txt_domainN.Text + ":" + txt_port.Text + "/api/v2/employee/update/?key={0}", txt_Key.Text);
ResponseMode mode = NewEmp.PostMethodToObj(url, jsonObj);
if (mode.ret != 0)
{
MessageBox.Show("保存失败,原因:请检查域名、端口、key值是否输入正确!");
return;
}
else
{
//成功后调用删除接口删除管理员并将SyncFlag初始化为0
string Delsql = string.Format("select LoginAccount as pin from P_EmployeeTab where p_emp_EmployeeName='管理员'");
DataTable delTable = SqlHelper.ExecuteDataTable(Delsql);
string delurl = string.Format("http://" + txt_domainN.Text + ":" + txt_port.Text + "/api/v2/employee/delete/?key={0}", txt_Key.Text);
jsonObj = JsonUtil.ToJsonArray(delTable);
string deljson = jsonObj.Substring(1, jsonObj.Length - 2);
NewEmp.PostMethodToObj(delurl, deljson);
SqlHelper.ExecuteNonQuery(string.Format("update P_EmployeeTab set SyncFlag = {0}", 0));
}
MessageBox.Show("保存成功!");
ini.IniWriteValue("同步人员", "DomainN", txt_domainN.Text);
ini.IniWriteValue("同步人员", "Port", txt_port.Text);
ini.IniWriteValue("同步人员", "Timer", txt_timer.Text);
ini.IniWriteValue("同步人员", "Deptnumber", txt_Deptnumber.Text);
ini.IniWriteValue("同步人员", "Key", txt_Key.Text);
fg = true;
this.Close();
}
}
private void btn_Close_Click(object sender, EventArgs e)
{
System.Environment.Exit(0);
}
private void config_FormClosing(object sender, FormClosingEventArgs e)
{
if (fg)
{
e.Cancel = false;
}
else
{
MessageBox.Show("请点击配置检测是否输入正确!");
e.Cancel = true;
}
}
}
}