private void SendMail(string To, string subject, string body)
{
NetworkCredential loginInfo = new NetworkCredential("YOURUSERNAME@gmail.com", "PASSWORD");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("YOURUSERNAME@gmail.com");
msg.To.Add(new MailAddress(To));
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
}
Monday, July 25, 2011
Tuesday, July 19, 2011
CDataAccess
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
namespace DBManager
{
///
/// Summary description for CDataAccess
///
///
#region "CDataAccess Class"
public class CDataAccess
{
#region "Fields and Enums"
// Fields
private SqlConnection connection;
private string connectionString;
private CDataAccess.DataAccessErrors errorCode;
private string errorMessage;
private bool isBeginTransaction;
private bool keepConnectionOpened;
private SqlDataAdapter daDataAdapter;
private DataTable dtDataTable;
private DataView dvDataView;
private SqlCommandBuilder cbCommandBuilder;
// Nested Types
public enum DataAccessErrors
{
Successful = 0,
Failed = 1,
ConnectionOpenFailure = 2,
ConnectionAlreadyOpened = 3,
DataFetchFailure = 4,
DataInsertFailure = 5,
DataUpdateFailure = 6,
ConcurrencyError = 7,
AddNewFailure = 8,
AllowNewFailure = 9,
RecordMovementfailed = 10
//public int value__;
}
#endregion
#region "Properties"
public string ConnectionString
{
get
{
return this.connectionString;
}
set
{
this.connectionString = value;
}
}
public CDataAccess.DataAccessErrors ErrorCode
{
get
{
return this.errorCode;
}
}
public string ErrorMessage
{
get
{
return this.errorMessage;
}
}
#endregion
#region "Constructors"
public CDataAccess()
{
this.connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["saveconnection"].ToString(); ;
connection = new SqlConnection(this.connectionString);
}
public CDataAccess(string connectionString)
{
this.connectionString = connectionString;
this.errorCode = CDataAccess.DataAccessErrors.Successful;
this.errorMessage = "";
this.connection = null;
this.keepConnectionOpened = false;
this.isBeginTransaction = false;
this.ConnectionString = connectionString;
}
#endregion
#region "Connection Related"
public SqlConnection GetConnection()
{
return new SqlConnection(this.connectionString);
}
public bool OpenConnection()
{
bool flag1;
if ((this.connection != null) && (this.connection.State == ConnectionState.Open))
{
this.errorCode = CDataAccess.DataAccessErrors.ConnectionAlreadyOpened;
return true;
}
try
{
this.connection = new SqlConnection(this.connectionString);
this.connection.Open();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
this.errorMessage = "";
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
public void CloseConnection()
{
if (!this.keepConnectionOpened)
{
if ((this.connection != null) && (this.connection.State == ConnectionState.Open))
{
this.connection.Close();
}
this.connection = null;
}
}
#endregion
#region "Parameter Related"
private void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)
{
if ((commandParameters != null) && (parameterValues != null))
{
bool flag1 = commandParameters[0].ParameterName == "@RETURN_VALUE";
if (commandParameters.Length != parameterValues.Length)
{
if (!flag1)
{
throw new ArgumentException("Parameter count does not match Parameter Value count.");
}
if ((commandParameters.Length - parameterValues.Length) != 1)
{
throw new ArgumentException("Parameter count does not match Parameter Value count.");
}
}
if (flag1)
{
int num1 = 1;
int num2 = commandParameters.Length;
while (num1 < num2)
{
commandParameters[num1].Value = parameterValues[num1 - 1];
num1++;
}
}
else
{
int num3 = 0;
int num4 = commandParameters.Length;
while (num3 < num4)
{
commandParameters[num3].Value = parameterValues[num3];
num3++;
}
}
}
}
private void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
{
foreach (SqlParameter parameter1 in commandParameters)
{
if ((parameter1.Direction == ParameterDirection.InputOutput) && (parameter1.Value == null))
{
parameter1.Value = DBNull.Value;
}
command.Parameters.Add(parameter1);
}
}
#endregion
#region "Transaction Related"
public bool BeginTransaction()
{
bool flag1;
try
{
this.GetCommand("Start Transaction;").ExecuteNonQuery();
this.isBeginTransaction = true;
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
public bool CommitTransaction()
{
bool flag1;
try
{
this.GetCommand("Commit;").ExecuteNonQuery();
this.CloseConnection();
this.isBeginTransaction = false;
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
public bool RollbackTransaction()
{
bool flag1;
try
{
this.GetCommand("Rollback;").ExecuteNonQuery();
this.CloseConnection();
this.isBeginTransaction = false;
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
#endregion
#region "Execute SQL and SP"
public int Execute(string StrTSQL)
{
int num2;
try
{
int num1 = this.GetCommand(StrTSQL).ExecuteNonQuery();
num2 = num1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return num2;
}
public DataSet ExecuteSP(string spName)
{
DataSet set2;
try
{
this.OpenConnection();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
DataSet set1 = this.ExecuteSP(spName, null);
if (!this.isBeginTransaction)
{
this.CloseConnection();
}
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSP(SqlTransaction transaction, string spName)
{
DataSet set2;
try
{
DataSet set1 = this.ExecuteSP(transaction, spName, null);
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSP(string spName, params SqlParameter[] commandParameters)
{
DataSet set2;
try
{
this.OpenConnection();
SqlCommand command1 = new SqlCommand();
this.PrepareCommand(command1, null, spName, commandParameters);
SqlDataAdapter adapter1 = new SqlDataAdapter(command1);
DataSet set1 = new DataSet();
adapter1.Fill(set1);
command1.Parameters.Clear();
set2 = set1;
this.CloseConnection();
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSP(SqlTransaction transaction, string spName, params object[] parameterValues)
{
DataSet set2;
try
{
this.connection = transaction.Connection;
DataSet set1 = null;
if ((parameterValues != null) && (parameterValues.Length > 0))
{
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(transaction.Connection, spName, false);
this.AssignParameterValues(parameterArray1, parameterValues);
set1 = this.ExecuteSP(transaction, spName, parameterArray1);
}
else
{
set1 = this.ExecuteSP(transaction, spName);
}
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSPWithDataSet(string spName, params object[] parameterValues)
{
DataSet set1 = null;
if ((parameterValues != null) && (parameterValues.Length > 0))
{
this.OpenConnection();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(this.connection, spName, true);
this.AssignParameterValues(parameterArray1, parameterValues);
return this.ExecuteSP(spName, parameterArray1);
}
this.ExecuteSP(spName);
if (!this.isBeginTransaction)
{
this.CloseConnection();
}
return set1;
}
public int ExecuteSPWithReturn(string spName, params object[] parameterValues)
{
int num1 = 0;
if ((parameterValues != null) && (parameterValues.Length > 0))
{
this.OpenConnection();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(this.connection, spName, true);
this.AssignParameterValues(parameterArray1, parameterValues);
this.ExecuteSP(spName, parameterArray1);
num1 = (int)parameterArray1[0].Value;
}
else
{
this.ExecuteSP(spName);
}
if (!this.isBeginTransaction)
{
this.CloseConnection();
}
return num1;
}
public DataTable ExecuteSPWithReturnDataTable(String spName, params SqlParameter[] CommandParameter)
{
DataTable tmpDataTable = new DataTable();
//try
//{
this.OpenConnection();
SqlCommand sqlCommand = new SqlCommand();
this.PrepareCommand(sqlCommand, null, spName, CommandParameter);
//this.PrepareCommand(sqlCommand, null, spName, CommandParameter);
SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(sqlCommand);
SqlDataAdapter.Fill(tmpDataTable).ToString();
this.CloseConnection();
//}
//catch (SqlException exception1)
//{
// //(exception1.Message);
//}
//Catch exception2 As Exception
// Throw New Exception(exception2.Message)
//End Try
return tmpDataTable;
}
#endregion
#region "Display Message"
public void DisplayMessage(ref Panel pPanel, string sText)
{
Label lblText = new Label();
lblText.Text = sText;
lblText.CssClass = "Red";
lblText.ForeColor = System.Drawing.Color.Red;
lblText.Font.Size = 7;
lblText.Font.Bold = true;
pPanel.Controls.Add(lblText);
}
#endregion
#region "Destructor"
~CDataAccess()
{
if (this.isBeginTransaction)
{
throw new Exception("Begin transaction without Rollback or Commit. Please check your code");
}
}
#endregion
#region "Command Related"
public SqlCommand GetCommand(string StrTSQL)
{
SqlCommand command2;
try
{
SqlCommand command1 = new SqlCommand();
this.OpenConnection();
command1.Connection = this.connection;
command1.CommandText = StrTSQL;
command2 = command1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return command2;
}
public void ExecuteQuery(String strSql)
{
this.OpenConnection();
SqlCommand tmpCommand = new SqlCommand(strSql, this.connection);
tmpCommand.ExecuteNonQuery();
this.CloseConnection();
}
public int ExecuteQuery(String strSql,string dummy)
{
this.OpenConnection();
SqlCommand tmpCommand = new SqlCommand(strSql, this.connection);
int NoofRowsAffected = tmpCommand.ExecuteNonQuery();
this.CloseConnection();
return NoofRowsAffected;
}
private void PrepareCommand(SqlCommand command, SqlTransaction transaction, string commandText, SqlParameter[] commandParameters)
{
//this.PrepareCommand(command1, null, spName, commandParameters);
command.Connection = this.connection;
command.CommandText = commandText;
if (transaction != null)
{
command.Transaction = transaction;
}
command.CommandType = CommandType.StoredProcedure;
if (commandParameters != null)
{
this.AttachParameters(command, commandParameters);
}
}
#endregion
#region "GetDataAdapter"
public SqlDataAdapter GetDataAdapter(string StrSQL)
{
SqlDataAdapter adapter2;
try
{
SqlDataAdapter adapter1 = new SqlDataAdapter(StrSQL, this.connectionString);
adapter2 = adapter1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return adapter2;
}
#endregion
#region "GetDataReader"
public SqlDataReader GetDataReader(string StrSQL)
{
SqlDataReader reader2;
try
{
SqlDataReader reader1 = null;
reader1 = this.GetCommand(StrSQL).ExecuteReader(CommandBehavior.Default);
reader2 = reader1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return reader2;
}
public SqlDataReader GetDataReaderSP(string spName, params SqlParameter[] commandParameters)
{
SqlCommand command1 = new SqlCommand();
this.PrepareCommand(command1, null, spName, commandParameters);
SqlDataAdapter adapter1 = new SqlDataAdapter(command1);
SqlDataReader reader1 = command1.ExecuteReader(CommandBehavior.Default);
command1.Parameters.Clear();
return reader1;
}
public SqlDataReader GetDataReaderSP(string spName, params object[] parameterValues)
{
if ((parameterValues != null) && (parameterValues.Length > 0))
{
this.errorCode = CDataAccess.DataAccessErrors.Successful;
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(this.connection, spName, false);
this.AssignParameterValues(parameterArray1, parameterValues);
return this.GetDataReaderSP(spName, parameterArray1);
}
return this.GetDataReaderSP(spName, null);
}
#endregion
#region "GetDataSet"
public DataSet GetDataSet(string StrSQL, string DateSetName)
{
DataSet set2;
try
{
DataSet set1 = new DataSet();
this.OpenConnection();
new SqlDataAdapter(StrSQL, this.connectionString).Fill(set1, DateSetName);
this.CloseConnection();
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet GetDataSet(string strSQL, string strTable, ref SqlDataAdapter m_DataAdapter, ref DataTable m_DataTable, ref DataView m_DataView)
{
DataSet dsDataSet2 = null;
try
{
this.OpenConnection();
DataSet Set1 = new DataSet();
SqlCommand cmCommand;
cmCommand = new SqlCommand(strSQL, connection);
daDataAdapter = new SqlDataAdapter(cmCommand);
SqlCommandBuilder cbCommandBuilder = new SqlCommandBuilder(daDataAdapter);
//Build the Data Operation SQL if flag is True
cbCommandBuilder.GetUpdateCommand();
DataSet dsDataSet = new DataSet();
m_DataAdapter.Fill(dsDataSet, strTable);
dsDataSet2.Merge(dsDataSet);
dtDataTable = dsDataSet.Tables[0];
dvDataView = dtDataTable.DefaultView;
dvDataView.AllowNew = false;
this.CloseConnection();
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return dsDataSet2;
}
public DataSet GetDataSet(string strSQL, string strTable, ref SqlDataAdapter m_DataAdapter, ref DataSet m_DataSet)
{
this.OpenConnection();
DataSet tmpDataSet = new DataSet();
SqlCommand m_Command;
m_Command = new SqlCommand(strSQL, this.connection);
m_DataAdapter = new SqlDataAdapter(m_Command);
SqlCommandBuilder m_CommandBuilder = new SqlCommandBuilder(m_DataAdapter);
cbCommandBuilder.GetUpdateCommand();
m_DataAdapter.Fill(m_DataSet, strTable);
m_DataSet.Merge(tmpDataSet);
this.CloseConnection();
return m_DataSet;
}
public DataSet GetDataSet(string strSQL, string strTable, ref DataSet m_DataSet)
{
this.OpenConnection();
SqlDataAdapter m_SQL_DataAdapter;
SqlCommand m_SQL_Command;
DataSet tmpDataSet = new DataSet();
m_SQL_Command = new SqlCommand(strSQL, this.connection);
m_SQL_DataAdapter = new SqlDataAdapter(m_SQL_Command);
m_SQL_DataAdapter.Fill(tmpDataSet, strTable);
m_DataSet.Merge(tmpDataSet);
this.CloseConnection();
return m_DataSet;
}
public DataSet GetDataSet(string strSQL, string strTable, ref DataSet m_DataSet, int BuildCommand)
{
this.OpenConnection();
DataSet tmpDataSet = new DataSet();
SqlCommand cmCommand;
cmCommand = new SqlCommand(strSQL, this.connection);
daDataAdapter = new SqlDataAdapter(cmCommand);
cbCommandBuilder = new SqlCommandBuilder(daDataAdapter);
cbCommandBuilder.GetUpdateCommand();
daDataAdapter.Fill(m_DataSet, strTable);
m_DataSet.Merge(tmpDataSet);
this.CloseConnection();
return m_DataSet;
}
#endregion
#region "GetDataTable"
public DataTable GetDataTable(string strSQL)
{
this.OpenConnection();
SqlCommand m_Command;
m_Command = new SqlCommand(strSQL, this.connection);
SqlDataAdapter tmpDataAdapter;
tmpDataAdapter = new SqlDataAdapter(m_Command);
DataTable tmpDataTable = new DataTable();
tmpDataAdapter.Fill(tmpDataTable);
this.CloseConnection();
return tmpDataTable;
}
#endregion
#region "FillCombo"
public void FillCombo(ref DropDownList Combo, string strSQL, bool AddAllOption, bool None)
{
DataTable dtTable = GetDataTable(strSQL);
if ((None))
{
DataRow drDataRow;
drDataRow = dtTable.NewRow();
drDataRow[0] = -1;
drDataRow[1] = "";
dtTable.Rows.Add(drDataRow);
}
if ((AddAllOption))
{
DataRow drDataRow;
drDataRow = dtTable.NewRow();
drDataRow[0] = 0;
drDataRow[1] = "_ALL_";
dtTable.Rows.Add(drDataRow);
}
{
DataView DataView = dtTable.DefaultView;
DataView.Sort = dtTable.Columns[1].ColumnName;
Combo.DataSource = DataView;
Combo.DataTextField = dtTable.Columns[1].ColumnName;
Combo.DataValueField = dtTable.Columns[0].ColumnName;
Combo.DataBind();
}
}
#endregion
#region "SqlParameterCache Class"
public sealed class SqlParameterCache
{
// Methods
static SqlParameterCache()
{
CDataAccess.SqlParameterCache.paramCache = Hashtable.Synchronized(new Hashtable());
}
private SqlParameterCache()
{
}
private static void CacheParameterSet(string connectionString, string spName, params SqlParameter[] commandParameters)
{
string text1 = connectionString + ":" + spName;
CDataAccess.SqlParameterCache.paramCache[text1] = commandParameters;
}
private static SqlParameter[] CloneParameters(SqlParameter[] originalParameters)
{
SqlParameter[] parameterArray1 = new SqlParameter[originalParameters.Length];
int num1 = 0;
int num2 = originalParameters.Length;
while (num1 < num2)
{
parameterArray1[num1] = (SqlParameter)((ICloneable)originalParameters[num1]).Clone();
num1++;
}
return parameterArray1;
}
private static SqlParameter[] DiscoverSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter)
{
using (SqlCommand command1 = new SqlCommand(spName, connection))
{
command1.CommandType = CommandType.StoredProcedure;
SqlCommandBuilder.DeriveParameters(command1);
if (!includeReturnValueParameter)
{
command1.Parameters.RemoveAt(0);
}
SqlParameter[] parameterArray1 = new SqlParameter[command1.Parameters.Count];
command1.Parameters.CopyTo(parameterArray1, 0);
return parameterArray1;
}
}
private static SqlParameter[] GetCachedParameterSet(string connectionString, string spName)
{
string text1 = connectionString + ":" + spName;
SqlParameter[] parameterArray1 = (SqlParameter[])CDataAccess.SqlParameterCache.paramCache[text1];
if (parameterArray1 == null)
{
return null;
}
return CDataAccess.SqlParameterCache.CloneParameters(parameterArray1);
}
public static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName)
{
return CDataAccess.SqlParameterCache.GetSpParameterSet(connection, spName, false);
}
public static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter)
{
string text1 = connection.ConnectionString + ":" + spName + (includeReturnValueParameter ? ":include ReturnValue Parameter" : "");
SqlParameter[] parameterArray1 = (SqlParameter[])CDataAccess.SqlParameterCache.paramCache[text1];
if (parameterArray1 == null)
{
object obj1;
CDataAccess.SqlParameterCache.paramCache[text1] = obj1 = CDataAccess.SqlParameterCache.DiscoverSpParameterSet(connection, spName, includeReturnValueParameter);
parameterArray1 = (SqlParameter[])obj1;
}
return CDataAccess.SqlParameterCache.CloneParameters(parameterArray1);
}
// Fields
private static Hashtable paramCache;
}
#endregion
//Open file into a filestream and
//read data in a byte array.
public byte[] ReadFile(string sPath)
{
//Initialize byte array with a null value initially.
byte[] data = null;
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
//Open FileStream to read file
FileStream fStream = new FileStream(sPath, FileMode.Open,
FileAccess.Read);
//Use BinaryReader to read file stream into byte array.
BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to
//supply number of bytes to read from file.
//In this case we want to read entire file.
//So supplying total number of bytes.
data = br.ReadBytes((int)numBytes);
return data;
}
#region "InitializeGrid"
//public void InitializeGrid(ref UltraWebGrid Grid)
//{
// // Grid.JavaScriptFileName = "../../infragistics/scripts/ig_WebGrid.js";
// //Grid.JavaScriptFileNameCommon = "../../infragistics/scripts/ig_csom.js";
// Grid.DisplayLayout.AllowColSizingDefault = AllowSizing.Free;
// Grid.DisplayLayout.AllowColumnMovingDefault = Infragistics.WebUI.UltraWebGrid.AllowColumnMoving.OnServer;
// Grid.DisplayLayout.AllowSortingDefault = AllowSorting.OnClient;
// Grid.DisplayLayout.CellClickActionDefault = CellClickAction.RowSelect;
// Grid.DisplayLayout.CellPaddingDefault = 1;
// Grid.DisplayLayout.ColHeadersVisibleDefault = ShowMarginInfo.Yes;
// Grid.DisplayLayout.HeaderClickActionDefault = HeaderClickAction.SortSingle;
// //Header Style
// Grid.DisplayLayout.HeaderStyleDefault.CssClass = "GridHeader";
// Grid.DisplayLayout.HeaderStyleDefault.Font.Bold = true;
// //Sort
// Grid.DisplayLayout.AllowSortingDefault = Infragistics.WebUI.UltraWebGrid.AllowSorting.OnClient;
// Grid.DisplayLayout.HeaderClickActionDefault = Infragistics.WebUI.UltraWebGrid.HeaderClickAction.SortSingle;
// Grid.DisplayLayout.NoDataMessage = "No Records Found";
// Grid.DisplayLayout.NullTextDefault = "";
// Grid.DisplayLayout.RowStyleDefault.CssClass = "GridRowEven";
// Grid.DisplayLayout.RowAlternateStyleDefault.CssClass = "GridRowOdd";
// //Grid.DisplayLayout.RowAlternateStyleDefault.BackColor = Drawing.Color.FromArgb(255, 255, 215);
// //Grid.DisplayLayout.RowAlternateStyleDefault.BackColor = Gray;
// //Padding
// Grid.DisplayLayout.CellPaddingDefault = 3;
// Grid.DisplayLayout.RowAlternateStyleDefault.TextOverflow = TextOverflow.Ellipsis;
// Grid.DisplayLayout.RowHeightDefault = 25;
// Grid.DisplayLayout.RowSelectorsDefault = RowSelectors.No;
// Grid.DisplayLayout.RowSizingDefault = AllowSizing.Fixed;
// Grid.DisplayLayout.ScrollBar = ScrollBar.Auto;
// Grid.DisplayLayout.ScrollBarView = ScrollBarView.Both;
// Grid.DisplayLayout.SelectedRowStyleDefault.CssClass = "GridSelectedRow";
// Grid.DisplayLayout.SelectTypeCellDefault = SelectType.None;
// Grid.DisplayLayout.SelectTypeColDefault = SelectType.None;
// Grid.DisplayLayout.SelectTypeRowDefault = SelectType.Single;
// Grid.DisplayLayout.StationaryMargins = StationaryMargins.No;
// Grid.DisplayLayout.TabDirection = TabDirection.LeftToRight;
// Grid.DisplayLayout.ViewType = Infragistics.WebUI.UltraWebGrid.ViewType.Flat;
// Grid.CssClass = "Grid";
// Grid.BorderStyle = BorderStyle.Solid;
//}
#endregion
public string VoucherNumber(String strHead)
{
String strSql;
String strCode;
DataTable tmpDataTable;
strSql = "SELECT * FROM tblAutoNumber ";
strSql += "WHERE Head = '" + strHead + "'";
tmpDataTable = GetDataTable(strSql);
strCode = tmpDataTable.Rows[0]["Prefix"] + "/";
strCode += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "/";
strCode += Convert.ToString(Convert.ToInt32(tmpDataTable.Rows[0]["Number"]) + 1);
if (Convert.ToString(tmpDataTable.Rows[0]["SufixCheck"]) == "True")
{
strCode += "/" + tmpDataTable.Rows[0]["Sufix"];
}
return (strCode);
}
//public void AddValueListItemToGrid(ref Infragistics.WebUI.UltraWebGrid.UltraWebGrid Grid, String strSQL, int ColumnIndex) //int BandIndex = 0
//{
// Int32 iCount;
// Infragistics.WebUI.UltraWebGrid.ValueList vValue = new ValueList();
// DataTable tmpDataTable = GetDataTable(strSQL);
// //vValue = Grid.DisplayLayout.ValueLists.Add
// for (iCount = 0; iCount <= tmpDataTable.Rows.Count - 1; iCount++)
// {
// //vValue.ValueListItems.Add(tmpDataTable.Rows[iCount][0],(tmpDataTable.Rows[iCount][1])=null, "", tmpDataTable.Rows[iCount][1]);
// vValue.ValueListItems.Add(tmpDataTable.Rows[iCount][1]);
// }
// vValue.DisplayStyle = Infragistics.WebUI.UltraWebGrid.ValueListDisplayStyle.DisplayText;
// //vValue.SortStyle = Infragistics.Win.ValueListSortStyle.Ascending
// Grid.DisplayLayout.Bands[0].Columns[ColumnIndex].ValueList = vValue;
//}
}
#endregion
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
namespace DBManager
{
///
/// Summary description for CDataAccess
///
///
#region "CDataAccess Class"
public class CDataAccess
{
#region "Fields and Enums"
// Fields
private SqlConnection connection;
private string connectionString;
private CDataAccess.DataAccessErrors errorCode;
private string errorMessage;
private bool isBeginTransaction;
private bool keepConnectionOpened;
private SqlDataAdapter daDataAdapter;
private DataTable dtDataTable;
private DataView dvDataView;
private SqlCommandBuilder cbCommandBuilder;
// Nested Types
public enum DataAccessErrors
{
Successful = 0,
Failed = 1,
ConnectionOpenFailure = 2,
ConnectionAlreadyOpened = 3,
DataFetchFailure = 4,
DataInsertFailure = 5,
DataUpdateFailure = 6,
ConcurrencyError = 7,
AddNewFailure = 8,
AllowNewFailure = 9,
RecordMovementfailed = 10
//public int value__;
}
#endregion
#region "Properties"
public string ConnectionString
{
get
{
return this.connectionString;
}
set
{
this.connectionString = value;
}
}
public CDataAccess.DataAccessErrors ErrorCode
{
get
{
return this.errorCode;
}
}
public string ErrorMessage
{
get
{
return this.errorMessage;
}
}
#endregion
#region "Constructors"
public CDataAccess()
{
this.connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["saveconnection"].ToString(); ;
connection = new SqlConnection(this.connectionString);
}
public CDataAccess(string connectionString)
{
this.connectionString = connectionString;
this.errorCode = CDataAccess.DataAccessErrors.Successful;
this.errorMessage = "";
this.connection = null;
this.keepConnectionOpened = false;
this.isBeginTransaction = false;
this.ConnectionString = connectionString;
}
#endregion
#region "Connection Related"
public SqlConnection GetConnection()
{
return new SqlConnection(this.connectionString);
}
public bool OpenConnection()
{
bool flag1;
if ((this.connection != null) && (this.connection.State == ConnectionState.Open))
{
this.errorCode = CDataAccess.DataAccessErrors.ConnectionAlreadyOpened;
return true;
}
try
{
this.connection = new SqlConnection(this.connectionString);
this.connection.Open();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
this.errorMessage = "";
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
public void CloseConnection()
{
if (!this.keepConnectionOpened)
{
if ((this.connection != null) && (this.connection.State == ConnectionState.Open))
{
this.connection.Close();
}
this.connection = null;
}
}
#endregion
#region "Parameter Related"
private void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)
{
if ((commandParameters != null) && (parameterValues != null))
{
bool flag1 = commandParameters[0].ParameterName == "@RETURN_VALUE";
if (commandParameters.Length != parameterValues.Length)
{
if (!flag1)
{
throw new ArgumentException("Parameter count does not match Parameter Value count.");
}
if ((commandParameters.Length - parameterValues.Length) != 1)
{
throw new ArgumentException("Parameter count does not match Parameter Value count.");
}
}
if (flag1)
{
int num1 = 1;
int num2 = commandParameters.Length;
while (num1 < num2)
{
commandParameters[num1].Value = parameterValues[num1 - 1];
num1++;
}
}
else
{
int num3 = 0;
int num4 = commandParameters.Length;
while (num3 < num4)
{
commandParameters[num3].Value = parameterValues[num3];
num3++;
}
}
}
}
private void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
{
foreach (SqlParameter parameter1 in commandParameters)
{
if ((parameter1.Direction == ParameterDirection.InputOutput) && (parameter1.Value == null))
{
parameter1.Value = DBNull.Value;
}
command.Parameters.Add(parameter1);
}
}
#endregion
#region "Transaction Related"
public bool BeginTransaction()
{
bool flag1;
try
{
this.GetCommand("Start Transaction;").ExecuteNonQuery();
this.isBeginTransaction = true;
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
public bool CommitTransaction()
{
bool flag1;
try
{
this.GetCommand("Commit;").ExecuteNonQuery();
this.CloseConnection();
this.isBeginTransaction = false;
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
public bool RollbackTransaction()
{
bool flag1;
try
{
this.GetCommand("Rollback;").ExecuteNonQuery();
this.CloseConnection();
this.isBeginTransaction = false;
flag1 = true;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return flag1;
}
#endregion
#region "Execute SQL and SP"
public int Execute(string StrTSQL)
{
int num2;
try
{
int num1 = this.GetCommand(StrTSQL).ExecuteNonQuery();
num2 = num1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return num2;
}
public DataSet ExecuteSP(string spName)
{
DataSet set2;
try
{
this.OpenConnection();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
DataSet set1 = this.ExecuteSP(spName, null);
if (!this.isBeginTransaction)
{
this.CloseConnection();
}
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSP(SqlTransaction transaction, string spName)
{
DataSet set2;
try
{
DataSet set1 = this.ExecuteSP(transaction, spName, null);
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSP(string spName, params SqlParameter[] commandParameters)
{
DataSet set2;
try
{
this.OpenConnection();
SqlCommand command1 = new SqlCommand();
this.PrepareCommand(command1, null, spName, commandParameters);
SqlDataAdapter adapter1 = new SqlDataAdapter(command1);
DataSet set1 = new DataSet();
adapter1.Fill(set1);
command1.Parameters.Clear();
set2 = set1;
this.CloseConnection();
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSP(SqlTransaction transaction, string spName, params object[] parameterValues)
{
DataSet set2;
try
{
this.connection = transaction.Connection;
DataSet set1 = null;
if ((parameterValues != null) && (parameterValues.Length > 0))
{
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(transaction.Connection, spName, false);
this.AssignParameterValues(parameterArray1, parameterValues);
set1 = this.ExecuteSP(transaction, spName, parameterArray1);
}
else
{
set1 = this.ExecuteSP(transaction, spName);
}
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet ExecuteSPWithDataSet(string spName, params object[] parameterValues)
{
DataSet set1 = null;
if ((parameterValues != null) && (parameterValues.Length > 0))
{
this.OpenConnection();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(this.connection, spName, true);
this.AssignParameterValues(parameterArray1, parameterValues);
return this.ExecuteSP(spName, parameterArray1);
}
this.ExecuteSP(spName);
if (!this.isBeginTransaction)
{
this.CloseConnection();
}
return set1;
}
public int ExecuteSPWithReturn(string spName, params object[] parameterValues)
{
int num1 = 0;
if ((parameterValues != null) && (parameterValues.Length > 0))
{
this.OpenConnection();
this.errorCode = CDataAccess.DataAccessErrors.Successful;
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(this.connection, spName, true);
this.AssignParameterValues(parameterArray1, parameterValues);
this.ExecuteSP(spName, parameterArray1);
num1 = (int)parameterArray1[0].Value;
}
else
{
this.ExecuteSP(spName);
}
if (!this.isBeginTransaction)
{
this.CloseConnection();
}
return num1;
}
public DataTable ExecuteSPWithReturnDataTable(String spName, params SqlParameter[] CommandParameter)
{
DataTable tmpDataTable = new DataTable();
//try
//{
this.OpenConnection();
SqlCommand sqlCommand = new SqlCommand();
this.PrepareCommand(sqlCommand, null, spName, CommandParameter);
//this.PrepareCommand(sqlCommand, null, spName, CommandParameter);
SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(sqlCommand);
SqlDataAdapter.Fill(tmpDataTable).ToString();
this.CloseConnection();
//}
//catch (SqlException exception1)
//{
// //(exception1.Message);
//}
//Catch exception2 As Exception
// Throw New Exception(exception2.Message)
//End Try
return tmpDataTable;
}
#endregion
#region "Display Message"
public void DisplayMessage(ref Panel pPanel, string sText)
{
Label lblText = new Label();
lblText.Text = sText;
lblText.CssClass = "Red";
lblText.ForeColor = System.Drawing.Color.Red;
lblText.Font.Size = 7;
lblText.Font.Bold = true;
pPanel.Controls.Add(lblText);
}
#endregion
#region "Destructor"
~CDataAccess()
{
if (this.isBeginTransaction)
{
throw new Exception("Begin transaction without Rollback or Commit. Please check your code");
}
}
#endregion
#region "Command Related"
public SqlCommand GetCommand(string StrTSQL)
{
SqlCommand command2;
try
{
SqlCommand command1 = new SqlCommand();
this.OpenConnection();
command1.Connection = this.connection;
command1.CommandText = StrTSQL;
command2 = command1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return command2;
}
public void ExecuteQuery(String strSql)
{
this.OpenConnection();
SqlCommand tmpCommand = new SqlCommand(strSql, this.connection);
tmpCommand.ExecuteNonQuery();
this.CloseConnection();
}
public int ExecuteQuery(String strSql,string dummy)
{
this.OpenConnection();
SqlCommand tmpCommand = new SqlCommand(strSql, this.connection);
int NoofRowsAffected = tmpCommand.ExecuteNonQuery();
this.CloseConnection();
return NoofRowsAffected;
}
private void PrepareCommand(SqlCommand command, SqlTransaction transaction, string commandText, SqlParameter[] commandParameters)
{
//this.PrepareCommand(command1, null, spName, commandParameters);
command.Connection = this.connection;
command.CommandText = commandText;
if (transaction != null)
{
command.Transaction = transaction;
}
command.CommandType = CommandType.StoredProcedure;
if (commandParameters != null)
{
this.AttachParameters(command, commandParameters);
}
}
#endregion
#region "GetDataAdapter"
public SqlDataAdapter GetDataAdapter(string StrSQL)
{
SqlDataAdapter adapter2;
try
{
SqlDataAdapter adapter1 = new SqlDataAdapter(StrSQL, this.connectionString);
adapter2 = adapter1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return adapter2;
}
#endregion
#region "GetDataReader"
public SqlDataReader GetDataReader(string StrSQL)
{
SqlDataReader reader2;
try
{
SqlDataReader reader1 = null;
reader1 = this.GetCommand(StrSQL).ExecuteReader(CommandBehavior.Default);
reader2 = reader1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return reader2;
}
public SqlDataReader GetDataReaderSP(string spName, params SqlParameter[] commandParameters)
{
SqlCommand command1 = new SqlCommand();
this.PrepareCommand(command1, null, spName, commandParameters);
SqlDataAdapter adapter1 = new SqlDataAdapter(command1);
SqlDataReader reader1 = command1.ExecuteReader(CommandBehavior.Default);
command1.Parameters.Clear();
return reader1;
}
public SqlDataReader GetDataReaderSP(string spName, params object[] parameterValues)
{
if ((parameterValues != null) && (parameterValues.Length > 0))
{
this.errorCode = CDataAccess.DataAccessErrors.Successful;
SqlParameter[] parameterArray1 = CDataAccess.SqlParameterCache.GetSpParameterSet(this.connection, spName, false);
this.AssignParameterValues(parameterArray1, parameterValues);
return this.GetDataReaderSP(spName, parameterArray1);
}
return this.GetDataReaderSP(spName, null);
}
#endregion
#region "GetDataSet"
public DataSet GetDataSet(string StrSQL, string DateSetName)
{
DataSet set2;
try
{
DataSet set1 = new DataSet();
this.OpenConnection();
new SqlDataAdapter(StrSQL, this.connectionString).Fill(set1, DateSetName);
this.CloseConnection();
set2 = set1;
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return set2;
}
public DataSet GetDataSet(string strSQL, string strTable, ref SqlDataAdapter m_DataAdapter, ref DataTable m_DataTable, ref DataView m_DataView)
{
DataSet dsDataSet2 = null;
try
{
this.OpenConnection();
DataSet Set1 = new DataSet();
SqlCommand cmCommand;
cmCommand = new SqlCommand(strSQL, connection);
daDataAdapter = new SqlDataAdapter(cmCommand);
SqlCommandBuilder cbCommandBuilder = new SqlCommandBuilder(daDataAdapter);
//Build the Data Operation SQL if flag is True
cbCommandBuilder.GetUpdateCommand();
DataSet dsDataSet = new DataSet();
m_DataAdapter.Fill(dsDataSet, strTable);
dsDataSet2.Merge(dsDataSet);
dtDataTable = dsDataSet.Tables[0];
dvDataView = dtDataTable.DefaultView;
dvDataView.AllowNew = false;
this.CloseConnection();
}
catch (SqlException exception1)
{
throw new Exception(exception1.Message);
}
catch (Exception exception2)
{
throw new Exception(exception2.Message);
}
return dsDataSet2;
}
public DataSet GetDataSet(string strSQL, string strTable, ref SqlDataAdapter m_DataAdapter, ref DataSet m_DataSet)
{
this.OpenConnection();
DataSet tmpDataSet = new DataSet();
SqlCommand m_Command;
m_Command = new SqlCommand(strSQL, this.connection);
m_DataAdapter = new SqlDataAdapter(m_Command);
SqlCommandBuilder m_CommandBuilder = new SqlCommandBuilder(m_DataAdapter);
cbCommandBuilder.GetUpdateCommand();
m_DataAdapter.Fill(m_DataSet, strTable);
m_DataSet.Merge(tmpDataSet);
this.CloseConnection();
return m_DataSet;
}
public DataSet GetDataSet(string strSQL, string strTable, ref DataSet m_DataSet)
{
this.OpenConnection();
SqlDataAdapter m_SQL_DataAdapter;
SqlCommand m_SQL_Command;
DataSet tmpDataSet = new DataSet();
m_SQL_Command = new SqlCommand(strSQL, this.connection);
m_SQL_DataAdapter = new SqlDataAdapter(m_SQL_Command);
m_SQL_DataAdapter.Fill(tmpDataSet, strTable);
m_DataSet.Merge(tmpDataSet);
this.CloseConnection();
return m_DataSet;
}
public DataSet GetDataSet(string strSQL, string strTable, ref DataSet m_DataSet, int BuildCommand)
{
this.OpenConnection();
DataSet tmpDataSet = new DataSet();
SqlCommand cmCommand;
cmCommand = new SqlCommand(strSQL, this.connection);
daDataAdapter = new SqlDataAdapter(cmCommand);
cbCommandBuilder = new SqlCommandBuilder(daDataAdapter);
cbCommandBuilder.GetUpdateCommand();
daDataAdapter.Fill(m_DataSet, strTable);
m_DataSet.Merge(tmpDataSet);
this.CloseConnection();
return m_DataSet;
}
#endregion
#region "GetDataTable"
public DataTable GetDataTable(string strSQL)
{
this.OpenConnection();
SqlCommand m_Command;
m_Command = new SqlCommand(strSQL, this.connection);
SqlDataAdapter tmpDataAdapter;
tmpDataAdapter = new SqlDataAdapter(m_Command);
DataTable tmpDataTable = new DataTable();
tmpDataAdapter.Fill(tmpDataTable);
this.CloseConnection();
return tmpDataTable;
}
#endregion
#region "FillCombo"
public void FillCombo(ref DropDownList Combo, string strSQL, bool AddAllOption, bool None)
{
DataTable dtTable = GetDataTable(strSQL);
if ((None))
{
DataRow drDataRow;
drDataRow = dtTable.NewRow();
drDataRow[0] = -1;
drDataRow[1] = "";
dtTable.Rows.Add(drDataRow);
}
if ((AddAllOption))
{
DataRow drDataRow;
drDataRow = dtTable.NewRow();
drDataRow[0] = 0;
drDataRow[1] = "_ALL_";
dtTable.Rows.Add(drDataRow);
}
{
DataView DataView = dtTable.DefaultView;
DataView.Sort = dtTable.Columns[1].ColumnName;
Combo.DataSource = DataView;
Combo.DataTextField = dtTable.Columns[1].ColumnName;
Combo.DataValueField = dtTable.Columns[0].ColumnName;
Combo.DataBind();
}
}
#endregion
#region "SqlParameterCache Class"
public sealed class SqlParameterCache
{
// Methods
static SqlParameterCache()
{
CDataAccess.SqlParameterCache.paramCache = Hashtable.Synchronized(new Hashtable());
}
private SqlParameterCache()
{
}
private static void CacheParameterSet(string connectionString, string spName, params SqlParameter[] commandParameters)
{
string text1 = connectionString + ":" + spName;
CDataAccess.SqlParameterCache.paramCache[text1] = commandParameters;
}
private static SqlParameter[] CloneParameters(SqlParameter[] originalParameters)
{
SqlParameter[] parameterArray1 = new SqlParameter[originalParameters.Length];
int num1 = 0;
int num2 = originalParameters.Length;
while (num1 < num2)
{
parameterArray1[num1] = (SqlParameter)((ICloneable)originalParameters[num1]).Clone();
num1++;
}
return parameterArray1;
}
private static SqlParameter[] DiscoverSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter)
{
using (SqlCommand command1 = new SqlCommand(spName, connection))
{
command1.CommandType = CommandType.StoredProcedure;
SqlCommandBuilder.DeriveParameters(command1);
if (!includeReturnValueParameter)
{
command1.Parameters.RemoveAt(0);
}
SqlParameter[] parameterArray1 = new SqlParameter[command1.Parameters.Count];
command1.Parameters.CopyTo(parameterArray1, 0);
return parameterArray1;
}
}
private static SqlParameter[] GetCachedParameterSet(string connectionString, string spName)
{
string text1 = connectionString + ":" + spName;
SqlParameter[] parameterArray1 = (SqlParameter[])CDataAccess.SqlParameterCache.paramCache[text1];
if (parameterArray1 == null)
{
return null;
}
return CDataAccess.SqlParameterCache.CloneParameters(parameterArray1);
}
public static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName)
{
return CDataAccess.SqlParameterCache.GetSpParameterSet(connection, spName, false);
}
public static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter)
{
string text1 = connection.ConnectionString + ":" + spName + (includeReturnValueParameter ? ":include ReturnValue Parameter" : "");
SqlParameter[] parameterArray1 = (SqlParameter[])CDataAccess.SqlParameterCache.paramCache[text1];
if (parameterArray1 == null)
{
object obj1;
CDataAccess.SqlParameterCache.paramCache[text1] = obj1 = CDataAccess.SqlParameterCache.DiscoverSpParameterSet(connection, spName, includeReturnValueParameter);
parameterArray1 = (SqlParameter[])obj1;
}
return CDataAccess.SqlParameterCache.CloneParameters(parameterArray1);
}
// Fields
private static Hashtable paramCache;
}
#endregion
//Open file into a filestream and
//read data in a byte array.
public byte[] ReadFile(string sPath)
{
//Initialize byte array with a null value initially.
byte[] data = null;
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
//Open FileStream to read file
FileStream fStream = new FileStream(sPath, FileMode.Open,
FileAccess.Read);
//Use BinaryReader to read file stream into byte array.
BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to
//supply number of bytes to read from file.
//In this case we want to read entire file.
//So supplying total number of bytes.
data = br.ReadBytes((int)numBytes);
return data;
}
#region "InitializeGrid"
//public void InitializeGrid(ref UltraWebGrid Grid)
//{
// // Grid.JavaScriptFileName = "../../infragistics/scripts/ig_WebGrid.js";
// //Grid.JavaScriptFileNameCommon = "../../infragistics/scripts/ig_csom.js";
// Grid.DisplayLayout.AllowColSizingDefault = AllowSizing.Free;
// Grid.DisplayLayout.AllowColumnMovingDefault = Infragistics.WebUI.UltraWebGrid.AllowColumnMoving.OnServer;
// Grid.DisplayLayout.AllowSortingDefault = AllowSorting.OnClient;
// Grid.DisplayLayout.CellClickActionDefault = CellClickAction.RowSelect;
// Grid.DisplayLayout.CellPaddingDefault = 1;
// Grid.DisplayLayout.ColHeadersVisibleDefault = ShowMarginInfo.Yes;
// Grid.DisplayLayout.HeaderClickActionDefault = HeaderClickAction.SortSingle;
// //Header Style
// Grid.DisplayLayout.HeaderStyleDefault.CssClass = "GridHeader";
// Grid.DisplayLayout.HeaderStyleDefault.Font.Bold = true;
// //Sort
// Grid.DisplayLayout.AllowSortingDefault = Infragistics.WebUI.UltraWebGrid.AllowSorting.OnClient;
// Grid.DisplayLayout.HeaderClickActionDefault = Infragistics.WebUI.UltraWebGrid.HeaderClickAction.SortSingle;
// Grid.DisplayLayout.NoDataMessage = "No Records Found";
// Grid.DisplayLayout.NullTextDefault = "";
// Grid.DisplayLayout.RowStyleDefault.CssClass = "GridRowEven";
// Grid.DisplayLayout.RowAlternateStyleDefault.CssClass = "GridRowOdd";
// //Grid.DisplayLayout.RowAlternateStyleDefault.BackColor = Drawing.Color.FromArgb(255, 255, 215);
// //Grid.DisplayLayout.RowAlternateStyleDefault.BackColor = Gray;
// //Padding
// Grid.DisplayLayout.CellPaddingDefault = 3;
// Grid.DisplayLayout.RowAlternateStyleDefault.TextOverflow = TextOverflow.Ellipsis;
// Grid.DisplayLayout.RowHeightDefault = 25;
// Grid.DisplayLayout.RowSelectorsDefault = RowSelectors.No;
// Grid.DisplayLayout.RowSizingDefault = AllowSizing.Fixed;
// Grid.DisplayLayout.ScrollBar = ScrollBar.Auto;
// Grid.DisplayLayout.ScrollBarView = ScrollBarView.Both;
// Grid.DisplayLayout.SelectedRowStyleDefault.CssClass = "GridSelectedRow";
// Grid.DisplayLayout.SelectTypeCellDefault = SelectType.None;
// Grid.DisplayLayout.SelectTypeColDefault = SelectType.None;
// Grid.DisplayLayout.SelectTypeRowDefault = SelectType.Single;
// Grid.DisplayLayout.StationaryMargins = StationaryMargins.No;
// Grid.DisplayLayout.TabDirection = TabDirection.LeftToRight;
// Grid.DisplayLayout.ViewType = Infragistics.WebUI.UltraWebGrid.ViewType.Flat;
// Grid.CssClass = "Grid";
// Grid.BorderStyle = BorderStyle.Solid;
//}
#endregion
public string VoucherNumber(String strHead)
{
String strSql;
String strCode;
DataTable tmpDataTable;
strSql = "SELECT * FROM tblAutoNumber ";
strSql += "WHERE Head = '" + strHead + "'";
tmpDataTable = GetDataTable(strSql);
strCode = tmpDataTable.Rows[0]["Prefix"] + "/";
strCode += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "/";
strCode += Convert.ToString(Convert.ToInt32(tmpDataTable.Rows[0]["Number"]) + 1);
if (Convert.ToString(tmpDataTable.Rows[0]["SufixCheck"]) == "True")
{
strCode += "/" + tmpDataTable.Rows[0]["Sufix"];
}
return (strCode);
}
//public void AddValueListItemToGrid(ref Infragistics.WebUI.UltraWebGrid.UltraWebGrid Grid, String strSQL, int ColumnIndex) //int BandIndex = 0
//{
// Int32 iCount;
// Infragistics.WebUI.UltraWebGrid.ValueList vValue = new ValueList();
// DataTable tmpDataTable = GetDataTable(strSQL);
// //vValue = Grid.DisplayLayout.ValueLists.Add
// for (iCount = 0; iCount <= tmpDataTable.Rows.Count - 1; iCount++)
// {
// //vValue.ValueListItems.Add(tmpDataTable.Rows[iCount][0],(tmpDataTable.Rows[iCount][1])=null, "", tmpDataTable.Rows[iCount][1]);
// vValue.ValueListItems.Add(tmpDataTable.Rows[iCount][1]);
// }
// vValue.DisplayStyle = Infragistics.WebUI.UltraWebGrid.ValueListDisplayStyle.DisplayText;
// //vValue.SortStyle = Infragistics.Win.ValueListSortStyle.Ascending
// Grid.DisplayLayout.Bands[0].Columns[ColumnIndex].ValueList = vValue;
//}
}
#endregion
}
EXPORT TO EXCEL
Public Sub ExportToExcel(ByVal objDT As DataTable)
Dim Excel As Object = CreateObject("Excel.Application")
Dim strFilename As String
Dim intCol, intRow As Integer
Dim strPath As String = "c:\"
If Excel Is Nothing Then
MsgBox("It appears that Excel is not installed on this machine. This operation requires MS Excel to be installed on this machine.", MsgBoxStyle.Critical)
Return
End If
Try
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()
'.cells(1, 1).value = "Heading" 'Heading of the excel file
.cells(1, 1).EntireRow.Font.Bold = True
Dim intI As Integer = 1
For intCol = 1 To objDT.Columns.Count - 1
.cells(2, intI).value = objDT.Columns(intCol).ColumnName
.cells(2, intI).EntireRow.Font.Bold = True
intI += 1
Next
intI = 3
Dim intK As Integer = 1
For intCol = 1 To objDT.Columns.Count - 1
intI = 3
For intRow = 0 To objDT.Rows.Count - 1
.Cells(intI, intK).Value = objDT.Rows(intRow).ItemArray(intCol)
intI += 1
Next
intK += 1
Next
If Mid$(strPath, strPath.Length, 1) <> "\" Then
strPath = strPath & "\"
End If
Dim filename As String = System.DateTime.Now.ToString("MM/dd/yyyy")
filename = filename.Replace("/", "_") & System.DateTime.Now.Millisecond.ToString()
strFilename = strPath & filename
.ActiveCell.Worksheet.SaveAs(strFilename)
End With
System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
Excel = Nothing
MsgBox("Data's are exported to Excel Succesfully in '" & strFilename & "'", MsgBoxStyle.Information)
s = ""
s = strFilename + ".xls"
Catch ex As Exception
'MsgBox(ex.Message)
End Try
' The excel is created and opened for insert value. We most close this excel using this system
Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each i As Process In pro
i.Kill()
Next
End Sub
Dim Excel As Object = CreateObject("Excel.Application")
Dim strFilename As String
Dim intCol, intRow As Integer
Dim strPath As String = "c:\"
If Excel Is Nothing Then
MsgBox("It appears that Excel is not installed on this machine. This operation requires MS Excel to be installed on this machine.", MsgBoxStyle.Critical)
Return
End If
Try
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()
'.cells(1, 1).value = "Heading" 'Heading of the excel file
.cells(1, 1).EntireRow.Font.Bold = True
Dim intI As Integer = 1
For intCol = 1 To objDT.Columns.Count - 1
.cells(2, intI).value = objDT.Columns(intCol).ColumnName
.cells(2, intI).EntireRow.Font.Bold = True
intI += 1
Next
intI = 3
Dim intK As Integer = 1
For intCol = 1 To objDT.Columns.Count - 1
intI = 3
For intRow = 0 To objDT.Rows.Count - 1
.Cells(intI, intK).Value = objDT.Rows(intRow).ItemArray(intCol)
intI += 1
Next
intK += 1
Next
If Mid$(strPath, strPath.Length, 1) <> "\" Then
strPath = strPath & "\"
End If
Dim filename As String = System.DateTime.Now.ToString("MM/dd/yyyy")
filename = filename.Replace("/", "_") & System.DateTime.Now.Millisecond.ToString()
strFilename = strPath & filename
.ActiveCell.Worksheet.SaveAs(strFilename)
End With
System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
Excel = Nothing
MsgBox("Data's are exported to Excel Succesfully in '" & strFilename & "'", MsgBoxStyle.Information)
s = ""
s = strFilename + ".xls"
Catch ex As Exception
'MsgBox(ex.Message)
End Try
' The excel is created and opened for insert value. We most close this excel using this system
Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each i As Process In pro
i.Kill()
Next
End Sub
Thursday, July 7, 2011
EMAIL VALIDATION IN ASP.NET
<
asp:RegularExpressionValidator
ValidationExpression
=
"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
ID
=
"rxpEmail"
runat
=
"server"
ErrorMessage
=
"Email Address is not valid"
Text
=
"*"
Display
=
"Static"
ControlToValidate
=
"txtEmail"
>asp:RegularExpressionValidator
>
Tuesday, July 5, 2011
GET PROSSESOR ID,MOTHERBOARD ID IN VB.NET
Firts add system.management dll in project
then
Imports System
Imports System.Management
Friend Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId + Format(Int(Rnd() * 10000), "0000")
End Function
===========MOTHER BOARD ID=================
Friend Function GetMotherBoardID() As String
Dim strMotherBoardID As String = String.Empty
Dim query As New SelectQuery("Win32_BaseBoard")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strMotherBoardID = info("SerialNumber").ToString()
Next
Return strMotherBoardID
End Function
then
Imports System
Imports System.Management
Friend Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId + Format(Int(Rnd() * 10000), "0000")
End Function
===========MOTHER BOARD ID=================
Friend Function GetMotherBoardID() As String
Dim strMotherBoardID As String = String.Empty
Dim query As New SelectQuery("Win32_BaseBoard")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strMotherBoardID = info("SerialNumber").ToString()
Next
Return strMotherBoardID
End Function
CHART CONTROL IN VB.NET
Imports System.Windows.Forms.DataVisualization.Charting
Public Class frmChart
Dim dtTest As New DataTable
Dim iRowCount As Integer = 0
Dim iPageCounter As Integer = 0
Dim bIschart As Boolean = False
Private Sub frmChart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
dtTest.Columns.Clear()
dtTest.Rows.Clear()
dtTest.Columns.Add("Name")
dtTest.Columns.Add("Marks")
'dttest = modCons.dtChart.Copy()
iRowCount = modCons.dtChart.Rows.Count
If (iRowCount > 40) Then
For i As Integer = 0 To 39
dtTest.Rows.Add(modCons.dtChart.Rows(i)("Name").ToString(), modCons.dtChart.Rows(i)("Marks").ToString())
Next
If (bIschart = False) Then
Chart1.Series.Add("Name")
With Chart1.Series(0)
' .Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With
Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()
bIschart = True
End If
Else
For i As Integer = 0 To modCons.dtChart.Rows.Count - 1
dtTest.Rows.Add(modCons.dtChart.Rows(i)("Name").ToString(), modCons.dtChart.Rows(i)("Marks").ToString())
Next
If (bIschart = False) Then
Chart1.Series.Add("Name")
With Chart1.Series(0)
' .Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With
Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()
bIschart = True
btnFwd.Enabled = False
btnPrv.Enabled = False
End If
End If
End Sub
Private Sub btnPrv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrv.Click
' Chart1.Dispose()
iPageCounter -= 1
dtTest.Columns.Clear()
dtTest.Rows.Clear()
dtTest.Columns.Add("Name")
dtTest.Columns.Add("Marks")
Dim iEndCounter As Integer = (40 * iPageCounter) + 40
If (iEndCounter > modCons.dtChart.Rows.Count - 1) Then
iEndCounter = modCons.dtChart.Rows.Count - 1
btnFwd.Enabled = False
Else
btnFwd.Enabled = True
End If
Dim j As Integer = iRowCount - 40
For k As Integer = (40 * iPageCounter) + 1 To iEndCounter
dtTest.Rows.Add(modCons.dtChart.Rows(k)("Name").ToString(), modCons.dtChart.Rows(k)("Marks").ToString())
Next
If (bIschart = False) Then
Chart1.Series.Add("Name")
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With
Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()
Else
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With
Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
If (iPageCounter = 0) Then
btnPrv.Enabled = False
Else
btnPrv.Enabled = True
End If
End If
End Sub
Private Sub btnFwd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFwd.Click
' Chart1.Dispose()
iPageCounter += 1
dtTest.Columns.Clear()
dtTest.Rows.Clear()
dtTest.Columns.Add("Name")
dtTest.Columns.Add("Marks")
Dim iEndCounter As Integer = (40 * iPageCounter) + 40
If (iEndCounter > modCons.dtChart.Rows.Count - 1) Then
iEndCounter = modCons.dtChart.Rows.Count - 1
btnFwd.Enabled = False
Else
btnFwd.Enabled = True
End If
Dim j As Integer = iRowCount - 40
For k As Integer = (40 * iPageCounter) + 1 To iEndCounter
dtTest.Rows.Add(modCons.dtChart.Rows(k)("Name").ToString(), modCons.dtChart.Rows(k)("Marks").ToString())
Next
If (bIschart = False) Then
Chart1.Series.Add("Name")
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With
Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()
Else
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With
Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
If (iPageCounter = 0) Then
btnPrv.Enabled = False
Else
btnPrv.Enabled = True
End If
End If
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
PrintDocument1.Print()
End Sub
End Class
Subscribe to:
Posts (Atom)