行 1: using System;
行 2: using System.Data;
行 3: using System.Data.SqlClient;
行 4: using System.Collections;
行 5:
行 6: namespace DBProjectGuide.Shop
行 7: {
行 8: /// <summary>
行 9: /// Order description。
行 10: /// </summary>
行 11: public class Order:DbBase.Base,IEnumerator
行 12: {
行 13: private ArrayList allProducts = new ArrayList();
行 14: private int userId;
行 15: //private byte status;
行 16: private DateTime date = System.DateTime.Now.Date;
行 17: private int position=-1;
行 18:
行 19: public Order()
行 20: {
行 21:
行 22: }
行 23:
行 24:
行 25: #region Properties of order class
行 26:
行 27: object IEnumerator.Current
行 28: {
行 29: get
行 30: {
行 31: return allProducts[position];
行 32: }
行 33: }
行 34:
行 35:
行 36: /// <summary>
行 37: /// set detail of order form
行 38: /// </summary>
行 39: public int Count
行 40: {
行 41: get
行 42: {
行 43: strSQL = "Select Count(*) From OrderDetails Where OrderId=" + this.ID;
行 44: try
行 45: {
行 46: return ExecuteSql4Value(strSQL);
行 47: }
行 48: catch
行 49: {
行 50: return -1;
行 51: }
行 52: }
行 53: }
行 54:
行 55: /// <summary>
行 56: /// sum
行 57: /// </summary>
行 58: public double Total
行 59: {
行 60: get
行 61: {
行 62: strSQL = "Select Sum(A.Price * C.Quantity) as Total From Products A,Orders B ,OrderDetails C Where A.id = C.ProductsId and B.id = C.OrderId And C.OrderId=" + this.ID;
行 63: try
行 64: {
行 65: return (double)ExecuteSql4ValueEx(strSQL);
行 66: }
行 67: catch
行 68: {
行 69: return 0.0;
行 70: }
行 71: }
行 72: }
行 73:
行 74:
行 75: /// <summary>
行 76: /// User ID
行 77: /// </summary>
行 78: public int UserId
行 79: {
行 80: get
行 81: {
行 82: return userId;
行 83: }
行 84: set
行 85: {
行 86: userId = value;
行 87: }
行 88: }
行 89: #endregion
行 90:
行 91:
行 92: #region Functions of order class
行 93:
行 94: /// <summary>
行 95: /// return details of this order
行 96: /// </summary>
行 97: /// <returns></returns>
行 98: public ICollection GetItems()
行 99: {
行 100: return allProducts;
行 101: }
行 102:
行 103:
行 104:
行 105: public OrderDetails this[int index]
行 106: {
行 107: get
行 108: {
行 109: return (OrderDetails)allProducts[index];
行 110: }
行 111: }
行 112:
行 113:
行 114: public void Clear()
行 115: {
行 116: allProducts.Clear();
行 117: }
行 118:
行 119:
行 120: public void Add(OrderDetails value)
行 121: {
行 122: allProducts.Add(value);
行 123: }
行 124:
行 125:
行 126: bool IEnumerator.MoveNext()
行 127: {
行 128: position++;
行 129: if(position>=allProducts.Count)
行 130: {
行 131: return false;
行 132: }
行 133: else
行 134: {
行 135: return true;
行 136: }
行 137: }
行 138:
行 139:
行 140: void IEnumerator.Reset()
行 141: {
行 142: position = -1;
行 143: }
行 144:
行 145:
行 146: public void RemoveAt(int index)
行 147: {
行 148: allProducts.RemoveAt(index);
行 149: }
行 150:
行 151:
行 152: public void Remove(int itemId)
行 153: {
行 154: foreach(OrderDetails item in allProducts)
行 155: {
行 156: if(itemId == item.ProductsId)
行 157: {
行 158: allProducts.Remove(item);
行 159: return;
行 160: }
行 161: }
行 162: }
行 163:
行 164:
行 165: public int Have(int userId)
行 166: {
行 167: try
行 168: {
行 169: string [] arrSQL = new String[allProducts.Count];
行 170: strSQL = "Insert into Orders(UserId) values(" + userId.ToString() + ")";
行 171: ExecuteSql(strSQL);
行 172: strSQL = "Select Max(Id) From Orders";
行 173: int orderId = ExecuteSql4Value(strSQL);
行 174:
行 175: System.Text.StringBuilder sb = new System.Text.StringBuilder();
行 176: DBProjectGuide.Shop.OrderDetails item = new DBProjectGuide.Shop.OrderDetails();
行 177: for(int i=0;i<allProducts.Count;i++)
行 178: {
行 179: item = (DBProjectGuide.Shop.OrderDetails)allProducts[i];
行 180: sb.Append("Insert into OrderDetails(OrderId,ProductsId,Quantity) values(");
行 181: sb.Append(orderId.ToString());
行 182: sb.Append(",");
行 183: sb.Append(item.ProductsId.ToString());
行 184: sb.Append(",");
行 185: sb.Append(item.Quantity.ToString());
行 186: sb.Append(")");
行 187: arrSQL[i] = sb.ToString();
行 188: sb.Remove(0,sb.Length);
行 189: }
行 190:
行 191: ExecuteSqls(arrSQL);
行 192: return orderId;
行 193: }
行 194: catch
行 195: {
行 196: throw new Exception("Order Products FAILED!");
行 197: }
行 198: }
行 199:
行 200:
行 201: public static bool Deal(int orderId)
行 202: {
行 203: strSQL = "Update OrdersV Set Status =1 Where Id=" + orderId.ToString();
行 204: try
行 205: {
行 206: ExecuteSql4Ds(strSQL);
行 207: strSQL = "Update Products set Sales=Sales+1 Where id in(SELECT b.ProductsId FROM Orders a INNER JOIN OrderDetails b ON a.Id = b.OrderId AND a.Id = " + orderId.ToString() + ")";
行 208: ExecuteSql4Ds(strSQL);
行 209: return true;
行 210: }
行 211: catch
行 212: {
行 213: throw new Exception("Deal with the order failed!");
行 214: }
行 215: }
行 216:
行 217:
行 218: public static DataSet GetOrder(int orderId)
行 219: {
行 220: strSQL = "SELECT UserId, OrderDate,CASE WHEN Status = '1' THEN 'dealt' ELSE 'on progress' END AS Status FROM Orders Where Id=" + orderId.ToString();
行 221: try
行 222: {
行 223: return ExecuteSql4Ds(strSQL);
行 224: }
行 225: catch
行 226: {
行 227: throw new Exception("Get order failed!");
行 228: }
行 229: }
行 230:
行 231:
行 232: public static DataSet GetOrders()
行 233: {
行 234: strSQL = "SELECT * FROM OrdersV Where Status=0 or Status IS NULL";
行 235: try
行 236: {
行 237: return ExecuteSql4Ds(strSQL);
行 238: }
行 239: catch
行 240: {
行 241: throw new Exception("Get orders failed!");
行 242: }
行 243: }
行 244:
行 245:
行 246: public static DataSet GetOrders(int userId)
行 247: {
行 248: strSQL = "SELECT Id,UserId, OrderDate,CASE WHEN Status = '1' THEN 'dealt' ELSE 'on progress' END AS Status FROM Orders Where UserId=" + userId.ToString();
行 249: try
行 250: {
行 251: return ExecuteSql4Ds(strSQL);
行 252: }
行 253: catch
行 254: {
行 255: throw new Exception("Get order failed!");
行 256: }
行 257: }
行 258:
行 259:
行 260: public static DataSet GetDetails(int orderId)
行 261: {
行 262: strSQL = "Select * from DetailsV Where orderId=" + orderId.ToString();
行 263: try
行 264: {
行 265: return ExecuteSql4Ds(strSQL);
行 266: }
行 267: catch
行 268: {
行 269: throw new Exception("Get order details failed!");
行 270: }
行 271: }
行 272:
行 273: #endregion
行 274: }
行 275: }
行 276: 提示编译错误,内容为:编译错误:c:\Users\Administrator\Desktop\shop\App_Code\Classes\Order.cs(156,23): error CS0122: “DBProjectGuide.Shop.OrderDetails.ProductsId”不可访问,因为它受保护级别限制。
请高手帮帮!!急用啊
行 2: using System.Data;
行 3: using System.Data.SqlClient;
行 4: using System.Collections;
行 5:
行 6: namespace DBProjectGuide.Shop
行 7: {
行 8: /// <summary>
行 9: /// Order description。
行 10: /// </summary>
行 11: public class Order:DbBase.Base,IEnumerator
行 12: {
行 13: private ArrayList allProducts = new ArrayList();
行 14: private int userId;
行 15: //private byte status;
行 16: private DateTime date = System.DateTime.Now.Date;
行 17: private int position=-1;
行 18:
行 19: public Order()
行 20: {
行 21:
行 22: }
行 23:
行 24:
行 25: #region Properties of order class
行 26:
行 27: object IEnumerator.Current
行 28: {
行 29: get
行 30: {
行 31: return allProducts[position];
行 32: }
行 33: }
行 34:
行 35:
行 36: /// <summary>
行 37: /// set detail of order form
行 38: /// </summary>
行 39: public int Count
行 40: {
行 41: get
行 42: {
行 43: strSQL = "Select Count(*) From OrderDetails Where OrderId=" + this.ID;
行 44: try
行 45: {
行 46: return ExecuteSql4Value(strSQL);
行 47: }
行 48: catch
行 49: {
行 50: return -1;
行 51: }
行 52: }
行 53: }
行 54:
行 55: /// <summary>
行 56: /// sum
行 57: /// </summary>
行 58: public double Total
行 59: {
行 60: get
行 61: {
行 62: strSQL = "Select Sum(A.Price * C.Quantity) as Total From Products A,Orders B ,OrderDetails C Where A.id = C.ProductsId and B.id = C.OrderId And C.OrderId=" + this.ID;
行 63: try
行 64: {
行 65: return (double)ExecuteSql4ValueEx(strSQL);
行 66: }
行 67: catch
行 68: {
行 69: return 0.0;
行 70: }
行 71: }
行 72: }
行 73:
行 74:
行 75: /// <summary>
行 76: /// User ID
行 77: /// </summary>
行 78: public int UserId
行 79: {
行 80: get
行 81: {
行 82: return userId;
行 83: }
行 84: set
行 85: {
行 86: userId = value;
行 87: }
行 88: }
行 89: #endregion
行 90:
行 91:
行 92: #region Functions of order class
行 93:
行 94: /// <summary>
行 95: /// return details of this order
行 96: /// </summary>
行 97: /// <returns></returns>
行 98: public ICollection GetItems()
行 99: {
行 100: return allProducts;
行 101: }
行 102:
行 103:
行 104:
行 105: public OrderDetails this[int index]
行 106: {
行 107: get
行 108: {
行 109: return (OrderDetails)allProducts[index];
行 110: }
行 111: }
行 112:
行 113:
行 114: public void Clear()
行 115: {
行 116: allProducts.Clear();
行 117: }
行 118:
行 119:
行 120: public void Add(OrderDetails value)
行 121: {
行 122: allProducts.Add(value);
行 123: }
行 124:
行 125:
行 126: bool IEnumerator.MoveNext()
行 127: {
行 128: position++;
行 129: if(position>=allProducts.Count)
行 130: {
行 131: return false;
行 132: }
行 133: else
行 134: {
行 135: return true;
行 136: }
行 137: }
行 138:
行 139:
行 140: void IEnumerator.Reset()
行 141: {
行 142: position = -1;
行 143: }
行 144:
行 145:
行 146: public void RemoveAt(int index)
行 147: {
行 148: allProducts.RemoveAt(index);
行 149: }
行 150:
行 151:
行 152: public void Remove(int itemId)
行 153: {
行 154: foreach(OrderDetails item in allProducts)
行 155: {
行 156: if(itemId == item.ProductsId)
行 157: {
行 158: allProducts.Remove(item);
行 159: return;
行 160: }
行 161: }
行 162: }
行 163:
行 164:
行 165: public int Have(int userId)
行 166: {
行 167: try
行 168: {
行 169: string [] arrSQL = new String[allProducts.Count];
行 170: strSQL = "Insert into Orders(UserId) values(" + userId.ToString() + ")";
行 171: ExecuteSql(strSQL);
行 172: strSQL = "Select Max(Id) From Orders";
行 173: int orderId = ExecuteSql4Value(strSQL);
行 174:
行 175: System.Text.StringBuilder sb = new System.Text.StringBuilder();
行 176: DBProjectGuide.Shop.OrderDetails item = new DBProjectGuide.Shop.OrderDetails();
行 177: for(int i=0;i<allProducts.Count;i++)
行 178: {
行 179: item = (DBProjectGuide.Shop.OrderDetails)allProducts[i];
行 180: sb.Append("Insert into OrderDetails(OrderId,ProductsId,Quantity) values(");
行 181: sb.Append(orderId.ToString());
行 182: sb.Append(",");
行 183: sb.Append(item.ProductsId.ToString());
行 184: sb.Append(",");
行 185: sb.Append(item.Quantity.ToString());
行 186: sb.Append(")");
行 187: arrSQL[i] = sb.ToString();
行 188: sb.Remove(0,sb.Length);
行 189: }
行 190:
行 191: ExecuteSqls(arrSQL);
行 192: return orderId;
行 193: }
行 194: catch
行 195: {
行 196: throw new Exception("Order Products FAILED!");
行 197: }
行 198: }
行 199:
行 200:
行 201: public static bool Deal(int orderId)
行 202: {
行 203: strSQL = "Update OrdersV Set Status =1 Where Id=" + orderId.ToString();
行 204: try
行 205: {
行 206: ExecuteSql4Ds(strSQL);
行 207: strSQL = "Update Products set Sales=Sales+1 Where id in(SELECT b.ProductsId FROM Orders a INNER JOIN OrderDetails b ON a.Id = b.OrderId AND a.Id = " + orderId.ToString() + ")";
行 208: ExecuteSql4Ds(strSQL);
行 209: return true;
行 210: }
行 211: catch
行 212: {
行 213: throw new Exception("Deal with the order failed!");
行 214: }
行 215: }
行 216:
行 217:
行 218: public static DataSet GetOrder(int orderId)
行 219: {
行 220: strSQL = "SELECT UserId, OrderDate,CASE WHEN Status = '1' THEN 'dealt' ELSE 'on progress' END AS Status FROM Orders Where Id=" + orderId.ToString();
行 221: try
行 222: {
行 223: return ExecuteSql4Ds(strSQL);
行 224: }
行 225: catch
行 226: {
行 227: throw new Exception("Get order failed!");
行 228: }
行 229: }
行 230:
行 231:
行 232: public static DataSet GetOrders()
行 233: {
行 234: strSQL = "SELECT * FROM OrdersV Where Status=0 or Status IS NULL";
行 235: try
行 236: {
行 237: return ExecuteSql4Ds(strSQL);
行 238: }
行 239: catch
行 240: {
行 241: throw new Exception("Get orders failed!");
行 242: }
行 243: }
行 244:
行 245:
行 246: public static DataSet GetOrders(int userId)
行 247: {
行 248: strSQL = "SELECT Id,UserId, OrderDate,CASE WHEN Status = '1' THEN 'dealt' ELSE 'on progress' END AS Status FROM Orders Where UserId=" + userId.ToString();
行 249: try
行 250: {
行 251: return ExecuteSql4Ds(strSQL);
行 252: }
行 253: catch
行 254: {
行 255: throw new Exception("Get order failed!");
行 256: }
行 257: }
行 258:
行 259:
行 260: public static DataSet GetDetails(int orderId)
行 261: {
行 262: strSQL = "Select * from DetailsV Where orderId=" + orderId.ToString();
行 263: try
行 264: {
行 265: return ExecuteSql4Ds(strSQL);
行 266: }
行 267: catch
行 268: {
行 269: throw new Exception("Get order details failed!");
行 270: }
行 271: }
行 272:
行 273: #endregion
行 274: }
行 275: }
行 276: 提示编译错误,内容为:编译错误:c:\Users\Administrator\Desktop\shop\App_Code\Classes\Order.cs(156,23): error CS0122: “DBProjectGuide.Shop.OrderDetails.ProductsId”不可访问,因为它受保护级别限制。
请高手帮帮!!急用啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货