[go: up one dir, main page]

0% found this document useful (0 votes)
18 views3 pages

CIPReport

The document is a C# code snippet for a Windows Forms UserControl named WINCC_CIPReport, which handles database connections and data loading for a report. It includes properties for server and database configurations, a date filter for querying data, and methods for loading data and exporting to Excel. The control initializes its components and manages user interactions to filter and display report data from a database.

Uploaded by

hoangthekiet186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

CIPReport

The document is a C# code snippet for a Windows Forms UserControl named WINCC_CIPReport, which handles database connections and data loading for a report. It includes properties for server and database configurations, a date filter for querying data, and methods for loading data and exporting to Excel. The control initializes its components and manages user interactions to filter and display report data from a database.

Uploaded by

hoangthekiet186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace RecipesDLL.Report
{
public partial class WINCC_CIPReport : UserControl
{
#region Property
//
private bool windowsAuthentication;
private string serverName;
private string databaseName;
private string userName;
private string password;
private string iniPath = "C:\\AppConfig\\app.ini";
private string _FileAppPath = "C:\\AppConfig\\";

//Add Tag
[Description("Select Tag for control")]
[TypeConverter(typeof(bool)), CategoryAttribute("HTEN Settings")]
public bool WindowsAuthentication { get => windowsAuthentication; set =>
windowsAuthentication = value; }

[Description("Select Tag for control")]


[TypeConverter(typeof(string)), CategoryAttribute("HTEN Settings")]
public string ServerName { get => serverName; set => serverName = value; }

[Description("Select Tag for control")]


[TypeConverter(typeof(string)), CategoryAttribute("HTEN Settings")]
public string DatabaseName { get => databaseName; set => databaseName =
value; }

[Description("Select Tag for control")]


[TypeConverter(typeof(string)), CategoryAttribute("HTEN Settings")]
public string UserName { get => userName; set => userName = value; }

[Description("Select Tag for control")]


[TypeConverter(typeof(string)), CategoryAttribute("HTEN Settings")]
public string Password { get => password; set => password = value; }

[Description("Select Tag for control")]


[TypeConverter(typeof(string)), CategoryAttribute("HTEN Settings")]
public string IniPath { get => iniPath; set => iniPath = value; }
[Description("Select Tag for control")]
[TypeConverter(typeof(string)), CategoryAttribute("HTEN Settings")]
public string FileAppPath { get => _FileAppPath; set => _FileAppPath =
value; }

#endregion Property
public static string objectId = "rptCIP";

U_DateTimeFilter u = new U_DateTimeFilter() { Dock = DockStyle.Fill };


public WINCC_CIPReport()
{
InitializeComponent();
panelDateFilter.Controls.Add(u);
u.btnFilter.Click += BtnFilter_Click;
u.cbType.Enabled = false;

}
private void BtnFilter_Click(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
using (var db = new HTENEntities(Connection.ConnecttionString()))
{
string sql;

sql = string.Format("Select * from CIPMaster_Report where


StartTimeLDT >'" + u.FromDate.ToString("yyyy -MM-dd HH:mm:ss") + "' and EndTimeLDT
<'" + u.ToDate.ToString("yyyy-MM-dd HH:mm:ss") + "' Order by ID");

List<CIPMaster_Report> result =
db.Database.SqlQuery<CIPMaster_Report>(sql).ToList();
eventLogClassBindingSource.DataSource = result;
gridMain.DataSource = result;
bandedGridView3.RefreshData();
}
}

private void WINCC_CIPReport_Load(object sender, EventArgs e)


{
if (DesignMode) { return; }
#region Xử lý chuỗi kết nối database
if (string.IsNullOrEmpty(ServerName) ||
string.IsNullOrEmpty(DatabaseName) || string.IsNullOrEmpty(UserName) ||
string.IsNullOrEmpty(Password))
{
//string location =
System.Reflection.Assembly.GetEntryAssembly().Location;
string directoryPath = IniPath;
IniFile ini = new IniFile(directoryPath);
Connection.WindowsAuthentication =
Convert.ToBoolean(ini.Read("WindowsAuthentication", "Config"));
Connection.ServerName = ini.Read("ServerName", "Config");
Connection.DatabaseName = ini.Read("DatabaseName", "Config");
Connection.UserName = ini.Read("UserName", "Config");
Connection.Password = ini.Read("Password", "Config");
}
else
{
Connection.WindowsAuthentication = windowsAuthentication;
Connection.ServerName = serverName;
Connection.DatabaseName = databaseName;
Connection.UserName = userName;
Connection.Password = password;
}
// HTENEntities.connection =
RecipesKIP1902DLL.Connection.ConnecttionString();

#endregion
// Common.CheckPermission(this, objectId);
Common.LoadLayout(gridMain, objectId, FileAppPath);
//u.cbType.SelectedIndexChanged += cbType_Change;
LoadData();
}

private void btnExportExcel_ItemClick(object sender,


DevExpress.XtraBars.ItemClickEventArgs e)
{
Common.ExportExcel(bandedGridView3, objectId, "From " +
u.deTuNgay.DateTime + " To " + u.deDenNgay.DateTime);
}
}
}

You might also like