示例#1
0
        public void handler(IResponder responder)
        {
            Trade trade = new Trade();

            trade.Shopid     = SJSRequest.GetInt("Shopid", 0);
            trade.Tradename  = SJSRequest.GetString("Tradename");
            trade.Tradevalue = SJSRequest.GetFloat("Tradevalue", 0);

            if (trade.Shopid <= 0)
            {
                responder.WriteErroredMsg("请求参数错误!");
                return;
            }

            if (string.IsNullOrEmpty(trade.Tradename))
            {
                responder.WriteErroredMsg("菜单名称不能为空!");
                return;
            }

            int rlt = TradeManager.AddTrade(trade);

            if (rlt <= 0)
            {
                responder.WriteErroredMsg("新增菜单失败,数据库写入不成功!");
                return;
            }

            responder.WriteSuccessedMsg("新增菜单成功!");
        }
示例#2
0
        private void importShopAndTrade()
        {
            XMLHelper xh = new XMLHelper(Server.MapPath("/ShopAndTrade.xml"));

            XmlNodeList xnl = xh.GetXmlNode("shops").ChildNodes;

            using (DbTransaction trans = DbHelper.BeginTransaction())
            {
                try
                {
                    foreach (XmlNode xn in xnl)
                    {
                        Shop shop = new Shop();

                        shop.Shopname = xn.Attributes["Shopname"].InnerText;
                        shop.Phone    = xn.Attributes["Phone"].InnerText;

                        shop.Id = ShopManager.AddShop(shop, trans);

                        if (shop.Id <= 0)
                        {
                            trans.Rollback();
                            Response.Write("<br />事务出错执行回滚.<br />");
                            return;
                        }

                        foreach (XmlNode tradeXN in xn.ChildNodes)
                        {
                            Trade trade = new Trade();

                            trade.Shopid = shop.Id;

                            trade.Tradename  = tradeXN.Attributes["Tradename"].InnerText;
                            trade.Tradevalue = Convert.ToDouble(tradeXN.Attributes["Tradevalue"].InnerText);

                            trade.Id = TradeManager.AddTrade(trade, trans);

                            if (trade.Id <= 0)
                            {
                                trans.Rollback();
                                Response.Write("<br />事务出错执行回滚.<br />");
                                return;
                            }
                        }

                        //Response.Write(xn.Attributes["Shopname"].InnerText + "<br />");
                    }



                    trans.Commit();
                    Response.Write("<br />店铺和菜单导入.<br />");
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    Response.Write("<br />事务出错执行回滚.<br />");
                }
            }
        }