sql的配置文件生成
This commit is contained in:
commit
294564d527
2 files changed
+92
-9
No files matched your search
+8
-8
@@ -7,19 +7,19 @@
|
|||||||
mc:Ignorable="d" Title="Sql" Loaded="Window_SQL"
|
mc:Ignorable="d" Title="Sql" Loaded="Window_SQL"
|
||||||
Height="450" Width="248" MaxHeight="450" MaxWidth="248" ResizeMode="NoResize">
|
Height="450" Width="248" MaxHeight="450" MaxWidth="248" ResizeMode="NoResize">
|
||||||
<Grid>
|
<Grid>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,20,0,0" TextWrapping="Wrap" Text=".\" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLIP" HorizontalAlignment="Center" Height="20" Margin="0,20,0,0" TextWrapping="Wrap" Text=".\" VerticalAlignment="Top" Width="144"/>
|
||||||
<ComboBox HorizontalAlignment="Center" Height="20" Margin="0,50,0,0" VerticalAlignment="Top" Width="144">
|
<ComboBox HorizontalAlignment="Center" Height="20" Margin="0,50,0,0" VerticalAlignment="Top" Width="144">
|
||||||
<ComboBoxItem Content="Windows 身份认证"></ComboBoxItem>
|
<ComboBoxItem Content="Windows 身份认证"></ComboBoxItem>
|
||||||
<ComboBoxItem Content="SQL SERVER 身份认证"></ComboBoxItem>
|
<ComboBoxItem Content="SQL SERVER 身份认证"></ComboBoxItem>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,80,0,0" TextWrapping="Wrap" Text="Dispensing" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLNAME" HorizontalAlignment="Center" Height="20" Margin="0,80,0,0" TextWrapping="Wrap" Text="Dispensing" VerticalAlignment="Top" Width="144"/>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,110,0,0" TextWrapping="Wrap" Text="sa" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLUSER" HorizontalAlignment="Center" Height="20" Margin="0,110,0,0" TextWrapping="Wrap" Text="sa" VerticalAlignment="Top" Width="144"/>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,140,0,0" TextWrapping="Wrap" Text="sunlight" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLPASWORD" HorizontalAlignment="Center" Height="20" Margin="0,140,0,0" TextWrapping="Wrap" Text="sunlight" VerticalAlignment="Top" Width="144"/>
|
||||||
<RadioButton Content="连接对象" HorizontalAlignment="Left" Height="19" Margin="52,170,0,0" VerticalAlignment="Top" Width="115"/>
|
<RadioButton Content="连接对象" HorizontalAlignment="Left" Height="19" Margin="52,170,0,0" VerticalAlignment="Top" Width="115"/>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,190,0,0" TextWrapping="Wrap" Text=".\" VerticalAlignment="Top" Width="144" IsEnabled="False"/>
|
<TextBox x:Name="TEXT_SQLIP2" HorizontalAlignment="Center" Height="20" Margin="0,190,0,0" TextWrapping="Wrap" Text=".\" VerticalAlignment="Top" Width="144" IsEnabled="False"/>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,250,0,0" TextWrapping="Wrap" Text="BatchDyeingCentral" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLNAME2" HorizontalAlignment="Center" Height="20" Margin="0,250,0,0" TextWrapping="Wrap" Text="BatchDyeingCentral" VerticalAlignment="Top" Width="144"/>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,280,0,0" TextWrapping="Wrap" Text="sa" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLUSER2" HorizontalAlignment="Center" Height="20" Margin="0,280,0,0" TextWrapping="Wrap" Text="sa" VerticalAlignment="Top" Width="144"/>
|
||||||
<TextBox HorizontalAlignment="Center" Height="20" Margin="0,310,0,0" TextWrapping="Wrap" Text="sunlight" VerticalAlignment="Top" Width="144"/>
|
<TextBox x:Name="TEXT_SQLPASWORD2" HorizontalAlignment="Center" Height="20" Margin="0,310,0,0" TextWrapping="Wrap" Text="sunlight" VerticalAlignment="Top" Width="144"/>
|
||||||
<ComboBox HorizontalAlignment="Center" Height="20" Margin="0,220,0,0" VerticalAlignment="Top" Width="144">
|
<ComboBox HorizontalAlignment="Center" Height="20" Margin="0,220,0,0" VerticalAlignment="Top" Width="144">
|
||||||
<ComboBoxItem Content="Windows 身份认证"></ComboBoxItem>
|
<ComboBoxItem Content="Windows 身份认证"></ComboBoxItem>
|
||||||
<ComboBoxItem Content="SQL SERVER 身份认证"></ComboBoxItem>
|
<ComboBoxItem Content="SQL SERVER 身份认证"></ComboBoxItem>
|
||||||
|
|||||||
+84
-1
@@ -12,6 +12,8 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace formula_manage.Windows
|
namespace formula_manage.Windows
|
||||||
{
|
{
|
||||||
@@ -20,20 +22,101 @@ namespace formula_manage.Windows
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Sql : Window
|
public partial class Sql : Window
|
||||||
{
|
{
|
||||||
|
public class IniFiles
|
||||||
|
{
|
||||||
|
public string path;
|
||||||
|
[DllImport("kernel32")] //返回0表示失败,非0为成功
|
||||||
|
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
||||||
|
[DllImport("kernel32")] //返回取得字符串缓冲区的长度
|
||||||
|
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存ini文件的路径
|
||||||
|
/// 调用示例:var ini = IniFiles("C:\file.ini");
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="INIPath"></param>
|
||||||
|
public IniFiles(string iniPath)
|
||||||
|
{
|
||||||
|
this.path = iniPath;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 写Ini文件
|
||||||
|
/// 调用示例:ini.IniWritevalue("Server","name","localhost");
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Section">[缓冲区]</param>
|
||||||
|
/// <param name="Key">键</param>
|
||||||
|
/// <param name="value">值</param>
|
||||||
|
public void IniWritevalue(string Section, string Key, string value)
|
||||||
|
{
|
||||||
|
WritePrivateProfileString(Section, Key, value, this.path);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 读Ini文件
|
||||||
|
/// 调用示例:ini.IniWritevalue("Server","name");
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Section">[缓冲区]</param>
|
||||||
|
/// <param name="Key">键</param>
|
||||||
|
/// <returns>值</returns>
|
||||||
|
public string IniReadvalue(string Section, string Key)
|
||||||
|
{
|
||||||
|
StringBuilder temp = new StringBuilder(255);
|
||||||
|
|
||||||
|
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
|
||||||
|
return temp.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public Sql()
|
public Sql()
|
||||||
{
|
{
|
||||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string SQL_IP1;
|
||||||
|
string SQL_MOD1;
|
||||||
|
string SQL_NAME1;
|
||||||
|
string SQL_USER1;
|
||||||
|
string SQL_PASWORD1;
|
||||||
|
string SQL_LINK;
|
||||||
|
string SQL_IP2;
|
||||||
|
string SQL_MOD2;
|
||||||
|
string SQL_NAME2;
|
||||||
|
string SQL_USER2;
|
||||||
|
string SQL_PASWORD2;
|
||||||
|
|
||||||
|
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini";
|
||||||
|
|
||||||
private void Window_SQL(object sender, RoutedEventArgs e)
|
private void Window_SQL(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
IniFiles Configini = new IniFiles(INIPath);
|
||||||
|
|
||||||
|
SQL_IP1 = Configini.IniReadvalue("SQL_SERVER", "SQL1");
|
||||||
|
SQL_MOD1 = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
||||||
|
SQL_NAME1 = Configini.IniReadvalue("SQL_SERVER", "SQL3");
|
||||||
|
SQL_USER1 = Configini.IniReadvalue("SQL_SERVER", "SQL4");
|
||||||
|
SQL_PASWORD1 = Configini.IniReadvalue("SQL_SERVER", "SQL5");
|
||||||
|
SQL_LINK = Configini.IniReadvalue("SQL_SERVER", "SQL6");
|
||||||
|
SQL_IP2 = Configini.IniReadvalue("SQL_SERVER", "SQL7");
|
||||||
|
SQL_MOD2 = Configini.IniReadvalue("SQL_SERVER", "SQL8");
|
||||||
|
SQL_NAME2 = Configini.IniReadvalue("SQL_SERVER", "SQL9");
|
||||||
|
SQL_USER2 = Configini.IniReadvalue("SQL_SERVER", "SQL10");
|
||||||
|
SQL_PASWORD2 = Configini.IniReadvalue("SQL_SERVER", "SQL11");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
IniFiles Configini = new IniFiles(INIPath);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL1", SQL_IP1);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL2", SQL_MOD1);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL3", SQL_NAME1);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL4", SQL_USER1);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL5", SQL_PASWORD1);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL6", SQL_LINK);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL7", SQL_IP2);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL8", SQL_MOD2);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL9", SQL_NAME2);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL10", SQL_USER2);
|
||||||
|
Configini.IniWritevalue("SQL_SERVER", "SQL11", SQL_PASWORD2);
|
||||||
|
System.Windows.MessageBox.Show("保存完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_Click_1(object sender, RoutedEventArgs e)
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
Reference in new issue
Block a user