using
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Net;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalReport
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
//当前选中的报表路径
public string Path_Str = "";
//TabPage序列
public int FI = 0;
//RadioButton序列
public int FISUB = 0;
//RadioButton宽度
public int FWidth = 0;
//RadioButton高度
public int FHeight = 0;
//RadioButton行数
public int FLines = 0;
//当前应用程序执行路径
public string FExePath = "";
//IP地址
public string FIP;
//连接字符串
public string FConStr;
//主机名Hostname
public string FHostname;
//数据库Dbname
public string FDbname;
//username
public string FUsername;
//password
public string FPassword;
//创建TabPage
public TabPage[] mTabPage = new TabPage[500];
//创建GroupBox
public GroupBox[] mGroupBox = new GroupBox[500];
//创建RadioButton
public RadioButton[] mRadioButton = new RadioButton[500];
public void CreateAll(DirectoryInfo source)
{
try
{
//判断rpt路径是否存在
if (Directory.Exists(source.FullName) == false)
{
MessageBox.Show(source.FullName + " 不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
//遍历目录
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
//MessageBox.Show(diSourceSubDir.Name, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//实例TabPage
mTabPage[FI] = new TabPage();
mTabPage[FI].Parent = tabControl1;
mTabPage[FI].Text = diSourceSubDir.Name;
mTabPage[FI].TabIndex = FI;
//实例GroupBox
mGroupBox[FI] = new GroupBox();
mGroupBox[FI].Parent = mTabPage[FI];
mGroupBox[FI].Dock = DockStyle.Fill;
mGroupBox[FI].Text = "选择报表";
//行次
int MI = 0;
int x = mGroupBox[FI].Location.X;
int y = mGroupBox[FI].Location.Y;
//遍历文件
foreach (FileInfo fi in diSourceSubDir.GetFiles())
{
//换列显示
if (MI % FLines == 0)
{
if (MI != 0)
{
x = x + FWidth;
y = 0;
MI = 0;
}
}
//实例RadioButton
mRadioButton[FISUB] = new RadioButton();
mRadioButton[FISUB].Parent = mGroupBox[FI];
mRadioButton[FISUB].Location = new System.Drawing.Point(x + 25, y + 15 + MI * FHeight);
mRadioButton[FISUB].Text = fi.Name;
mRadioButton[FISUB].AutoSize = true;
//默认选择第一个
if (mRadioButton[FISUB].Location.Y == 15)
if (mRadioButton[FISUB].Location.X == 25)
mRadioButton[FISUB].Checked = true;
//行次累加
MI = MI + 1;
//当前的RadioButton总Id累加
FISUB = FISUB + 1;
}
//当前的TabPage总Id累加
FI = FI + 1;
//递归
CreateAll(diSourceSubDir);
}
}
catch
{
}
}
//调用kernel32.dll读写ini文件信息
[DllImport("kernel32")]
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);
//写ini
public void IniWriteValue(string Section, string Key, string Value, string filepath)//对ini文件进行写操作的函数
{
try
{
WritePrivateProfileString(Section, Key, Value, filepath);
}
catch
{
}
}
//读ini
public string IniReadValue(string Section, string Key, string filepath) //对ini文件进行读操作的函数
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "无法读取对应的值", temp, 255, filepath);
return temp.ToString();
}
//字符串转换为整型
public static int IntParse(string objValue, int defaultValue)
{
int returnValue = defaultValue;
if (!string.IsNullOrEmpty(objValue))
{
try
{
returnValue = int.Parse(objValue);
}
catch
{
returnValue = defaultValue;
}
}
return returnValue;
}
//reportDocument conn to DB
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
try
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
catch
{
}
}
private void Main_Load(object sender, EventArgs e)
{
try
{
//取得当前路径
FExePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "").Replace("\\", @"\");
//从ini读取RPT存放路径
Path_Str = IniReadValue("PathInfo", "Path", FExePath + "\\CrystalReport.ini");
//DBInfo
FHostname = IniReadValue("DBInfo", "Host", FExePath + "\\CrystalReport.ini");
FDbname = IniReadValue("DBInfo", "Dbname", FExePath + "\\CrystalReport.ini");
FUsername = IniReadValue("DBInfo", "User", FExePath + "\\CrystalReport.ini");
FPassword = IniReadValue("DBInfo", "Pass", FExePath + "\\CrystalReport.ini");
//从ini读取RPT显示信息
FWidth = IntParse(IniReadValue("ViewInfo", "Width", FExePath + "\\CrystalReport.ini"), 160);
FHeight = IntParse(IniReadValue("ViewInfo", "Height", FExePath + "\\CrystalReport.ini"), 25);
FLines = IntParse(IniReadValue("ViewInfo", "Lines", FExePath + "\\CrystalReport.ini"), 8);
//IP地址
IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
FIP = ips[0].ToString();
//连接字符串
FConStr = @"Data Source=" + FHostname + ";Database=" + FDbname + ";User ID=" + FUsername + ";Password=" + FPassword;
}
catch (Exception)
{
MessageBox.Show("CrystalReport.ini配置错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
}
private void Main_Shown(object sender, EventArgs e)
{
try
{
//判断rpt路径是否存在
if (Directory.Exists(Path_Str) == false)
{
MessageBox.Show(Path_Str + " 不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
//窗体定位
Main.ActiveForm.Width = IntParse(IniReadValue("FormInfo", "Width", FExePath + "\\CrystalReport.ini"), 540); ;
Main.ActiveForm.Height = IntParse(IniReadValue("FormInfo", "Height", FExePath + "\\CrystalReport.ini"), 310);
Main.ActiveForm.Left = IntParse(IniReadValue("FormInfo", "Left", FExePath + "\\CrystalReport.ini"), 310);
Main.ActiveForm.Top = IntParse(IniReadValue("FormInfo", "Top", FExePath + "\\CrystalReport.ini"), 310);
//delpage1
tabControl1.TabPages.Clear();
//遍历RPT路径并动态新增页签及radio报表名称
DirectoryInfo diSource = new DirectoryInfo(Path_Str);
CreateAll(diSource);
//addpage1
tabControl1.Controls.Add(mtabPageX);
//条件一 --------------------------------------------------------------------------
cbo10.SelectedIndex = 0;
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
sqlSelectCommand1.CommandText = @"SELECT MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo11.DataSource = DataSet1.Tables["Table1"];
cbo11.DisplayMember = "MA001C";
cbo11.ValueMember = "MA001";
cbo12.DataSource = DataSet1.Tables["Table2"];
cbo12.DisplayMember = "MA001C";
cbo12.ValueMember = "MA001";
//条件二 --------------------------------------------------------------------------
cbo13.SelectedIndex = 0;
DataSet DataSet2 = new DataSet();
SqlDataAdapter SqlDataAdapter2 = new SqlDataAdapter();
SqlCommand sqlSelectCommand2 = new SqlCommand();
SqlConnection sqlConnection2 = new SqlConnection();
//Set the variables.
sqlSelectCommand2.CommandText = @"SELECT MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
sqlSelectCommand2.Connection = sqlConnection2;
sqlConnection2.ConnectionString = FConStr;
SqlDataAdapter2.SelectCommand = sqlSelectCommand2;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter2.Fill(DataSet2, "Table1");
SqlDataAdapter2.Fill(DataSet2, "Table2");
//绑定
cbo14.DataSource = DataSet2.Tables["Table1"];
cbo14.DisplayMember = "MA001C";
cbo14.ValueMember = "MA001";
cbo15.DataSource = DataSet2.Tables["Table2"];
cbo15.DisplayMember = "MA001C";
cbo15.ValueMember = "MA001";
//依据 --------------------------------------------------------------------------
cbo07.SelectedIndex = 0;
DataSet DataSet3 = new DataSet();
SqlDataAdapter SqlDataAdapter3 = new SqlDataAdapter();
SqlCommand sqlSelectCommand3 = new SqlCommand();
SqlConnection sqlConnection3 = new SqlConnection();
//Set the variables.
sqlSelectCommand3.CommandText = @"SELECT MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
sqlSelectCommand3.Connection = sqlConnection3;
sqlConnection3.ConnectionString = FConStr;
SqlDataAdapter3.SelectCommand = sqlSelectCommand3;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter3.Fill(DataSet3, "Table1");
SqlDataAdapter3.Fill(DataSet3, "Table2");
//绑定
cbo08.DataSource = DataSet3.Tables["Table1"];
cbo08.DisplayMember = "MA001C";
cbo08.ValueMember = "MA001";
cbo09.DataSource = DataSet3.Tables["Table2"];
cbo09.DisplayMember = "MA001C";
cbo09.ValueMember = "MA001";
}
catch
{
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//获取当前页签及当前页签选中的报表
string mClass = tabControl1.SelectedTab.Text;
string mRpt = "";
string mRTPPath = "";
if (mClass == "动态环比同比报表")
{
//执行存储过程
String mTYPE, mTIME1_BEGIN, mTIME1_END, mTIME2_BEGIN, mTIME2_END, mBASE;
int mCBO07;
if (rdo01.Checked == true)
{
mTYPE = "1";
}
else
{
mTYPE = "2";
}
mTIME1_BEGIN = ed03.Text;
mTIME1_END = ed04.Text;
mTIME2_BEGIN = ed05.Text;
mTIME2_END = ed06.Text;
mCBO07 = cbo07.SelectedIndex + 1;
mBASE = mCBO07.ToString();
try
{
SqlConnection sqlConnection1 = new SqlConnection(FConStr);
sqlConnection1.Open();
SqlCommand SqlCommand1 = new SqlCommand();
SqlCommand1.CommandText = "SALE_SEARCH_TWO_TIMES";
SqlCommand1.CommandType = CommandType.StoredProcedure;
SqlCommand1.Connection = sqlConnection1;
SqlCommand1.Parameters.Add("@TYPE", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME1_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME1_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME2_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME2_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE1", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE1_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE1_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE2", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE2_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE2_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@BASE", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@IP", SqlDbType.VarChar);
SqlCommand1.Parameters[0].Value = mTYPE;
SqlCommand1.Parameters[1].Value = mTIME1_BEGIN;
SqlCommand1.Parameters[2].Value = mTIME1_END;
SqlCommand1.Parameters[3].Value = mTIME2_BEGIN;
SqlCommand1.Parameters[4].Value = mTIME2_END;
SqlCommand1.Parameters[5].Value = Convert.ToString(cbo10.SelectedIndex + 1);
if (cbo11.SelectedValue == null)
{
SqlCommand1.Parameters[6].Value = "";
}
else
{
SqlCommand1.Parameters[6].Value = cbo11.SelectedValue;
}
if (cbo12.SelectedValue == null)
{
SqlCommand1.Parameters[7].Value = "";
}
else
{
SqlCommand1.Parameters[7].Value = cbo12.SelectedValue;
}
SqlCommand1.Parameters[8].Value = Convert.ToString(cbo13.SelectedIndex + 1);
if (cbo14.SelectedValue == null)
{
SqlCommand1.Parameters[9].Value = "";
}
else
{
SqlCommand1.Parameters[9].Value = cbo14.SelectedValue;
}
if (cbo15.SelectedValue == null)
{
SqlCommand1.Parameters[10].Value = "";
}
else
{
SqlCommand1.Parameters[10].Value = cbo15.SelectedValue;
}
SqlCommand1.Parameters[11].Value = mBASE;
SqlCommand1.Parameters[12].Value = FIP;
Int32 mRowsAffected = SqlCommand1.ExecuteNonQuery();
sqlConnection1.Close();
}
catch (Exception)
{
MessageBox.Show("SALE_SEARCH_TWO_TIMES执行失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
//新建实例
Report_View RPT = new Report_View();
//获得RPT文件路径
if (mClass == "动态环比同比报表")
{
mRpt = "动态环比同比报表.rpt";
mRTPPath = Path_Str + "\\" + "动态环比同比报表.rpt";
}
else
{
for (int MI = 0; MI <= FISUB - 1; MI++)
{
if (mRadioButton[MI].Parent.Parent.Text == mClass)
{
if (mRadioButton[MI].Checked == true)
{
mRpt = mRadioButton[MI].Text;
break;
}
}
}
mRTPPath = Path_Str + "\\" + mClass + "\\" + mRpt;
}
//预览窗口显示
RPT.Text = "预览_" + mRpt;
RPT.Show();
//Load rpt
RPT.RDT1.Load(mRTPPath);
//trans Param
if (mClass == "动态环比同比报表")
{
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterRangeValue rangeVal = new ParameterRangeValue();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
//1
paramField = new ParameterField();
paramField.ParameterFieldName = "依据编号";
if (Convert.ToInt32(cbo08.SelectedValue.ToString()) < Convert.ToInt32(cbo09.SelectedValue.ToString()))
{
rangeVal.StartValue = cbo08.SelectedValue;
rangeVal.EndValue = cbo09.SelectedValue;
}
else
{
rangeVal.StartValue = cbo09.SelectedValue;
rangeVal.EndValue = cbo08.SelectedValue;
}
paramField.CurrentValues.Add(rangeVal);
paramFields.Add(paramField);
//2
paramField = new ParameterField();
paramField.ParameterFieldName = "IP";
discreteVal.Value = FIP;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
RPT.RPT1.ParameterFieldInfo = paramFields;
}
//conn to DB
ConnectionInfo ConnectionInfo1 = new ConnectionInfo();
ConnectionInfo1.DatabaseName = FDbname;
ConnectionInfo1.UserID = FUsername;
ConnectionInfo1.Password = FPassword;
ConnectionInfo1.ServerName = FHostname;
SetDBLogonForReport(ConnectionInfo1, RPT.RDT1);
//Add to Report View
RPT.RPT1.ReportSource = RPT.RDT1;
}
catch
{
}
}
private void cbo07_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//开始、结束两下拉框填值
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
if (cbo07.SelectedIndex == 0)
{
sqlSelectCommand1.CommandText = @"SELECT MA001 AS MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
}
else if (cbo07.SelectedIndex == 1)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='1' ORDER BY MR002";
}
else if (cbo07.SelectedIndex == 2)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='3' ORDER BY MR002";
}
else if (cbo07.SelectedIndex == 3)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='4' ORDER BY MR002";
}
else if (cbo07.SelectedIndex == 4)
{
sqlSelectCommand1.CommandText = @"SELECT ME001 AS MA001,RTRIM(ME001)+'-'+RTRIM(ME002) AS MA001C FROM CMSME ORDER BY ME001";
}
else if (cbo07.SelectedIndex == 5)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo07.SelectedIndex == 6)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo07.SelectedIndex == 7)
{
sqlSelectCommand1.CommandText = @"SELECT MB001 AS MA001,RTRIM(MB001)+'-'+RTRIM(MB002) AS MA001C FROM INVMB ORDER BY MB001";
}
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo08.DataSource = DataSet1.Tables["Table1"];
cbo08.DisplayMember = "MA001C";
cbo08.ValueMember = "MA001";
cbo09.DataSource = DataSet1.Tables["Table2"];
cbo09.DisplayMember = "MA001C";
cbo09.ValueMember = "MA001";
}
catch
{
}
}
private void cbo10_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//开始、结束两下拉框填值
if (cbo10.SelectedIndex != 8)
{
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
if (cbo10.SelectedIndex == 0)
{
sqlSelectCommand1.CommandText = @"SELECT MA001 AS MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
}
else if (cbo10.SelectedIndex == 1)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='1' ORDER BY MR002";
}
else if (cbo10.SelectedIndex == 2)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='3' ORDER BY MR002";
}
else if (cbo10.SelectedIndex == 3)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='4' ORDER BY MR002";
}
else if (cbo10.SelectedIndex == 4)
{
sqlSelectCommand1.CommandText = @"SELECT ME001 AS MA001,RTRIM(ME001)+'-'+RTRIM(ME002) AS MA001C FROM CMSME ORDER BY ME001";
}
else if (cbo10.SelectedIndex == 5)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo10.SelectedIndex == 6)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo10.SelectedIndex == 7)
{
sqlSelectCommand1.CommandText = @"SELECT MB001 AS MA001,RTRIM(MB001)+'-'+RTRIM(MB002) AS MA001C FROM INVMB ORDER BY MB001";
}
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo11.DataSource = DataSet1.Tables["Table1"];
cbo11.DisplayMember = "MA001C";
cbo11.ValueMember = "MA001";
cbo12.DataSource = DataSet1.Tables["Table2"];
cbo12.DisplayMember = "MA001C";
cbo12.ValueMember = "MA001";
}
else
{
cbo11.DataSource = null;
cbo11.DisplayMember = "";
cbo11.ValueMember = "";
cbo12.DataSource = null;
cbo12.DisplayMember = "";
cbo12.ValueMember = "";
}
}
catch
{
}
}
private void cbo13_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//开始、结束两下拉框填值
if (cbo13.SelectedIndex != 8)
{
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
if (cbo13.SelectedIndex == 0)
{
sqlSelectCommand1.CommandText = @"SELECT MA001 AS MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
}
else if (cbo13.SelectedIndex == 1)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='1' ORDER BY MR002";
}
else if (cbo13.SelectedIndex == 2)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='3' ORDER BY MR002";
}
else if (cbo13.SelectedIndex == 3)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='4' ORDER BY MR002";
}
else if (cbo13.SelectedIndex == 4)
{
sqlSelectCommand1.CommandText = @"SELECT ME001 AS MA001,RTRIM(ME001)+'-'+RTRIM(ME002) AS MA001C FROM CMSME ORDER BY ME001";
}
else if (cbo13.SelectedIndex == 5)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo13.SelectedIndex == 6)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo13.SelectedIndex == 7)
{
sqlSelectCommand1.CommandText = @"SELECT MB001 AS MA001,RTRIM(MB001)+'-'+RTRIM(MB002) AS MA001C FROM INVMB ORDER BY MB001";
}
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo14.DataSource = DataSet1.Tables["Table1"];
cbo14.DisplayMember = "MA001C";
cbo14.ValueMember = "MA001";
cbo15.DataSource = DataSet1.Tables["Table2"];
cbo15.DisplayMember = "MA001C";
cbo15.ValueMember = "MA001";
}
else
{
cbo14.DataSource = null;
cbo14.DisplayMember = "";
cbo14.ValueMember = "";
cbo15.DataSource = null;
cbo15.DisplayMember = "";
cbo15.ValueMember = "";
}
}
catch
{
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();//关闭
}
private void Main_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
//保存当前窗口宽高
string mWidth = Main.ActiveForm.Width.ToString();
string mHeight = Main.ActiveForm.Height.ToString();
string mLeft = Main.ActiveForm.Left.ToString();
string mTop = Main.ActiveForm.Top.ToString();
IniWriteValue("FormInfo", "Width", mWidth, FExePath + "\\CrystalReport.ini");
IniWriteValue("FormInfo", "Height", mHeight, FExePath + "\\CrystalReport.ini");
IniWriteValue("FormInfo", "Left", mLeft, FExePath + "\\CrystalReport.ini");
IniWriteValue("FormInfo", "Top", mTop, FExePath + "\\CrystalReport.ini");
}
catch
{
}
}
}
}
C
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Net;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalReport
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
//当前选中的报表路径
public string Path_Str = "";
//TabPage序列
public int FI = 0;
//RadioButton序列
public int FISUB = 0;
//RadioButton宽度
public int FWidth = 0;
//RadioButton高度
public int FHeight = 0;
//RadioButton行数
public int FLines = 0;
//当前应用程序执行路径
public string FExePath = "";
//IP地址
public string FIP;
//连接字符串
public string FConStr;
//主机名Hostname
public string FHostname;
//数据库Dbname
public string FDbname;
//username
public string FUsername;
//password
public string FPassword;
//创建TabPage
public TabPage[] mTabPage = new TabPage[500];
//创建GroupBox
public GroupBox[] mGroupBox = new GroupBox[500];
//创建RadioButton
public RadioButton[] mRadioButton = new RadioButton[500];
public void CreateAll(DirectoryInfo source)
{
try
{
//判断rpt路径是否存在
if (Directory.Exists(source.FullName) == false)
{
MessageBox.Show(source.FullName + " 不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
//遍历目录
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
//MessageBox.Show(diSourceSubDir.Name, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//实例TabPage
mTabPage[FI] = new TabPage();
mTabPage[FI].Parent = tabControl1;
mTabPage[FI].Text = diSourceSubDir.Name;
mTabPage[FI].TabIndex = FI;
//实例GroupBox
mGroupBox[FI] = new GroupBox();
mGroupBox[FI].Parent = mTabPage[FI];
mGroupBox[FI].Dock = DockStyle.Fill;
mGroupBox[FI].Text = "选择报表";
//行次
int MI = 0;
int x = mGroupBox[FI].Location.X;
int y = mGroupBox[FI].Location.Y;
//遍历文件
foreach (FileInfo fi in diSourceSubDir.GetFiles())
{
//换列显示
if (MI % FLines == 0)
{
if (MI != 0)
{
x = x + FWidth;
y = 0;
MI = 0;
}
}
//实例RadioButton
mRadioButton[FISUB] = new RadioButton();
mRadioButton[FISUB].Parent = mGroupBox[FI];
mRadioButton[FISUB].Location = new System.Drawing.Point(x + 25, y + 15 + MI * FHeight);
mRadioButton[FISUB].Text = fi.Name;
mRadioButton[FISUB].AutoSize = true;
//默认选择第一个
if (mRadioButton[FISUB].Location.Y == 15)
if (mRadioButton[FISUB].Location.X == 25)
mRadioButton[FISUB].Checked = true;
//行次累加
MI = MI + 1;
//当前的RadioButton总Id累加
FISUB = FISUB + 1;
}
//当前的TabPage总Id累加
FI = FI + 1;
//递归
CreateAll(diSourceSubDir);
}
}
catch
{
}
}
//调用kernel32.dll读写ini文件信息
[DllImport("kernel32")]
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);
//写ini
public void IniWriteValue(string Section, string Key, string Value, string filepath)//对ini文件进行写操作的函数
{
try
{
WritePrivateProfileString(Section, Key, Value, filepath);
}
catch
{
}
}
//读ini
public string IniReadValue(string Section, string Key, string filepath) //对ini文件进行读操作的函数
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "无法读取对应的值", temp, 255, filepath);
return temp.ToString();
}
//字符串转换为整型
public static int IntParse(string objValue, int defaultValue)
{
int returnValue = defaultValue;
if (!string.IsNullOrEmpty(objValue))
{
try
{
returnValue = int.Parse(objValue);
}
catch
{
returnValue = defaultValue;
}
}
return returnValue;
}
//reportDocument conn to DB
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
try
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
catch
{
}
}
private void Main_Load(object sender, EventArgs e)
{
try
{
//取得当前路径
FExePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "").Replace("\\", @"\");
//从ini读取RPT存放路径
Path_Str = IniReadValue("PathInfo", "Path", FExePath + "\\CrystalReport.ini");
//DBInfo
FHostname = IniReadValue("DBInfo", "Host", FExePath + "\\CrystalReport.ini");
FDbname = IniReadValue("DBInfo", "Dbname", FExePath + "\\CrystalReport.ini");
FUsername = IniReadValue("DBInfo", "User", FExePath + "\\CrystalReport.ini");
FPassword = IniReadValue("DBInfo", "Pass", FExePath + "\\CrystalReport.ini");
//从ini读取RPT显示信息
FWidth = IntParse(IniReadValue("ViewInfo", "Width", FExePath + "\\CrystalReport.ini"), 160);
FHeight = IntParse(IniReadValue("ViewInfo", "Height", FExePath + "\\CrystalReport.ini"), 25);
FLines = IntParse(IniReadValue("ViewInfo", "Lines", FExePath + "\\CrystalReport.ini"), 8);
//IP地址
IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
FIP = ips[0].ToString();
//连接字符串
FConStr = @"Data Source=" + FHostname + ";Database=" + FDbname + ";User ID=" + FUsername + ";Password=" + FPassword;
}
catch (Exception)
{
MessageBox.Show("CrystalReport.ini配置错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
}
private void Main_Shown(object sender, EventArgs e)
{
try
{
//判断rpt路径是否存在
if (Directory.Exists(Path_Str) == false)
{
MessageBox.Show(Path_Str + " 不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
//窗体定位
Main.ActiveForm.Width = IntParse(IniReadValue("FormInfo", "Width", FExePath + "\\CrystalReport.ini"), 540); ;
Main.ActiveForm.Height = IntParse(IniReadValue("FormInfo", "Height", FExePath + "\\CrystalReport.ini"), 310);
Main.ActiveForm.Left = IntParse(IniReadValue("FormInfo", "Left", FExePath + "\\CrystalReport.ini"), 310);
Main.ActiveForm.Top = IntParse(IniReadValue("FormInfo", "Top", FExePath + "\\CrystalReport.ini"), 310);
//delpage1
tabControl1.TabPages.Clear();
//遍历RPT路径并动态新增页签及radio报表名称
DirectoryInfo diSource = new DirectoryInfo(Path_Str);
CreateAll(diSource);
//addpage1
tabControl1.Controls.Add(mtabPageX);
//条件一 --------------------------------------------------------------------------
cbo10.SelectedIndex = 0;
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
sqlSelectCommand1.CommandText = @"SELECT MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo11.DataSource = DataSet1.Tables["Table1"];
cbo11.DisplayMember = "MA001C";
cbo11.ValueMember = "MA001";
cbo12.DataSource = DataSet1.Tables["Table2"];
cbo12.DisplayMember = "MA001C";
cbo12.ValueMember = "MA001";
//条件二 --------------------------------------------------------------------------
cbo13.SelectedIndex = 0;
DataSet DataSet2 = new DataSet();
SqlDataAdapter SqlDataAdapter2 = new SqlDataAdapter();
SqlCommand sqlSelectCommand2 = new SqlCommand();
SqlConnection sqlConnection2 = new SqlConnection();
//Set the variables.
sqlSelectCommand2.CommandText = @"SELECT MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
sqlSelectCommand2.Connection = sqlConnection2;
sqlConnection2.ConnectionString = FConStr;
SqlDataAdapter2.SelectCommand = sqlSelectCommand2;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter2.Fill(DataSet2, "Table1");
SqlDataAdapter2.Fill(DataSet2, "Table2");
//绑定
cbo14.DataSource = DataSet2.Tables["Table1"];
cbo14.DisplayMember = "MA001C";
cbo14.ValueMember = "MA001";
cbo15.DataSource = DataSet2.Tables["Table2"];
cbo15.DisplayMember = "MA001C";
cbo15.ValueMember = "MA001";
//依据 --------------------------------------------------------------------------
cbo07.SelectedIndex = 0;
DataSet DataSet3 = new DataSet();
SqlDataAdapter SqlDataAdapter3 = new SqlDataAdapter();
SqlCommand sqlSelectCommand3 = new SqlCommand();
SqlConnection sqlConnection3 = new SqlConnection();
//Set the variables.
sqlSelectCommand3.CommandText = @"SELECT MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
sqlSelectCommand3.Connection = sqlConnection3;
sqlConnection3.ConnectionString = FConStr;
SqlDataAdapter3.SelectCommand = sqlSelectCommand3;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter3.Fill(DataSet3, "Table1");
SqlDataAdapter3.Fill(DataSet3, "Table2");
//绑定
cbo08.DataSource = DataSet3.Tables["Table1"];
cbo08.DisplayMember = "MA001C";
cbo08.ValueMember = "MA001";
cbo09.DataSource = DataSet3.Tables["Table2"];
cbo09.DisplayMember = "MA001C";
cbo09.ValueMember = "MA001";
}
catch
{
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
//获取当前页签及当前页签选中的报表
string mClass = tabControl1.SelectedTab.Text;
string mRpt = "";
string mRTPPath = "";
if (mClass == "动态环比同比报表")
{
//执行存储过程
String mTYPE, mTIME1_BEGIN, mTIME1_END, mTIME2_BEGIN, mTIME2_END, mBASE;
int mCBO07;
if (rdo01.Checked == true)
{
mTYPE = "1";
}
else
{
mTYPE = "2";
}
mTIME1_BEGIN = ed03.Text;
mTIME1_END = ed04.Text;
mTIME2_BEGIN = ed05.Text;
mTIME2_END = ed06.Text;
mCBO07 = cbo07.SelectedIndex + 1;
mBASE = mCBO07.ToString();
try
{
SqlConnection sqlConnection1 = new SqlConnection(FConStr);
sqlConnection1.Open();
SqlCommand SqlCommand1 = new SqlCommand();
SqlCommand1.CommandText = "SALE_SEARCH_TWO_TIMES";
SqlCommand1.CommandType = CommandType.StoredProcedure;
SqlCommand1.Connection = sqlConnection1;
SqlCommand1.Parameters.Add("@TYPE", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME1_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME1_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME2_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@TIME2_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE1", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE1_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE1_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE2", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE2_BEGIN", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@WHERE2_END", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@BASE", SqlDbType.VarChar);
SqlCommand1.Parameters.Add("@IP", SqlDbType.VarChar);
SqlCommand1.Parameters[0].Value = mTYPE;
SqlCommand1.Parameters[1].Value = mTIME1_BEGIN;
SqlCommand1.Parameters[2].Value = mTIME1_END;
SqlCommand1.Parameters[3].Value = mTIME2_BEGIN;
SqlCommand1.Parameters[4].Value = mTIME2_END;
SqlCommand1.Parameters[5].Value = Convert.ToString(cbo10.SelectedIndex + 1);
if (cbo11.SelectedValue == null)
{
SqlCommand1.Parameters[6].Value = "";
}
else
{
SqlCommand1.Parameters[6].Value = cbo11.SelectedValue;
}
if (cbo12.SelectedValue == null)
{
SqlCommand1.Parameters[7].Value = "";
}
else
{
SqlCommand1.Parameters[7].Value = cbo12.SelectedValue;
}
SqlCommand1.Parameters[8].Value = Convert.ToString(cbo13.SelectedIndex + 1);
if (cbo14.SelectedValue == null)
{
SqlCommand1.Parameters[9].Value = "";
}
else
{
SqlCommand1.Parameters[9].Value = cbo14.SelectedValue;
}
if (cbo15.SelectedValue == null)
{
SqlCommand1.Parameters[10].Value = "";
}
else
{
SqlCommand1.Parameters[10].Value = cbo15.SelectedValue;
}
SqlCommand1.Parameters[11].Value = mBASE;
SqlCommand1.Parameters[12].Value = FIP;
Int32 mRowsAffected = SqlCommand1.ExecuteNonQuery();
sqlConnection1.Close();
}
catch (Exception)
{
MessageBox.Show("SALE_SEARCH_TWO_TIMES执行失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
//新建实例
Report_View RPT = new Report_View();
//获得RPT文件路径
if (mClass == "动态环比同比报表")
{
mRpt = "动态环比同比报表.rpt";
mRTPPath = Path_Str + "\\" + "动态环比同比报表.rpt";
}
else
{
for (int MI = 0; MI <= FISUB - 1; MI++)
{
if (mRadioButton[MI].Parent.Parent.Text == mClass)
{
if (mRadioButton[MI].Checked == true)
{
mRpt = mRadioButton[MI].Text;
break;
}
}
}
mRTPPath = Path_Str + "\\" + mClass + "\\" + mRpt;
}
//预览窗口显示
RPT.Text = "预览_" + mRpt;
RPT.Show();
//Load rpt
RPT.RDT1.Load(mRTPPath);
//trans Param
if (mClass == "动态环比同比报表")
{
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterRangeValue rangeVal = new ParameterRangeValue();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
//1
paramField = new ParameterField();
paramField.ParameterFieldName = "依据编号";
if (Convert.ToInt32(cbo08.SelectedValue.ToString()) < Convert.ToInt32(cbo09.SelectedValue.ToString()))
{
rangeVal.StartValue = cbo08.SelectedValue;
rangeVal.EndValue = cbo09.SelectedValue;
}
else
{
rangeVal.StartValue = cbo09.SelectedValue;
rangeVal.EndValue = cbo08.SelectedValue;
}
paramField.CurrentValues.Add(rangeVal);
paramFields.Add(paramField);
//2
paramField = new ParameterField();
paramField.ParameterFieldName = "IP";
discreteVal.Value = FIP;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
RPT.RPT1.ParameterFieldInfo = paramFields;
}
//conn to DB
ConnectionInfo ConnectionInfo1 = new ConnectionInfo();
ConnectionInfo1.DatabaseName = FDbname;
ConnectionInfo1.UserID = FUsername;
ConnectionInfo1.Password = FPassword;
ConnectionInfo1.ServerName = FHostname;
SetDBLogonForReport(ConnectionInfo1, RPT.RDT1);
//Add to Report View
RPT.RPT1.ReportSource = RPT.RDT1;
}
catch
{
}
}
private void cbo07_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//开始、结束两下拉框填值
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
if (cbo07.SelectedIndex == 0)
{
sqlSelectCommand1.CommandText = @"SELECT MA001 AS MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
}
else if (cbo07.SelectedIndex == 1)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='1' ORDER BY MR002";
}
else if (cbo07.SelectedIndex == 2)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='3' ORDER BY MR002";
}
else if (cbo07.SelectedIndex == 3)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='4' ORDER BY MR002";
}
else if (cbo07.SelectedIndex == 4)
{
sqlSelectCommand1.CommandText = @"SELECT ME001 AS MA001,RTRIM(ME001)+'-'+RTRIM(ME002) AS MA001C FROM CMSME ORDER BY ME001";
}
else if (cbo07.SelectedIndex == 5)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo07.SelectedIndex == 6)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo07.SelectedIndex == 7)
{
sqlSelectCommand1.CommandText = @"SELECT MB001 AS MA001,RTRIM(MB001)+'-'+RTRIM(MB002) AS MA001C FROM INVMB ORDER BY MB001";
}
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo08.DataSource = DataSet1.Tables["Table1"];
cbo08.DisplayMember = "MA001C";
cbo08.ValueMember = "MA001";
cbo09.DataSource = DataSet1.Tables["Table2"];
cbo09.DisplayMember = "MA001C";
cbo09.ValueMember = "MA001";
}
catch
{
}
}
private void cbo10_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//开始、结束两下拉框填值
if (cbo10.SelectedIndex != 8)
{
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
if (cbo10.SelectedIndex == 0)
{
sqlSelectCommand1.CommandText = @"SELECT MA001 AS MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
}
else if (cbo10.SelectedIndex == 1)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='1' ORDER BY MR002";
}
else if (cbo10.SelectedIndex == 2)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='3' ORDER BY MR002";
}
else if (cbo10.SelectedIndex == 3)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='4' ORDER BY MR002";
}
else if (cbo10.SelectedIndex == 4)
{
sqlSelectCommand1.CommandText = @"SELECT ME001 AS MA001,RTRIM(ME001)+'-'+RTRIM(ME002) AS MA001C FROM CMSME ORDER BY ME001";
}
else if (cbo10.SelectedIndex == 5)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo10.SelectedIndex == 6)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo10.SelectedIndex == 7)
{
sqlSelectCommand1.CommandText = @"SELECT MB001 AS MA001,RTRIM(MB001)+'-'+RTRIM(MB002) AS MA001C FROM INVMB ORDER BY MB001";
}
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo11.DataSource = DataSet1.Tables["Table1"];
cbo11.DisplayMember = "MA001C";
cbo11.ValueMember = "MA001";
cbo12.DataSource = DataSet1.Tables["Table2"];
cbo12.DisplayMember = "MA001C";
cbo12.ValueMember = "MA001";
}
else
{
cbo11.DataSource = null;
cbo11.DisplayMember = "";
cbo11.ValueMember = "";
cbo12.DataSource = null;
cbo12.DisplayMember = "";
cbo12.ValueMember = "";
}
}
catch
{
}
}
private void cbo13_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//开始、结束两下拉框填值
if (cbo13.SelectedIndex != 8)
{
DataSet DataSet1 = new DataSet();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlCommand sqlSelectCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection();
//Set the variables.
if (cbo13.SelectedIndex == 0)
{
sqlSelectCommand1.CommandText = @"SELECT MA001 AS MA001,RTRIM(MA001)+'-'+RTRIM(MA002) AS MA001C FROM COPMA ORDER BY MA001";
}
else if (cbo13.SelectedIndex == 1)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='1' ORDER BY MR002";
}
else if (cbo13.SelectedIndex == 2)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='3' ORDER BY MR002";
}
else if (cbo13.SelectedIndex == 3)
{
sqlSelectCommand1.CommandText = @"SELECT MR002 AS MA001,RTRIM(MR002)+'-'+RTRIM(MR003) AS MA001C FROM CMSMR WHERE MR001='4' ORDER BY MR002";
}
else if (cbo13.SelectedIndex == 4)
{
sqlSelectCommand1.CommandText = @"SELECT ME001 AS MA001,RTRIM(ME001)+'-'+RTRIM(ME002) AS MA001C FROM CMSME ORDER BY ME001";
}
else if (cbo13.SelectedIndex == 5)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo13.SelectedIndex == 6)
{
sqlSelectCommand1.CommandText = @"SELECT MV001 AS MA001,RTRIM(MV001)+'-'+RTRIM(MV002) AS MA001C FROM CMSMV ORDER BY MV001";
}
else if (cbo13.SelectedIndex == 7)
{
sqlSelectCommand1.CommandText = @"SELECT MB001 AS MA001,RTRIM(MB001)+'-'+RTRIM(MB002) AS MA001C FROM INVMB ORDER BY MB001";
}
sqlSelectCommand1.Connection = sqlConnection1;
sqlConnection1.ConnectionString = FConStr;
SqlDataAdapter1.SelectCommand = sqlSelectCommand1;
// Fill the data set with the result of the query.
// The results are stored in the data set called "Table1".
SqlDataAdapter1.Fill(DataSet1, "Table1");
SqlDataAdapter1.Fill(DataSet1, "Table2");
//绑定
cbo14.DataSource = DataSet1.Tables["Table1"];
cbo14.DisplayMember = "MA001C";
cbo14.ValueMember = "MA001";
cbo15.DataSource = DataSet1.Tables["Table2"];
cbo15.DisplayMember = "MA001C";
cbo15.ValueMember = "MA001";
}
else
{
cbo14.DataSource = null;
cbo14.DisplayMember = "";
cbo14.ValueMember = "";
cbo15.DataSource = null;
cbo15.DisplayMember = "";
cbo15.ValueMember = "";
}
}
catch
{
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();//关闭
}
private void Main_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
//保存当前窗口宽高
string mWidth = Main.ActiveForm.Width.ToString();
string mHeight = Main.ActiveForm.Height.ToString();
string mLeft = Main.ActiveForm.Left.ToString();
string mTop = Main.ActiveForm.Top.ToString();
IniWriteValue("FormInfo", "Width", mWidth, FExePath + "\\CrystalReport.ini");
IniWriteValue("FormInfo", "Height", mHeight, FExePath + "\\CrystalReport.ini");
IniWriteValue("FormInfo", "Left", mLeft, FExePath + "\\CrystalReport.ini");
IniWriteValue("FormInfo", "Top", mTop, FExePath + "\\CrystalReport.ini");
}
catch
{
}
}
}
}