Hello Sir/Madam,
I have created one windows application for Batch Report using C# in which i am logging the data into Sqlite Database table (BatchDetails) .The issue is i want to use same script in multiple project, that's why i want to make that script dynamic, even if
i will add the same script in new project , but i don't want to change in the script.
Now the problem i have faced is, if column name in the table will change, then i have to change in the script to accordingly.
SC_BatchReport Script Module
//--------------------------------------------------------------
// Press F1 to get help about using script.
// To access an object that is not located in the current class, start the call with Globals.
// When using events and timers be cautious not to generate memoryleaks,
// please see the help for more information.
//---------------------------------------------------------------
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.IO; // for ApplicationPath
using System.Reflection; // for ApplicationPath
using System.Collections.Generic; // for List<T>
using System.Data; // for DataTables, DataSets...
using System.Data.SQLite; // for SQLite Database IO
using System.Globalization; // for CultureInfo
using System.Text; // for Stringbuilder
using System.IO.Ports; // for COM...
using Neo.ApplicationFramework.Common.Printer.Document;
using Neo.ApplicationFramework.Tools.Printer;
using Neo.ApplicationFramework.Interfaces.Printer;
using Neo.ApplicationFramework.Tools.OpcClient;
using Core.Api.Service; //IsecurityServiceCF
public partial class SC_BatchReport
{
ISecurityServiceCF securityServiceMessage = ServiceContainerCF.GetService<ISecurityServiceCF>();
public DataTable dtLogData = new DataTable ("DataLogger1");
public DataTable dtAlarmData = new DataTable ("AlarmServer");
public DataTable dtAuditData = new DataTable ("AuditLog");
public DateTime CurrentDate;
public DateTime BatchStartTime;
public DateTime BatchStopTime;
public String UniqueID;
public string excecutingPath;
public DataTable dtBatchDetails = new DataTable ("BatchDetails");
public DataTable dtBatchHeader = new DataTable ("BatchDetails");
string sProjectReportPath;
SerialPort m_port = new SerialPort();
public void ReadFromDataLogger(string fstart, string fstop)
{
dtLogData.Clear();
dtAlarmData.Clear();
// Create a new SQL connection object.
using (var sqlConnection = new SQLiteConnection())
{
// Specify the ConnectionString, with the full path to the database.
excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
try
{
// Tries to open the connection.
sqlConnection.Open();
// Define a query that selects the 10 top data elements
string query = "SELECT time(Time) as Time,BlenderSpeed FROM DataLogger1 Where Time >= '"+fstart+"' and Time <= '"+fstop+"'";
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtLogData);
string query1 = "SELECT Text,ActiveTime,InActiveTime FROM AlarmServer Where ActiveTime >= '"+fstart+"' and ActiveTime <= '"+fstop+"'";
SQLiteDataAdapter sqlda1 = new SQLiteDataAdapter(query1,sqlConnection);
sqlda1.Fill(dtAlarmData);
sqlConnection.Close();
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
}
}
public void ReadFromAuditTrail(string fstart, string fstop)
{
var data = new StringBuilder();
dtAuditData.Clear();
// Create a new SQL connection object.
using (var sqlConnectionAudit = new SQLiteConnection())
{
// Specify the ConnectionString, with the full path to the database.
string excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnectionAudit.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "AuditTrail.db"));
try
{
// Tries to open the connection.
sqlConnectionAudit.Open();
// Define a query that selects the 10 top data elements
string query = "SELECT TimeStamp,Message,ValueBefore As VBefore,ValueAfter As VAfter,UserName As User FROM AuditLog Where TimeStamp >= '"+fstart+"' and TimeStamp <= '"+fstop+"'";
//MessageBox.Show(query);
SQLiteDataAdapter sqlda1 = new SQLiteDataAdapter(query,sqlConnectionAudit);
sqlda1.Fill(dtAuditData);
sqlConnectionAudit.Close();
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
}
}
public void BatchStart()
{
Globals.Tags.BatchStarted.Value=true;
var data = new StringBuilder();
BatchStartTime=DateTime.Now;
Globals.Tags.UniqueID.Value = DateTime.Now.ToString("yyyyMMddHHmmss");
// Create a new SQL connection object.
using (var sqlConnection = new SQLiteConnection())
{
// Specify the ConnectionString, with the full path to the database.
string excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
try
{
// Tries to open the connection.
sqlConnection.Open();
// Define a query that selects the 10 top data elements
Globals.Tags.BatchStartTime.Value=BatchStartTime;
string query = "INSERT INTO BatchDetails (BatchStartTime, BatchStopTime, ProductName, OperatorName, ProductCode, BatchCode, RecipeNo, BatchSize,PrintInterval, UniqueID, TotalNoMixings, Mixing1_Bit,Mixing1,Mixing2_Bit, Mixing2,Mixing3_Bit, Mixing3,Mixing4_Bit, Mixing4,Mixing5_Bit, Mixing5) VALUES ('"+ BatchStartTime +"', '"+Globals.Tags.SystemTagDateTime.Value.ToString() +"', '"+Globals.Tags.PRODUCT_NAME.Value.ToString()+"','"+Globals.Tags.OPERATOR_NAME.Value.ToString() +"','"+Globals.Tags.PRODUCT_CODE.Value.ToString() +"','"+Globals.Tags.BATCH_NO.Value.ToString() +"','"+Globals.Tags.RECIPE_NO.Value.ToString() +"','"+Globals.Tags.BATCH_SIZE.Value.ToString() +"','"+Globals.Tags.PRINT_INTERVAL.Value.ToString() +"','"+Globals.Tags.UniqueID.Value.ToString() +"', '"+Globals.Tags.TOTAL_NO_MIXINGS.Value.ToString() +"','"+Globals.Tags.m240.Value.ToString() +"', '"+Globals.Tags.MIXING_1.Value.ToString() +"','"+Globals.Tags.m241.Value.ToString() +"', '"+Globals.Tags.MIXING_2.Value.ToString() +"','"+Globals.Tags.m242.Value.ToString() +"', '"+Globals.Tags.MIXING_3.Value.ToString() +"','"+Globals.Tags.m243.Value.ToString() +"', '"+Globals.Tags.MIXING_4.Value.ToString() +"','"+Globals.Tags.m244.Value.ToString() +"', '"+Globals.Tags.MIXING_5.Value.ToString() +"'); ";
//MessageBox.Show(query);
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtLogData);
sqlConnection.Close();
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
}
}
public void BatchStop()
{
Globals.Tags.BatchStarted.Value=false;
var data = new StringBuilder();
if( Globals.Tags.UniqueID.Value != null)
{
// Create a new SQL connection object.
using (var sqlConnection = new SQLiteConnection())
{
BatchStopTime=DateTime.Now;
Globals.Tags.Date.Value=BatchStopTime.ToString("dd/MM/yyyy");
Globals.Tags.Time.Value=BatchStopTime.ToString("HH:mm:ss");
Globals.Tags.BatchStopTime.Value=BatchStopTime;
// Specify the ConnectionString, with the full path to the database.
string excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
try
{
// Tries to open the connection.
sqlConnection.Open();
// Define a query that selects the 10 top data elements
Globals.Tags.BatchStopTime.Value = BatchStopTime.ToString();
string query = "UPDATE BatchDetails SET BatchStopTime = '"+BatchStopTime.ToString()+"' WHERE UniqueID = '"+ Globals.Tags.UniqueID.Value +"'";
//MessageBox.Show(query);
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtLogData);
sqlConnection.Close();
Globals.Tags.UniqueID.Value="";
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
}
}
else
{
securityServiceMessage.ShowMessageBoxWithTimeout("Machine was not started", "WARNING");
}
}
public string[] GetStoredReports()
{
string BatchName=string.Empty;
List<string> sReports = new List<string>();
using (var sqlConnection = new SQLiteConnection())
{
string excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
try
{
dtBatchDetails.Clear();
sqlConnection.Open();
string query = "SELECT * FROM BatchDetails LIMIT 10";
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtBatchDetails);
sqlConnection.Close();
sReports.Clear();
foreach (DataRow DR in dtBatchDetails.Rows){
{
foreach(DataColumn dc in dtBatchDetails.Columns)
{
if ((dc.ColumnName == "BatchStartTime") || (dc.ColumnName == "BatchStopTime") || (dc.ColumnName == "BatchCode")) // skip column "Id"
{
if (dc.ColumnName == "BatchCode")
{
BatchName+=DR[dc].ToString();
}
else{BatchName+=DR[dc].ToString()+"_";}
}
}
sReports.Add(BatchName);
BatchName="";
}
}
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
return sReports.ToArray();
}
}
public void DataBase()
{
foreach (DataRow DR in dtLogData.Rows)
{
foreach(DataColumn dc in dtLogData.Columns)
{
MessageBox.Show(DR[dc].ToString());
}
}
}
public void BatchHeader(string IDvalue)
{
if(IDvalue!=null)
{
using (var sqlConnection = new SQLiteConnection())
{
string excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
try
{
dtBatchHeader.Clear();
sqlConnection.Open();
string query = "SELECT BatchStartTime,BatchStopTime,ProductName,OperatorName,ProductCode,BatchCode,RecipeNo,BatchSize,PrintInterval,TotalNoMixings,Mixing1_Bit,Mixing1,Mixing2_Bit,Mixing2,Mixing3_Bit,Mixing3,Mixing4_Bit,Mixing4,Mixing5_Bit,Mixing5 FROM BatchDetails WHERE UniqueID='"+IDvalue+"'";
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtBatchHeader);
}
catch (SQLiteException exception)
{
//MessageBox.Show(exception.ToString());
}
}
}
}
public void Delete(string deleteBatchID, string deleteBatchStartTime, string deleteBatchStopTime)
{
try
{
if(deleteBatchID!=null)
{
using (var sqlConnection = new SQLiteConnection())
{
string excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
dtBatchDetails.Clear();
sqlConnection.Open();
string query = "DELETE FROM BatchDetails WHERE UniqueID='"+deleteBatchID+"'";
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtBatchDetails);
sqlConnection.Close();
//MessageBox.Show("header Deleted successfully");
excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "AuditTrail.db"));
sqlConnection.Open();
query = "DELETE FROM AuditLog Where TimeStamp >= '"+deleteBatchStartTime+"' and TimeStamp <= '"+deleteBatchStopTime+"'";
SQLiteDataAdapter sqlda1 = new SQLiteDataAdapter(query,sqlConnection);
sqlda1.Fill(dtAuditData);
sqlConnection.Close();
//MessageBox.Show("Audit Deleted successfully");
excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
sqlConnection.Open();
query = "DELETE FROM DataLogger1 Where Time >= '"+deleteBatchStartTime+"' and Time <= '"+deleteBatchStopTime+"'";
SQLiteDataAdapter sqlda2 = new SQLiteDataAdapter(query,sqlConnection);
sqlda2.Fill(dtLogData);
//MessageBox.Show("Log value Deleted successfully");
query = "DELETE FROM AlarmServer Where ActiveTime >= '"+deleteBatchStartTime+"' and ActiveTime <= '"+deleteBatchStopTime+"'";
SQLiteDataAdapter sqlda3 = new SQLiteDataAdapter(query,sqlConnection);
sqlda3.Fill(dtAlarmData);
sqlConnection.Close();
securityServiceMessage.ShowMessageBoxWithTimeout("Batch Related Data Deleted successfully", "Batch Status");
//MessageBox.Show("Batch Related Data Deleted successfully");
}
}
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
}
public void PrintReport()
{
Globals.Tags.Date.Value=DateTime.Now.ToString("dd/MM/yyyy");
Globals.Tags.Time.Value=DateTime.Now.ToString("HH:mm:ss");
try
{
StringBuilder sReport = new StringBuilder();
int count=0;
int[] MaxLength={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int RowValueLength=0;
int LastRowValueLength=0;
int columnNumber=0;
if (dtBatchHeader.Rows.Count > 0)
{
columnNumber=columnNumber+1;
foreach(DataColumn dc in dtBatchHeader.Columns)
{
foreach (DataRow DR in dtBatchHeader.Rows)
{
RowValueLength=DR[dc].ToString().Length;
if(LastRowValueLength < RowValueLength)
{
LastRowValueLength=RowValueLength;
}
}
MaxLength[columnNumber]=LastRowValueLength;
LastRowValueLength=0;
RowValueLength=0;
}
}
if (dtBatchHeader.Rows.Count > 0)
{
sReport.Append(" *** Batch Report *** ").AppendLine();
sReport.Append("Date :"+Globals.Tags.Date.Value.ToString()+" Time :"+Globals.Tags.Time.Value.ToString()+"").AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
sReport.Append(" Dr. REDDY'S LABORATORIES LTD. ").AppendLine();
sReport.Append(" FTO- 3, ").AppendLine();
sReport.Append("OCTAGONAL BLENDER EQP ID. :PRE 224").AppendLine();
//sReport.Append("------------------------------------------------------------------------------").AppendLine();
sReport.Append("________________________________________________________________________________").AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
sReport.Append(" SET PARAMETER ").AppendLine();
sReport.AppendLine();
string cs_mixing1_bit = string.Empty;
string cs_mixing2_bit = string.Empty;
string cs_mixing3_bit = string.Empty;
string cs_mixing4_bit = string.Empty;
string cs_mixing5_bit = string.Empty;
foreach (DataRow DR in dtBatchHeader.Rows)
{
foreach(DataColumn dc in dtBatchHeader.Columns)
{
count=count+1;
var field1 = DR[dc];
if(dc.ColumnName =="BatchStartTime")
{
sReport.Append("BATCH START TIME : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="BatchStopTime")
{
sReport.Append("BATCH STOP TIME : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="ProductName")
{
sReport.Append("PRODUCT NAME : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="OperatorName")
{
sReport.Append("OPERATOR NAME : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="ProductCode")
{
sReport.Append("PRODUCT CODE : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="BatchCode")
{
sReport.Append("BATCH CODE : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="RecipeNo")
{
sReport.Append("RECIPE NO. : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="BatchSize")
{
sReport.Append("BATCH SIZE : "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="PrintInterval")
{
sReport.Append("PRINT INTERVAL : "+field1.ToString()).AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
sReport.Append("SET PARAMETERS : ").AppendLine();
}
else if(dc.ColumnName=="TotalNoMixings")
{
sReport.Append("TOTAL NO OF MIXINGS: "+field1.ToString()).AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="Mixing1_Bit")
{
string bitresult = "OFF";
if(field1.ToString() == "False"){bitresult = "OFF";}else{bitresult = "ON";}
cs_mixing1_bit = "MIXINGS 1: "+ bitresult;
}
else if(dc.ColumnName=="Mixing1")
{
sReport.Append(cs_mixing1_bit + " " + field1.ToString()+ " MIN ").AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="Mixing2_Bit")
{
string bitresult = "OFF";
if(field1.ToString() == "False"){bitresult = "OFF";}else{bitresult = "ON";}
cs_mixing2_bit = "MIXINGS 2: "+ bitresult;
}
else if(dc.ColumnName=="Mixing2")
{
sReport.Append(cs_mixing2_bit + " " + field1.ToString()+ " MIN ").AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="Mixing3_Bit")
{
string bitresult = "OFF";
if(field1.ToString() == "False"){bitresult = "OFF";}else{bitresult = "ON";}
cs_mixing3_bit = "MIXINGS 3: "+ bitresult;
}
else if(dc.ColumnName=="Mixing3")
{
sReport.Append(cs_mixing3_bit + " " + field1.ToString()+ " MIN ").AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="Mixing4_Bit")
{
string bitresult = "OFF";
if(field1.ToString() == "False"){bitresult = "OFF";}else{bitresult = "ON";}
cs_mixing4_bit = "MIXINGS 4: "+ bitresult;
}
else if(dc.ColumnName=="Mixing4")
{
sReport.Append(cs_mixing4_bit + " " + field1.ToString()+ " MIN ").AppendLine();
sReport.AppendLine();
}
else if(dc.ColumnName=="Mixing5_Bit")
{
string bitresult = "OFF";
if(field1.ToString() == "False"){bitresult = "OFF";}else{bitresult = "ON";}
cs_mixing5_bit = "MIXINGS 5: "+ bitresult;
}
else if(dc.ColumnName=="Mixing5")
{
sReport.Append(cs_mixing5_bit + " " + field1.ToString()+ " MIN ").AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
}
}
count=0;
}
}
sReport.AppendLine();
//sReport.AppendLine();
//sReport.AppendLine();
//sReport.Append("CHECKED BY Verified By:").AppendLine();
//sReport.AppendLine();
//sReport.Append("Operator :").AppendLine();
//sReport.AppendLine();
//sReport.Append("Pharmacist :").AppendLine();
//sReport.AppendLine();
//sReport.Append("--------------------------------------------------------------------------------------------------------------------------------------").AppendLine();
//MessageBox.Show(sReport.ToString());
OpenPort("COM5", 9600,Parity.None,StopBits.One,8);
m_port.Write(sReport.ToString());
m_port.Close();
sReport.Remove(0,sReport.Length);
PrintBatchLogData();
PrintAlarmReport();
PrintAuditReport();
sReport.AppendLine();
//sReport.AppendLine();
//sReport.AppendLine();
sReport.Remove(0,sReport.Length);
sReport.AppendLine();
sReport.AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
sReport.Append("CHECKED BY Verified By:").AppendLine();
sReport.AppendLine();
sReport.Append("Operator :").AppendLine();
sReport.AppendLine();
sReport.AppendLine();
sReport.AppendLine();
//sReport.Append("--------------------------------------------------------------------------------------------------------------------------------------").AppendLine();
OpenPort("COM5", 9600,Parity.None,StopBits.One,8);
m_port.Write(sReport.ToString());
m_port.Close();
//MessageBox.Show(sReport.ToString());
//PrintMessage(sReport.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
/// <summary>
/// open COM port
/// </summary>
public void OpenPort(string portName, int baudrate, Parity parity, StopBits stopbit, int databits)
{
try
{
m_port.PortName = portName;
m_port.BaudRate = baudrate;
m_port.Parity = parity;
m_port.DataBits = databits;
m_port.StopBits = stopbit;
m_port.ReadTimeout = 1000;
//m_port.ReadBufferSize =50000;
/*m_Timer = new Timer();
m_Timer.Interval = 10000;
m_Timer.Enabled = true;*/
if(!m_port.IsOpen)
{
m_port.Open();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void PrintMessage(string text)
{
IPrinterServiceCF printerService= new PrinterToolCF();
if (printerService != null)
{
Paragraph paragraph = new Paragraph(text);
FlowDocument flowDocument = new FlowDocument();
flowDocument.Blocks.Add(paragraph);
try
{
printerService.SendToPrinterAsync(flowDocument);
MessageBox.Show("Print Data Send to Port Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
MessageBox.Show("No printer device configured!");
}
}
public void CreateReport(string fBatchName ,string fBatchStartTime, string fBatchStopTime)
{
MessageBox.Show("1");
int iFirstDataRow = 54;
string sReportPeriod = fBatchStartTime + " - " + fBatchStopTime;
MessageBox.Show("2");
string sConfigPath = ApplicationPath + @"\Project Files\Config\";
MessageBox.Show("3");
sProjectReportPath = ApplicationPath + @"\Project Files\";
//Make sure that the path and template file name is correct
MessageBox.Show("4");
FlexCel.XlsAdapter.XlsFile xls = new FlexCel.XlsAdapter.XlsFile(sConfigPath + "Template.xls");
MessageBox.Show("5");
// defining a DateTime Cell Format - aligned left
FlexCel.Core.TFlxFormat f1 = xls.GetDefaultFormat;
f1.Format="DD.MM.YYYY hh:mm:ss";
f1.HAlignment = FlexCel.Core.THFlxAlignment.left;
int iFormatDateTime = xls.AddFormat(f1); // first index = 1
// defining a Arial 12 bold underlined Format - aligned left
FlexCel.Core.TFlxFormat f2 = xls.GetDefaultFormat;
f2.HAlignment = FlexCel.Core.THFlxAlignment.left;
FlexCel.Core.TFlxFont ft = new FlexCel.Core.TFlxFont();// generates Arial size 10
ft.Size20 = 240; // 240/20 = 12 pixel
ft.Style = FlexCel.Core.TFlxFontStyles.Bold;
ft.Underline = FlexCel.Core.TFlxUnderline.Single;
f2.Font = ft;
string fBatchNameSufix=fBatchStartTime.Replace(":","");
fBatchNameSufix=fBatchNameSufix.Replace(" ","");
fBatchNameSufix=fBatchNameSufix.Replace("-","");
string sReportName = fBatchName + "_" + fBatchNameSufix;
int iFormatArial12BoldUnderlined = xls.AddFormat(f2);
xls.SetCellValue(4, 2, sReportName);
xls.SetCellValue(4, 4, sReportPeriod);
xls.SetCellValue(50, 2, dtAlarmData.Rows.Count);
xls.SetCellValue(51, 2, dtAuditData.Rows.Count);
xls.SetCellValue(52, 2, dtLogData.Rows.Count);
//xls.SetCellValue(53, 2, dtLoadedRecipes.Rows.Count);
MessageBox.Show("6");
int iRow = iFirstDataRow;
int iCol = 1;
if (dtAlarmData.Rows.Count > 0)
{
xls.SetCellValue(iRow, 1, "Alarms:");
xls.SetCellFormat(iRow, 1, iFormatArial12BoldUnderlined);
iRow++;
// Loop through the Alarm table header
foreach (DataColumn dc in dtAlarmData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
xls.SetCellValue(iRow, iCol, dc.ColumnName);
iCol ++;
}
}
iRow++;
// Loop through the Alarm table rows
foreach (DataRow DR in dtAlarmData.Rows)
{
iCol = 1;
foreach(DataColumn dc in dtAlarmData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
if (dc.ColumnName.Contains("Time"))
{
xls.SetCellFormat(iRow, iCol, iFormatDateTime);
}
var field1 = DR[dc];
xls.SetCellValue(iRow, iCol, field1);
iCol ++;
}
}
iRow ++;
}
iRow++; // "add" an empty line
}
if (dtAuditData.Rows.Count > 0)
{
xls.SetCellValue(iRow, 1, "Events:");
xls.SetCellFormat(iRow, 1, iFormatArial12BoldUnderlined);
iRow++;
iCol = 1;
// Loop through the Events table header
foreach (DataColumn dc in dtAuditData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
xls.SetCellValue(iRow, iCol, dc.ColumnName);
iCol ++;
}
}
iRow++;
// Loop through the Events table rows
foreach (DataRow DR in dtAuditData.Rows)
{
iCol = 1;
foreach(DataColumn dc in dtAuditData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
if (dc.ColumnName.Contains("Time"))
{
xls.SetCellFormat(iRow, iCol, iFormatDateTime);
}
var field1 = DR[dc];
xls.SetCellValue(iRow, iCol, field1);
if (dc.ColumnName == "Message")
{
string sMessage = DR[dc].ToString();
if (sMessage.StartsWith("Load Recipe"))
{
string[] sMessageArray = sMessage.Split(' ');
MessageBox.Show(sMessageArray[2]);
}
}
iCol ++;
}
}
iRow ++;
}
iRow++; // "add" an empty line
}
if (dtLogData.Rows.Count > 0)
{
xls.SetCellValue(iRow, 1, "Logged Data:");
xls.SetCellFormat(iRow, 1, iFormatArial12BoldUnderlined);
iRow++;
iCol = 1;
// Loop through the LogData table header
foreach (DataColumn dc in dtLogData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
xls.SetCellValue(iRow, iCol, dc.ColumnName);
iCol ++;
}
}
iRow++;
// Loop through the LogData table rows
foreach (DataRow DR in dtLogData.Rows)
{
iCol = 1;
foreach(DataColumn dc in dtLogData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
if (dc.ColumnName.Contains("Time"))
{
xls.SetCellFormat(iRow, iCol, iFormatDateTime);
}
var field1 = DR[dc];
xls.SetCellValue(iRow, iCol, field1);
iCol ++;
}
}
iRow ++;
}
iRow++; // "add" an empty line
}
/* if (dtLoadedRecipes.Rows.Count > 0)
{
xls.SetCellValue(iRow, 1, "Loaded Recipes:");
xls.SetCellFormat(iRow, 1, iFormatArial12BoldUnderlined);
iRow++;
iCol = 1;
// Loop through the LoadedRecipes table header
foreach (DataColumn dc in dtLoadedRecipes.Columns)
{
xls.SetCellValue(iRow, iCol, dc.ColumnName);
iCol ++;
}
iRow++;
// Loop through the LoadedRecipes table rows
foreach (DataRow DR in dtLoadedRecipes.Rows)
{
iCol = 1;
foreach(DataColumn dc in dtLoadedRecipes.Columns)
{
if (dc.ColumnName.Contains("Time"))
{
xls.SetCellFormat(iRow, iCol, iFormatDateTime);
}
var field1 = DR[dc];
xls.SetCellValue(iRow, iCol, field1);
iCol ++;
}
iRow ++;
}
}
*/
MessageBox.Show(sReportName);
if (! File.Exists(sProjectReportPath + sReportName + ".xls"))
{
xls.Save(sProjectReportPath + sReportName + ".xls");
//copyfile(sReportName);
}
else
{
//copyfile(sReportName);
}
//copyfile(sReportName);
MessageBox.Show(sReportName);
}
private string ApplicationPath
{
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName); }
}
public void copyfile()
{
try
{
bool UsbPresent = Directory.Exists("\\Hard Disk");
bool NetworkPasent = Directory.Exists("\\MAESTROTEK");
//MessageBox.Show(UsbPresent.ToString());
bool SDCardPresent = Directory.Exists("\\Storage Card");
if (UsbPresent==true)
{
DateTime time1;
time1=DateTime.Now;
string sFilename=time1.ToString("yyyyMMdd_HHmmss");
//sFilename=sFilename.Replace(" ","");
//sFilename=sFilename.Replace("/","");
string sProjectReportPathcopy="\\Hard Disk\\";
//string sProjectReportPathcopy="\\SERVICE-MAESTRO\\share\\";
//sProjectReportPathcopy=@"\\192.168.1.110\Shared\";
sProjectReportPath = ApplicationPath + @"\";
string sConfigPath = ApplicationPath + @"\Project Files\Config\";
File.Copy(sProjectReportPath + "Database" + ".db",sProjectReportPathcopy + sFilename + "DataBase" + ".db");//"AuditTrail.db"
File.Copy(sProjectReportPath + "AuditTrail" + ".db",sProjectReportPathcopy + sFilename + "AuditTrail" + ".db");//"AuditTrail.db"
//File.Copy(sConfigPath + "HeaderData" + ".db",sProjectReportPathcopy + sFilename + "HeaderData" + ".db");
MessageBox.Show("DataBase Backup Succesfuly");
using (var sqlConnection = new SQLiteConnection())
{
//Delete Headers Details:
//string excecutingPath = ApplicationPath + @"\Project Files\Config\";
string excecutingPath = ApplicationPath + @"\";
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
dtBatchDetails.Clear();
sqlConnection.Open();
string query = "DELETE FROM BatchDetails";
SQLiteDataAdapter sqlda = new SQLiteDataAdapter(query,sqlConnection);
sqlda.Fill(dtBatchDetails);
sqlConnection.Close();
MessageBox.Show("Header Deleted Succesfuly");
//Delete Alarm and Data
excecutingPath = ApplicationPath + @"\";
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
dtBatchDetails.Clear();
sqlConnection.Open();
query = "DELETE FROM DataLogger1";
SQLiteDataAdapter sqlda1 = new SQLiteDataAdapter(query,sqlConnection);
sqlda1.Fill(dtLogData);
//Alarm Clear
query = "DELETE FROM AlarmServer";
SQLiteDataAdapter sqlda2 = new SQLiteDataAdapter(query,sqlConnection);
sqlda2.Fill(dtAlarmData);
sqlConnection.Close();
MessageBox.Show("Alarm Deleted Succesfuly");
// Audit Trail Clear.............
excecutingPath = ApplicationPath + @"\";
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "AuditTrail.db"));
dtBatchDetails.Clear();
sqlConnection.Open();
query = "DELETE FROM AuditLog";
SQLiteDataAdapter sqlda3 = new SQLiteDataAdapter(query,sqlConnection);
sqlda3.Fill(dtAuditData);
}
}
else
{
MessageBox.Show("Pendrive Not Found.............");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void BatchTrend(string sFilename)
{
if (dtLogData.Rows.Count > 0)
{
// Loop through the LogData table rows
foreach (DataRow DR in dtLogData.Rows)
{
foreach(DataColumn dc in dtLogData.Columns)
{
if (dc.ColumnName != "Id") // skip column "Id"
{
var field1 = DR[dc];
}
}
}
}
}
public void filesName()
{
//sProjectReportPath = ApplicationPath + @"\\Hard Disk\";
//string sConfigPath = ApplicationPath + @"\Project Files\Config\";
string path = "\\Hard Disk";
try
{
// Only get files that begin with the letter "c."
string[] dirs = Directory.GetFiles(path , ".db");
foreach (string dir in dirs)
{
MessageBox.Show(dir.ToString());
}
}
catch (Exception e)
{
MessageBox.Show(Convert.ToString(e));
//Console.WriteLine("The process failed: {0}", e.ToString());
}
}
public void stringtest( string stringValue, int stringLength)
{
if ((stringValue.Length>stringLength)&&(stringValue!=null))
{
stringValue=stringValue.Substring(0,stringLength);
}
else if((stringValue.Length<=stringLength)&&(stringValue!=null))
{
stringValue=stringValue.PadLeft(stringLength,' ');
}
//string st2=stringValue.
MessageBox.Show(stringValue);
MessageBox.Show(stringValue);
}
public void MyStringFormate()
{
//stringtest(Globals.Tags.BatchName.Value,Globals.Tags.ProductName.Value.Int);
/*if (Globals.Tags.BatchName.Value!=null){
string t1=string.Format("{0:0.00}",Globals.Tags.BatchName.Value.Decimal);
MessageBox.Show(t1);
string t2=string.Format("{0:0.00}",100.01);
MessageBox.Show(t2);
string t3=string.Format("{0:0.00}",100);
MessageBox.Show(t3);
}*/
//MessageBox.Show(Globals.Tags.BatchName.Value.ToString().PadLeft(10,'-'));
}
private GlobalDataItem GetGlobalDataItem(string propertyName)
{
PropertyInfo tagProperty = typeof (Neo.ApplicationFramework.Generated.Tags).GetProperty(propertyName);
if(tagProperty == null)
return null;
else
return tagProperty.GetValue(Globals.Tags, null) as GlobalDataItem;
}
public void ReadAlarmTimeBased(string fstart, string fstop)
{
dtAlarmData.Clear();
// Create a new SQL connection object.
using (var sqlConnection = new SQLiteConnection())
{
// Specify the ConnectionString, with the full path to the database.
excecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
//excecutingPath = ApplicationPath + @"\Project Files\Config\";
sqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(excecutingPath, "Database.db"));
// Using a try/catch in case something goes wrong.
// Should the full path to the database be wrong, it will throw an exception.
// This prevents the termination of the program.
try
{
// Tries to open the connection.
sqlConnection.Open();
string query1 = "SELECT Text,ActiveTime,InActiveTime FROM AlarmServer Where ActiveTime >= '"+fstart+"' and ActiveTime <= '"+fstop+"'";
SQLiteDataAdapter sqlda1 = new SQLiteDataAdapter(query1,sqlConnection);
sqlda1.Fill(dtAlarmData);
sqlConnection.Close();
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
}
}
public void AlarmPrint()
{
Globals.Tags.Date.Value=DateTime.Now.ToString("dd/MM/yyyy");
Globals.Tags.Time.Value=DateTime.Now.ToString("HH:mm:ss");
try
{
StringBuilder sReport = new StringBuilder();
string printdata="";
int count=0;
int[] MaxLength={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int RowValueLength=0;
int LastRowValueLength=0;
int columnNumber=0;
if (dtAlarmData.Rows.Count > 0)
{
columnNumber=columnNumber+1;
foreach(DataColumn dc in dtAlarmData.Columns)
{
foreach (DataRow DR in dtAlarmData.Rows)
{
RowValueLength=DR[dc].ToString().Length;
if(LastRowValueLength < RowValueLength)
{
LastRowValueLength=RowValueLength;
}
}
MaxLength[columnNumber]=LastRowValueLength;
LastRowValueLength=0;
RowValueLength=0;
}
}
if (dtAlarmData.Rows.Count > 0)
{
sReport.Append(" Emcure Pharmaceuticals Ltd. ").AppendLine();
sReport.Append("Date :"+Globals.Tags.Date.Value.ToString()+" Time :"+Globals.Tags.Time.Value.ToString()+"").AppendLine();
//sReport.Append("Equipment ID : "+Globals.Tags.PRODUCT_CODE.Value.ToString()+" ").AppendLine();
sReport.AppendLine();
sReport.AppendLine();
sReport.Append(" Alarm Text Active Time InActive Time").AppendLine();
foreach (DataRow DR in dtAlarmData.Rows)
{
foreach(DataColumn dc in dtAlarmData.Columns)
{
count=count+1;
var field1 = DR[dc];
if(dc.ColumnName =="Text")
{
printdata=field1.ToString();
sReport.Append(" "+printdata.PadRight(30,' '));
}
else if(dc.ColumnName=="ActiveTime")
{
sReport.Append(" "+field1.ToString());
}
else if(dc.ColumnName=="InActiveTime")
{
sReport.Append(" "+field1.ToString());
}
}
sReport.AppendLine();
count=0;
}
}
sReport.AppendLine();
//sReport.AppendLine();
//sReport.AppendLine();
sReport.Append("CHECKED BY Verified By:").AppendLine();
sReport.AppendLine();
sReport.Append("Operator :").AppendLine();
sReport.AppendLine();
sReport.Append("Pharmacist :").AppendLine();
sReport.AppendLine();
sReport.AppendLine();
sReport.AppendLine();
//sReport.Append("--------------------------------------------------------------------------------------------------------------------------------------").AppendLine();
OpenPort("COM5", 9600,Parity.None,StopBits.One,8);
m_port.Write(sReport.ToString());
m_port.Close();
}
catch(Exception ex)
{
}
}
public void PrintAuditReport()
{
try
{
StringBuilder sReport = new StringBuilder();
int count=0;
string[] maxlength = new String[dtAuditData.Columns.Count];
for (int j =0; j < dtAuditData.Columns.Count; j++)
{
int refmaxlength = dtAuditData.Columns[j].ColumnName.ToString().Length;
for (int i =0; i < dtAuditData.Rows.Count; i++)
{
if (refmaxlength < dtAuditData.Rows[i][j].ToString().Length){maxlength[j] = dtAuditData.Rows[i][j].ToString().Length.ToString();refmaxlength = dtAuditData.Rows[i][j].ToString().Length;}
else{ maxlength[j] = refmaxlength.ToString();}
}
// MessageBox.Show(j.ToString()+"" + maxlength[j].ToString());
}
if (dtAuditData.Rows.Count > 0)
{
sReport.AppendLine();
sReport.Append("Audit Trail:").AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
// Loop through the Alarm table header
foreach (DataColumn dc in dtAuditData.Columns)
{
count=count+1;
if(count==1)//|| count==2 || count==3
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
if(count==2)//|| count==2 || count==3
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[1]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==3)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[2]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==4)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[3]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==5)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[4]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
}
sReport.AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
count=0;
foreach (DataRow DR in dtAuditData.Rows)
{
foreach(DataColumn dc in dtAuditData.Columns)
{
count=count+1;
var field1 = DR[dc];
if(count==1)//|| count==2 || count==3
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if( count==2 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[1]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if( count==3 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[2]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if(count==4)
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[3]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if( count==5 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[4]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
/*else if( count==6 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[5]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}*/
}
count=0;
OpenPort("COM5", 9600,Parity.None,StopBits.One,8);
m_port.Write(sReport.ToString());
m_port.Close();
sReport.Remove(0,sReport.Length);
sReport.AppendLine();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void PrintAlarmReport()
{
try
{
StringBuilder sReport = new StringBuilder();
int count=0;
string[] maxlength = new String[dtAlarmData.Columns.Count];
for (int j =0; j < dtAlarmData.Columns.Count; j++)
{
int refmaxlength = dtAlarmData.Columns[j].ColumnName.ToString().Length;
for (int i =0; i < dtAlarmData.Rows.Count; i++)
{
if (refmaxlength < dtAlarmData.Rows[i][j].ToString().Length){maxlength[j] = dtAlarmData.Rows[i][j].ToString().Length.ToString();refmaxlength = dtAlarmData.Rows[i][j].ToString().Length;}
else{ maxlength[j] = refmaxlength.ToString();}
}
// MessageBox.Show(j.ToString()+"" + maxlength[j].ToString());
}
if (dtAlarmData.Rows.Count > 0)
{
sReport.Append("Alarms:").AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
// Loop through the Alarm table header
foreach (DataColumn dc in dtAlarmData.Columns)
{
count=count+1;
if(count==2)//|| count==2 || count==3
{
string columnnametoprint = "Event Time";
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[1]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
if(count==1)//|| count==2 || count==3
{
string columnnametoprint = "Text";
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==3)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[2]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
}
sReport.AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
count=0;
foreach (DataRow DR in dtAlarmData.Rows)
{
foreach(DataColumn dc in dtAlarmData.Columns)
{
count=count+1;
var field1 = DR[dc];
if(count==1)
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if( count==2 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[1]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if( count==3 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[2]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
}
count=0;
OpenPort("COM5", 9600,Parity.None,StopBits.One,8);
m_port.Write(sReport.ToString());
m_port.Close();
sReport.Remove(0,sReport.Length);
sReport.AppendLine();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void PrintBatchLogData()
{
try
{
StringBuilder sReport = new StringBuilder();
int count=0;
string[] maxlength = new String[dtLogData.Columns.Count];
for (int j =0; j < dtLogData.Columns.Count; j++)
{
int refmaxlength = dtLogData.Columns[j].ColumnName.ToString().Length;
for (int i =0; i < dtLogData.Rows.Count; i++)
{
if (refmaxlength < dtLogData.Rows[i][j].ToString().Length){maxlength[j] = dtLogData.Rows[i][j].ToString().Length.ToString();refmaxlength = dtLogData.Rows[i][j].ToString().Length;}
else{ maxlength[j] = refmaxlength.ToString();}
}
// MessageBox.Show(j.ToString()+"" + maxlength[j].ToString());
}
if (dtLogData.Rows.Count > 0)
{
sReport.AppendLine();
sReport.Append("Log Data:").AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
// Loop through the Alarm table header
foreach (DataColumn dc in dtLogData.Columns)
{
count=count+1;
/*if(count==1)//|| count==2 || count==3
{
string columnnametoprint =dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}*/
if(count==1)//|| count==2 || count==3
{
string columnnametoprint =dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==2)
{
string columnnametoprint = "Blender Speed (RPM)";
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[1]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
/*else if(count==4)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[3]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==5)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[4]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}
else if(count==6)
{
string columnnametoprint = dc.ColumnName;
columnnametoprint = columnnametoprint.PadRight(Convert.ToInt32(maxlength[5]),' ');
sReport.Append(columnnametoprint + " | ").ToString();
}*/
}
sReport.AppendLine();
sReport.Append("--------------------------------------------------------------------------------").AppendLine();
count=0;
foreach (DataRow DR in dtLogData.Rows)
{
foreach(DataColumn dc in dtLogData.Columns)
{
count=count+1;
var field1 = DR[dc];
if(count==1)//|| count==2 || count==3
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[0]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if( count==2 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[1]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
/*else if( count==3 )
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[2]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}
else if(count==4)
{
string columnvaluetoprint = field1.ToString();
columnvaluetoprint = columnvaluetoprint.PadRight(Convert.ToInt32(maxlength[3]),' ');
sReport.Append(columnvaluetoprint + " | ").ToString();
}*/
}
count=0;
sReport.AppendLine();
OpenPort("COM5", 9600,Parity.None,StopBits.One,8);
m_port.Write(sReport.ToString());
m_port.Close();
sReport.Remove(0,sReport.Length);
sReport.AppendLine();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
![]()
For reference attached herewith screenshot of application and code snippet.
Please do needful.
Thanks & Regards
MTrush