📄 commondbo.cs
字号:
using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections;
namespace stock_Log
{
public class CommonDbo
{
private string CONN_STRING = "";
// private string SYNC_PATH = "";
public CommonDbo()
{
CONN_STRING = ConnectionInfo.GetConnString("config.xml","stock");
// SYNC_PATH = ConnectionInfo.GetSyncString("config.xml");
}
public string ConnectionString
{
get { return CONN_STRING; }
}
// public UserInfo LoginCheck(string username)
// {
// UserInfo info = new UserInfo();
// OleDbConnection connection = null;
// DataTableReader dr = null;
//
// try
// {
// connection = new OleDbConnection();
// connection.ConnectionString = CONN_STRING;
// connection.Open();
// OleDbCommand command = connection.CreateCommand();
// string sql = "select p.p_userid,p.name,p.logname,p.category,p.password,p.p_siteid,s.name from p_user p,p_site s where p.p_siteid=s.p_siteid and p.logname='" + username + "'";
// command.CommandText = sql;
//
// OleDbDataAdapter adapter = new OleDbDataAdapter(command);
// DataTable dt = new DataTable();
// adapter.Fill(dt);
//
// dr = dt.CreateDataReader();
// if (dr.HasRows)
// {
// dr.Read();
// info.Userid = (int)dr[0];
// info.UserName = (string)dr[1];
// info.LogName = (string)dr[2];
// info.Category = (string)dr[3];
// info.Password = (string)dr[4];
// info.Siteid = (int)dr[5];
// info.SiteName = (string)dr[6];
// }
// else
// {
// info = null;
// }
// }
// catch (Exception e)
// {
// throw e;
// }
// finally
// {
// if (dr != null && !dr.IsClosed)
// {
// dr.Close();
// }
// if (connection != null)
// connection.Close();
// }
//
// return info;
// }
public OleDbDataAdapter FindCustomerAdapter(String sql)
{
OleDbDataAdapter ad;
try
{
ad = new OleDbDataAdapter(sql, CONN_STRING);
}
catch (Exception e)
{
throw e;
}
return ad;
}
public bool FindByMemCode(string code)
{
bool re = false;
try
{
string sql = "select P_CUSTOMERID from p_customer where memcode='" + code.Trim() + "'";
using (OleDbConnection connection = new OleDbConnection(CONN_STRING))
{
connection.Open();
OleDbCommand command = connection.CreateCommand();
command.CommandText = sql.ToString();
using (OleDbDataReader dr = command.ExecuteReader())
{
if (dr.HasRows)
{
re = true;
}
}
}
}
catch (Exception e)
{
throw e;
}
return re;
}
public int GetBrandLevelByBrand(int brandid)
{
int re = 0;
try
{
string sql = "select p_brand_levelid from p_brand_level where p_brandid=" + brandid + " order by price";
using (OleDbConnection connection = new OleDbConnection(CONN_STRING))
{
connection.Open();
OleDbCommand command = connection.CreateCommand();
command.CommandText = sql.ToString();
using (OleDbDataReader dr = command.ExecuteReader())
{
if (dr.Read())
{
re = (int)dr[0];
}
}
}
}
catch (Exception e)
{
throw e;
}
return re;
}
public int InsertSql(string sql)
{
int i = 0;
try
{
using (OleDbConnection connection = new OleDbConnection(CONN_STRING))
{
connection.Open();
OleDbTransaction tran = connection.BeginTransaction();
OleDbCommand command = connection.CreateCommand();
command.CommandText = sql;
command.Transaction = tran;
i = command.ExecuteNonQuery();
tran.Commit();
command.Dispose();
}
}
catch (Exception e)
{
throw e;
}
return i;
}
public IDataReader GetReader(string sql)
{
IDataReader reader = null;
try
{
OleDbConnection connection = new OleDbConnection(CONN_STRING);
{
connection.Open();
OleDbCommand command = connection.CreateCommand();
command.CommandText = sql;
reader = command.ExecuteReader();
}
}
catch (Exception e)
{
throw e;
}
return reader;
}
private void FindAllCategory(int categoryid, ref StringBuilder sb)
{
try
{
using (OleDbConnection connection = new OleDbConnection(CONN_STRING))
{
connection.Open();
OleDbCommand command = connection.CreateCommand();
command.CommandText = "select p_categoryid from p_category where parentid=" + categoryid;
using (OleDbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
sb.Append(dr[0] + ",");
FindAllCategory((int)dr[0],ref sb);
}
}
}
}
catch (Exception e)
{
throw e;
}
}
public ArrayList FindAllSetProduct(int siteid)
{
ArrayList re = new ArrayList();
try
{
using (OleDbConnection connection = new OleDbConnection(CONN_STRING))
{
connection.Open();
OleDbCommand command = connection.CreateCommand();
command.CommandText = "select distinct p_productid from h_inventory where p_siteid=" + siteid;
using (OleDbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
re.Add((int)dr[0]);
}
}
}
}
catch (Exception e)
{
throw e;
}
return re;
}
public Hashtable FindAllSiteProduct(int siteid)
{
Hashtable re = new Hashtable();
// mySite = dbo.FindSiteInSameRegion(GlobalPar.siteid);
// InitializeComponent();
// foreach (DictionaryEntry de in mySite)
// {
// this.comboBoxItem.Items.Add(de.Value);
// }
try
{
using (OleDbConnection connection = new OleDbConnection(CONN_STRING))
{
connection.Open();
OleDbCommand command = connection.CreateCommand();
command.CommandText = "select distinct p_productid,notes from d_site_product where p_siteid=" + siteid;
using (OleDbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
re.Add((int)dr[0],(string)dr[1]);
}
}
}
}
catch (Exception e)
{
throw e;
}
return re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -