Files
FG2608061/CODE/20230901/SA17168/AGVSystem Ver2.0/DatabaseSet.cs
T

148 lines
5.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Data.ConnectionUI;
using System.Runtime.InteropServices;
//using Microsoft.Win32;
namespace AGVSystem
{
public partial class DatabaseSet : Form
{
private Point mouseOffset;//记录鼠标指针的坐标
private bool isMouseDown;//记录鼠标左键是否按下
[DllImport("user32.dll")]
private static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
[DllImport("gdi32.dll")]
private static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
private string tempconnectStr;
public DatabaseSet()
{
InitializeComponent();
tempconnectStr = Cls.Param.connectStr;
string[] str = Cls.Param.connectStr.Split(';');
try
{
textBox1.Text = str[0].Split('=')[1];
textBox2.Text = str[1].Split('=')[1];
textBox5.Text = Cls.Param.Pro_id;
textBox3.Text = str[2].Split('=')[1];
if (textBox3.Text == "True") textBox3.Text = "Windows身份验证";
//textBox4.Text = str[3].Split('=')[1];
}
catch
{ }
}
private void savebtn_Click(object sender, EventArgs e)
{
if (Cls.Param.UserName_temp == "" && mainfrm.newmainfrm != null)
{
MessageBox.Show("请登录管理员权限!", "AGV调度管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (Cls.Param.connectStr == tempconnectStr || textBox5.Text.Trim() == "") return;
//Properties.Settings.Default.connectStr = tempconnectStr;
//Properties.Settings.Default.Save();
//RegistryKey key = Registry.LocalMachine;
//RegistryKey software = key.CreateSubKey("Software\\AGV Manager System");
//software.SetValue("conn", tempconnectStr);
//software.SetValue("item_id", Cls.Param.Pro_id);
Cls.FileRW.WriteIniValue("conn", "conn", tempconnectStr, Application.StartupPath + @"\info.ini");
Cls.FileRW.WriteIniValue("item_id", "item_id", Cls.Param.Pro_id, Application.StartupPath + @"\info.ini");
if (mainfrm.newmainfrm != null)
{
MessageBox.Show("数据库连接配置已保存成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("数据库连接配置已保存成功,请重启软件!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
private void button1_Click(object sender, EventArgs e)
{
DataConnectionDialog dialog = new DataConnectionDialog();
dialog.DataSources.Add(DataSource.SqlDataSource);//Sql Server
dialog.SelectedDataSource = DataSource.SqlDataSource;
dialog.SelectedDataProvider = DataProvider.SqlDataProvider;
if (DataConnectionDialog.Show(dialog) == DialogResult.OK)
{
tempconnectStr = dialog.ConnectionString;
string[] str = tempconnectStr.Split(';');
try
{
textBox1.Text = str[0].Split('=')[1];
textBox2.Text = str[1].Split('=')[1];
textBox5.Text = textBox2.Text.Split('_')[2];
tempconnectStr = tempconnectStr.Replace(textBox5.Text, "XXXXX");
Cls.Param.Pro_id = textBox5.Text;
textBox3.Text = str[2].Split('=')[1];
if (textBox3.Text == "True") textBox3.Text = "Windows身份验证";
textBox4.Text = str[3].Split('=')[1];
}
catch
{ }
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void panel3_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{//获取鼠标的位置
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
}
private void panel3_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
isMouseDown = false;
}
}
private void panel3_MouseDown(object sender, MouseEventArgs e)
{
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - 2 * SystemInformation.FrameBorderSize.Width;//减去的属性为窗体边线宽
yOffset = -e.Y - 99;//减去的两个属性分别是标题栏高、窗体边线高。如果FormBorderStyle = None,则上述两句代码不需要减去后面的属性值
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
protected override void OnResize(EventArgs e)
{
//base.OnResize(e);
//IntPtr Rgn = CreateRoundRectRgn(3, 3, this.Width - 2, this.Height - 2, 7, 7);
//SetWindowRgn(this.Handle, Rgn, true);
}
}
}