using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FCOMMON { public static class DBM { private static System.Data.SqlClient.SqlConnection getCn() { string cs = FCOMMON.info.CS; System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(); cn.ConnectionString = cs; return cn; } public struct sItemInfo { public int idx; public string sid; public string model; public string supply; } public static sItemInfo getItemInfo(int idx) { var cn = getCn(); cn.Open(); var retval = new sItemInfo(); retval.idx = -1; string sql = "select * from Items where idx = " + idx.ToString(); var cmd = new System.Data.SqlClient.SqlCommand(sql, cn); var rdr = cmd.ExecuteReader(); while(rdr.Read()) { retval.idx = (int)rdr["idx"]; if(rdr["sid"] != DBNull.Value) retval.sid = rdr["sid"].ToString(); if (rdr["model"] != DBNull.Value) retval.model = rdr["model"].ToString(); if (rdr["supply"] != DBNull.Value) retval.supply = rdr["supply"].ToString(); } cn.Close(); cn.Dispose(); return retval; } public static List getGroupList(string GroupColumn, string table, string where = "",Boolean desc=false) { List retval = new List(); var cn = getCn(); cn.Open(); var sql = "select {0} " + " from {1} " + " where isnull({0},'') != '' "; if (where != "") sql += " and " + where; sql += " group by {0} " + " order by {0} "; if (desc) sql += " desc"; sql = string.Format(sql, "[" + GroupColumn + "]", table); var cmd = new System.Data.SqlClient.SqlCommand(sql, cn); var rdr = cmd.ExecuteReader(); while (rdr.Read()) { retval.Add(rdr[0].ToString()); } cmd.Dispose(); cn.Close(); cn.Dispose(); return retval; } public static List getDateList(string table, string where = "",Boolean desc =false) { return getGroupList("pdate", table, where,desc); } } }