using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace cadre_mgmt_system.DataRepository
{
public class OracleDAL
{
//public static readonly string connectionString = ConfigurationManager.ConnectionStrings["OracleConn"].ConnectionString;
OracleConnection conn;
public OracleDAL()
{
conn = new OracleConnection("user id=readonly;password=readonly;data source=192.168.101.29:1522/PROD");
}
//public DataSet Read(string StoredProcedure, SqlParameter[] param)
//{
// OracleCommand cmd = new OracleCommand(StoredProcedure, conn);
// cmd.CommandType = CommandType.StoredProcedure;
// if (param != null)
// cmd.Parameters.AddRange(param.ToArray());
// OracleDataAdapter da = new OracleDataAdapter(cmd);
// DataSet ds = new DataSet();
// conn.Open();
// da.Fill(ds);
// conn.Close();
// return ds;
//}
public DataSet Read(string Query)
{
//Query = "select * from XXICAR_EMPLOYEE_BANK_DETAILS";
OracleCommand cmd = new OracleCommand(Query, conn);
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
return ds;
}
public bool Write(string Query)
{
OracleCommand cmd = new OracleCommand(Query, conn);
cmd.CommandType = CommandType.Text;
conn.Open();
int rows = cmd.ExecuteNonQuery();
conn.Close();
if (rows == 1)
return true;
else
return false;
}
public bool Write(string StoredProcedure, SqlParameter[] param = null)
{
OracleCommand cmd = new OracleCommand(StoredProcedure, conn);
cmd.CommandType = CommandType.StoredProcedure;
if (param != null)
cmd.Parameters.AddRange(param.ToArray());
conn.Open();
int rows = cmd.ExecuteNonQuery();
conn.Close();
if (rows == 1)
return true;
else
return false;
}
}
}
--------------------------------------------------------
or from bokaro
public List<PlatformData> GetStationPlatformReport(string userid, out string errmsg)
{
OracleConnection connection = null;
List<PlatformData> PlatformDataReport = null;
try
{
connection = RepositoryConnectionManager.Instance.CreateConnection();
OracleCommand OraCmd = new OracleCommand("REPORTS.GetStationPlatform", connection);
OraCmd.CommandType = System.Data.CommandType.StoredProcedure;
OraCmd.Parameters.Add(new OracleParameter("OUT_CURSOR", OracleDbType.RefCursor, ParameterDirection.Output));
PlatformDataReport = new List<PlatformData>();
Logfile.LogMain("REPORTS.GetStationPlatform", userid);
connection.Open();
using (IDataReader reader = OraCmd.ExecuteReader())
{
while (reader.Read())
{
PlatformData Platform = new PlatformData();
if (reader["DVSNCODE"] != null)
{
Platform.ZoneCode = reader["ZONECODE"].ToString();
Platform.DvsnCode = reader["DVSNCODE"].ToString();
Platform.StationCode = reader["STTNCODE"].ToString();
Platform.PlatformNumber = reader["PLATFORMNUMB"].ToString();
Platform.PlatformType = reader["PFTYPE"].ToString();
//Platform.SuburbanFlag = reader["SUBURBANFLAG"].ToString();
Platform.IsSuburbanTraffic = reader["SUBURBANFLAG"].ToString().ToUpper() == "Y" ? true : false;
Platform.IsAllTraffic = reader["SUBURBANFLAG"].ToString().ToUpper() == "N" ? true : false;
Platform.Length = reader["LENGTH"].ToString();
Platform.Capacity = reader["CAPACITY"].ToString();
//Platform.Facility = reader["FACILITY"].ToString();
Platform.IsFacilityFL = reader["FACILITY"].ToString().Contains("FL") ? true : false;
Platform.IsFacilityWT = reader["FACILITY"].ToString().Contains("WT") ? true : false;
Platform.IsFacilityCH = reader["FACILITY"].ToString().Contains("CH") ? true : false;
Platform.IsFacilityFB = reader["FACILITY"].ToString().Contains("FB") ? true : false;
Platform.IsFacilityWC = reader["FACILITY"].ToString().Contains("WC") ? true : false;
}
PlatformDataReport.Add(Platform);
}
}
errmsg = "";
return PlatformDataReport;
}
catch (OracleException e)
{
Logfile.LogMain(e.Procedure + " :- Message: " + e.Message, userid);
Console.WriteLine(e.Procedure + " :- Message: " + e.Message);
errmsg = e.Message;
return PlatformDataReport;
}
catch (Exception e)
{
Logfile.LogMain("REPORTS.GetStationPlatform :- " + e.Message, userid);
Console.WriteLine("REPORTS.GetStationPlatform :- " + e.Message);
errmsg = e.Message;
return PlatformDataReport;
}
finally
{
if (connection != null && connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
No comments:
Post a Comment