Beispiel #1
0
        /// <summary>
        /// 根据sql语句执行增删改操作,返回受影响的行数
        /// </summary>
        /// <param name="strSql">sql语句</param>
        /// <returns></returns>
        public static int ExcuteBySql(string strSql)
        {
            int    i       = 0;
            string strConn = SqlDataHelper.GetConnectionString();

            using (SqlConnection connection = new SqlConnection(strConn))
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                SqlTransaction transaction = connection.BeginTransaction();//开启事务
                SqlCommand     command     = connection.CreateCommand();
                command.Connection     = connection;
                command.CommandTimeout = iTimeOut;
                command.Transaction    = transaction;
                try
                {
                    command.CommandText = strSql;
                    i = command.ExecuteNonQuery();
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    InsertLog.Insert(ex.Message, ex);
                }
                finally
                {
                    connection.Close();
                }
            }

            return(i);
        }
Beispiel #2
0
        public HttpResponseMessage ImportOrder([FromBody] OrderInfoListClient orderInfoListClient)
        {
            InsertLog.Insert("订单导入数据获得的订单数据", orderInfoListClient.xmOrderInfoClientList.Count.ToString());
            _utilManager.Write(JsonConvert.SerializeObject(orderInfoListClient));
            var apiMessage = new ApiMassage();

            apiMessage.Header = new Header();
            var str = string.Empty;

            if (orderInfoListClient.xmOrderInfoClientList.Count == 0)
            {
                apiMessage.Header.IsSuccess = false;
                apiMessage.Header.Message   = "请求的参数为空";
                str = JsonConvert.SerializeObject(apiMessage);
                return(_utilManager.HttpMessage(str));
            }
            var nostatus = new List <string>()
            {
                "待付款", "待使用", "已完成", "已发货"
            };
            var clientOrderList = orderInfoListClient.xmOrderInfoClientList.Where(m => !nostatus.Contains(m.OrderStatus)).ToList();

            if (clientOrderList.Count > 500 || clientOrderList.Count == 0)
            {
                apiMessage.Header.IsSuccess = false;
                apiMessage.Header.Message   = "传入的订单条数不能超过500!或者少于0";
                str = JsonConvert.SerializeObject(apiMessage);
                return(_utilManager.HttpMessage(str));
            }
            _orderInsertManager.InsertXMOrderInfo(clientOrderList, apiMessage.Header);
            if (string.IsNullOrWhiteSpace(apiMessage.Header.Message))
            {
                apiMessage.Header.IsSuccess = true;
                apiMessage.Header.Message   = "接口接收订单数量:" + clientOrderList.Count.ToString() + "处理成功!";
            }
            else
            {
                apiMessage.Header.IsSuccess = false;
            }
            //apiMessage.Header.Message += errorStr;
            str = JsonConvert.SerializeObject(apiMessage);
            InsertLog.Insert("订单导入数据返回值", str);
            return(_utilManager.HttpMessage(str));
            //return JsonConvert.SerializeObject(apiMessage);
        }