/*判断数据库里面是否有重名的类型*/ public static int CategoryIsExist(string sCategoryName, ref int iRdID) { DataSet stDs; DataTable stDt; string sSql; Log.WriteLog(LogType.Trace, "come in CategoryIsExist"); try { sSql = "select * from Category where CategoryName = '" + sCategoryName + "';"; stDs = SqlAccess.GetDataSet(sSql); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not category[" + sCategoryName + "] in database."); iRdID = 0; return(0); //store不存在 } else { iRdID = Int32.Parse(stDt.Rows[0]["CategoryID"].ToString()); Log.WriteLog(LogType.Trace, "success to get the category[" + sCategoryName + "] and id[" + iRdID + "]"); return(1); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(-1); } }
//判断条形码是否又被product使用 public static int BarcodeHadBeenUse(string sBarcodeNum, ref int iID) { DataSet stDs; DataTable stDt; string sSql; Log.WriteLog(LogType.Trace, "come in BarcodeHadBeenUse"); try { sSql = "select ProductID from Product join Barcode on Product.BarcodeID = Barcode.BarcodeID" + " where BarcodeNumber = '" + sBarcodeNum + "';"; stDs = SqlAccess.GetDataSet(sSql); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not barcode[" + sBarcodeNum + "] in database."); iID = 0; return(0); //barcode 没有被使用过 } else { iID = Int32.Parse(stDt.Rows[0]["ProductID"].ToString()); Log.WriteLog(LogType.Trace, "success to get the product[" + iID + "] use barcode[" + sBarcodeNum + "]"); return(1); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(-1); } }
public static int BarcodeIsExist(string sBarcodeNum, ref int iID) { DataSet stDs; DataTable stDt; string sSql; Log.WriteLog(LogType.Trace, "come in BarcodeIsExist"); try { sSql = "select * from Barcode where BarcodeNumber = '" + sBarcodeNum + "';"; stDs = SqlAccess.GetDataSet(sSql); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not barcode[" + sBarcodeNum + "] in database."); iID = 0; return(0); //barcode不存在 } else { iID = Int32.Parse(stDt.Rows[0]["BarcodeID"].ToString()); Log.WriteLog(LogType.Trace, "success to get the barcode[" + sBarcodeNum + "] with id[" + iID + "]"); return(1); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(-1); } }
/*返回值:0标识不存在;1标识存在;-1表示处理出错*/ public static int StoreIsExist(string sStoreName, string sLocation, ref int iID) { DataSet stDs; DataTable stDt; string sSql; Log.WriteLog(LogType.Trace, "come in StoreIsExist"); try { sSql = "select * from Store where StoreName = '" + sStoreName + "' and StoreLocation = '" + sLocation + "';"; stDs = SqlAccess.GetDataSet(sSql); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not store[" + sStoreName + "," + sLocation + "] in database."); iID = 0; return(0); //store不存在 } else { iID = Int32.Parse(stDt.Rows[0]["StoreID"].ToString()); Log.WriteLog(LogType.Trace, "success to get the store[" + sStoreName + "," + sLocation + "] with id[" + iID + "]"); return(1); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(-1); } }
//保存antenna信息 private static bool SaveAntennaInfo(ref ReaderMain rm, int iReaderId) { DataSet stDs; DataTable stDt; Log.WriteLog(LogType.Trace, "come in SaveAntennaInfo"); string sSql = "select * from Antenna where ReaderID = " + iReaderId + " order by AntennaID;"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "success to get reader[" + iReaderId + "] antenna info from db"); stDt = stDs.Tables[0]; if (stDt.Rows.Count > 0) { for (int iIdx = 0; iIdx < stDt.Rows.Count; iIdx++) { DataRow stDr = stDt.Rows[iIdx]; LTS.Antenna stAnt = new LTS.Antenna(); stAnt.AntennaID = Int32.Parse(stDr["AntennaID"].ToString()); stAnt.ReaderID = Int32.Parse(stDr["ReaderID"].ToString()); stAnt.RxPower = decimal.Parse(stDr["RxPower"].ToString()); stAnt.TxPower = decimal.Parse(stDr["TxPower"].ToString()); stAnt.AntennaNumber = Int32.Parse(stDr["AntennaNumber"].ToString()); rm.antennas.Add(stAnt); Log.WriteLog(LogType.Trace, "success to save reader[" + iReaderId + "] antenna[" + stAnt.AntennaNumber + "] info:antennid[" + stAnt.AntennaID + "], " + "RxPower[" + stAnt.RxPower + "], TxPower[" + stAnt.TxPower + "]"); } } else { Log.WriteLog(LogType.Trace, "info:there is not antenna with reader[" + iReaderId + "]"); return(true); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(false); } return(true); }
/*获取store的信息*/ public static DataTable StoreGetInfo() { DataSet stDs; Log.WriteLog(LogType.Trace, "come in StoreGetInfo"); string sSql = "Select Store.StoreID, Store.StoreName, Store.StoreLocation " + "From Store order by StoreID"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "Success to store info from db"); return(stDs.Tables[0]); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(null); } }
public static int BarcodeDelRecode(int iID) { DataSet stDs; DataTable stDt; string sSql; Log.WriteLog(LogType.Trace, "come in BarcodeDelRecode"); try { sSql = "delete from Barcode where BarcodeID = '" + iID + "';"; SqlAccess.ExecuteSql(sSql); Log.WriteLog(LogType.Trace, "success to delete barcode with id[" + iID + "] from db"); return(1); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call ExecuteSql"); return(0); } }
/*获取Brands的信息*/ public static DataTable BrandsGetInfo() { DataSet stDs; Log.WriteLog(LogType.Trace, "come in BrandsGetInfo"); string sSql = "Select BrandID, BrandName, BrandDescription " + "From Brand"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "Success to brands info from db"); return(stDs.Tables[0]); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(null); } }
/*获取category的信息*/ public static DataTable CategoryGetInfo() { DataSet stDs; Log.WriteLog(LogType.Trace, "come in StoreGetInfo"); string sSql = "Select CategoryID, CategoryName, CategoryDescription " + "From Category"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "Success to category info from db"); return(stDs.Tables[0]); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(null); } }
/*获取produce的id*/ public static int ProductIsExist(string sProduceName, string sBrandName, string sCategoryName, ref int iRdID) { DataSet stDs; DataTable stDt; Log.WriteLog(LogType.Trace, "come in ProductIsExist"); string sSql = "Select Product.ProductID From Product " + " Join Brand on Product.BrandID = Brand.BrandID " + " Join Category on Category.CategoryID = Product.CategoryID " + " where Product.ProductName = '" + sProduceName + "' And Brand.BrandName = '" + sBrandName + "' And Category.CategoryName = '" + sCategoryName + "';"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "Success to product info from db"); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not product[" + sProduceName + "," + sBrandName + "," + sCategoryName + "] in database."); iRdID = 0; return(0); //barcode不存在 } else { iRdID = Int32.Parse(stDt.Rows[0]["ProductID"].ToString()); Log.WriteLog(LogType.Trace, "success to get the product[" + sProduceName + "," + sBrandName + "," + sCategoryName + "] and id[" + iRdID + "]"); return(1); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(-1); } }
/*获取products的信息*/ public static DataTable ProductGetInfo() { DataSet stDs; Log.WriteLog(LogType.Trace, "come in ProductGetInfo"); string sSql = "Select Product.ProductID, Product.ProductName, Product.ProductDescription, Barcode.BarcodeNumber, Brand.BrandName, Category.CategoryName From Product " + "Join Barcode on Product.BarcodeID = Barcode.BarcodeID " + "Join Brand on Product.BrandID = Brand.BrandID " + "Join Category on Product.CategoryID = Category.CategoryID;"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "Success to get product info from db"); return(stDs.Tables[0]); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call product"); return(null); } }
public static int BrandGetID(string sBrandName) { DataSet stDs; DataTable stDt; int iRdID; Log.WriteLog(LogType.Trace, "come in BrandGetID"); string sSql = "Select BrandID From Brand Where BrandName = '" + sBrandName + "'"; try { stDs = SqlAccess.GetDataSet(sSql); Log.WriteLog(LogType.Trace, "Success to brand info from db"); stDt = stDs.Tables[0]; if (stDt.Rows.Count > 0) { iRdID = Int32.Parse(stDt.Rows[0]["BrandID"].ToString()); Log.WriteLog(LogType.Trace, "success to get brand['" + sBrandName + "'] with id[" + iRdID + "]"); return(iRdID); } else { Log.WriteLog(LogType.Error, "there is not brand with name[" + sBrandName + "]"); return(0); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to call GetDataSet"); return(-1); } }
/*int iStoreId, int iSettingId, * List<ImpinjRevolution> impinjrev, 读写器列表; * delegate_read_handler dRHandler, 读操作函数; * delegate_write_handler dWHandler, 写操作函数; * delegate_check_handler dCHandler, 校验函数; * bool bTest, 标识是否是测试操作; *描述:供外部使用的连接读写器的接口API。应用setting的配置,连接到指定的读写器上。 */ public static bool reader_connectReader(int iStoreId, int iSettingId, List <ImpinjRevolution> impinjrev, BusinessQue stBQue, delegate_read_handler dRHandler, delegate_write_handler dWHandler, delegate_check_handler dCHandler, bool bTest) { DataSet stDs; DataTable stDt; SettingsMain smi = new SettingsMain(); Log.WriteLog(LogType.Trace, "come in reader_connectReader"); //获取指定setting下所有reader的信息 string sSql = "select s.StoreID, s.StoreName, s.StoreLocation, st.SettingsID, st.SettingsName, st.SettingsSelect, r.ReaderID, r.IPaddress, r.NumAntennas, r.ReaderType " + "from Store s " + "LEFT JOIN Settings st ON st.StoreID = s.StoreID " + "LEFT JOIN Reader r ON r.SettingsID = st.SettingsID " + "where s.StoreID = " + iStoreId + " AND st.SettingsID = " + iSettingId + "; "; try { stDs = SqlAccess.GetDataSet(sSql); stDt = stDs.Tables[0]; if (stDt.Rows.Count == 0) { Log.WriteLog(LogType.Trace, "there is not setting with storeid[" + iStoreId + "] and settingId[" + iSettingId + "]"); MessageBox.Show("there is not setting with storeid[" + iStoreId + "] and settingId[" + iSettingId + "]"); return(true); } Log.WriteLog(LogType.Trace, "success to get " + stDt.Rows.Count + " readers configs in store[" + iStoreId + "] settings[" + iSettingId + "]."); /*====================保存配置到内存====================*/ SaveStoreInfo(ref stDt, ref smi); SaveSettingInfo(ref stDt, ref smi); //遍历所有reader for (int iIdx = 0; iIdx < stDt.Rows.Count; iIdx++) { DataRow stDr = stDt.Rows[iIdx]; if (!SaveReaderInfo(ref stDr, ref smi, iIdx)) { MessageBox.Show("error to get reader config, so can not connect to reader."); return(false); } } /*================根据配置连接到指定的读写器上================*/ if (!reader_connect_handler(smi, impinjrev, stBQue, dRHandler, dWHandler, dCHandler, bTest)) { Log.WriteLog(LogType.Error, "error go call reader_connect"); return(false); } return(true); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to process connect reader, the exception msg is " + ex.Message.ToString() + "."); return(false); } }