/// <summary>
        /// Get all
        /// </summary>
        /// <returns>Return a object list like: List<User></returns>
        internal List <T> GetAll()
        {
            string data = GetResponse("User", "All", HttpMethod.GET);

            if (string.IsNullOrEmpty(data))
            {
                return(null);
            }

            return(JsonHelp.JsonDeserialize <List <T> >(data));
        }
Beispiel #2
0
        /// <summary>
        /// 新增临时停车信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private string TempPayFees(string requestParam)
        {
            try
            {
                if (string.IsNullOrEmpty(requestParam))
                {
                    new Logger().WriteLog("鸿坤道闸临停信息请求参数", DateTime.Now.ToString() + "--" + requestParam);
                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, "请求参数不能为空");
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }

                string        ContionString = PubConstant.GetConnectionString("HKSQLConnection").ToString();
                IDbConnection con           = new SqlConnection(ContionString);

                Tb_HSPR_HKCostInfo costInfo = JsonHelp.JsonDeserialize <Tb_HSPR_HKCostInfo>(requestParam);
                string             CommID   = null;//项目ID
                string             sKey     = "A2YGWFV7QP5KFOMLXIYRW";

                int    parkId       = costInfo.parkId;
                int    duration     = costInfo.duration;
                string dutyId       = costInfo.dutyId;
                string endTime      = costInfo.endTime;
                string feeAli       = costInfo.feeAli;
                string feeCash      = costInfo.feeCash;
                string feeCoupon    = costInfo.feeCoupon;
                string feeException = costInfo.feeException;
                string feeExpected  = costInfo.feeExpected;
                string feeFree      = costInfo.feeFree;
                string feeWechat    = costInfo.feeWechat;
                string roomNum      = costInfo.roomNum;
                string startTime    = costInfo.startTime;
                string tollManName  = costInfo.tollManName;
                string HtcSign      = costInfo.sign;

                //查询当前数据是否已经存在天问系统
                string    tmpStr         = "SELECT * FROM Tb_HSPR_TemporaryCarPrecostsDetail WHERE dutyId='" + dutyId + "'";
                DataTable dtTemporaryCar = new DbHelperSQLP(ContionString).Query(tmpStr).Tables[0];
                if (dtTemporaryCar.Rows.Count > 0)
                {
                    new Logger().WriteLog("鸿坤道闸临停信息同步异常", DateTime.Now.ToString() + "--" + "该条临停数据已经存在天问系统:" + tmpStr);

                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, "该条临停数据已经存在天问系统");
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }


                if (parkId <= 0)
                {
                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, "车场ID不能为空");
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }
                string signParm = "{\"duration\":" + duration + ",\"dutyId\":\"" + dutyId + "\",\"endTime\":\"" + endTime
                                  + "\",\"feeAli\":" + feeAli + ",\"feeCash\":" + feeCash + ",\"feeCoupon\":" + feeCoupon + ",\"feeException\":"
                                  + feeException + ",feeExpected:" + feeExpected + ",feeFree:" + feeFree + ",feeWechat:" + feeWechat
                                  + ",\"roomNum\":\"" + roomNum + "\",\"startTime\":\"" + startTime + "\",\"tollManName\":\"" + tollManName + "\"}";

                Dictionary <String, String> param = JSONHelper.StringToDictionary <string, string>(signParm);
                string signStr = BuildParamStr(param) + "&key=" + sKey + "";
                string sign    = MD5Encrypt(signStr);
                if (sign != HtcSign)
                {
                    new Logger().WriteLog("鸿坤道闸临停信息同步异常", DateTime.Now.ToString() + "--" + "签名错误:" + sign);

                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, "签名错误");
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }



                string    ctpStr       = "SELECT * FROM Tb_HTC_CommToPark WHERE ParkId='" + parkId + "'";
                DataTable dtCommToPark = new DbHelperSQLP(ContionString).Query(ctpStr).Tables[0];
                if (dtCommToPark.Rows.Count > 0)
                {
                    DataRow retRow = dtCommToPark.Rows[0];
                    CommID = retRow["CommID"].ToString();
                }
                else
                {
                    new Logger().WriteLog("鸿坤道闸临停信息同步异常", DateTime.Now.ToString() + "--" + "车场ID无法匹配天问CommID:" + ctpStr);

                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, "车场ID无法匹配天问CommID");
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }

                long      CustId         = 0;
                long      RoomId         = 0;
                long      CostId         = 0;
                long      CorpStanId     = 0;
                long      StanId         = 0;
                string    UserCode       = "";
                string    csStr          = "SELECT * FROM Tb_HTC_CostStandard WHERE ParkId='" + parkId + "'";
                DataTable dtCostStandard = new DbHelperSQLP(ContionString).Query(csStr).Tables[0];
                if (dtCostStandard.Rows.Count > 0)
                {
                    DataRow retRow = dtCostStandard.Rows[0];
                    CustId     = AppGlobal.StrToLong(retRow["CustId"].ToString());
                    RoomId     = AppGlobal.StrToLong(retRow["RoomId"].ToString());
                    CostId     = AppGlobal.StrToLong(retRow["CostId"].ToString());
                    CorpStanId = AppGlobal.StrToLong(retRow["CorpStanId"].ToString());
                    StanId     = AppGlobal.StrToLong(retRow["StanId"].ToString());
                    UserCode   = retRow["UserCode"].ToString();
                }
                else
                {
                    new Logger().WriteLog("鸿坤道闸临停信息同步异常", DateTime.Now.ToString() + "--" + "车场ID无法匹配天问收费标准:" + csStr);
                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, "车场ID无法匹配天问收费标准");
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }
                try
                {
                    DynamicParameters parameters = new DynamicParameters();
                    var InfoCode = Guid.NewGuid();
                    parameters.Add("@InfoCode", InfoCode);
                    parameters.Add("@CardID", null);
                    parameters.Add("@CardType", null);
                    parameters.Add("@GoName", null);
                    parameters.Add("@CommID", CommID);
                    parameters.Add("@OverTime", startTime);
                    parameters.Add("@OutTime", endTime);
                    parameters.Add("@CarNumber", null);
                    parameters.Add("@Money", feeExpected);
                    parameters.Add("@IssueDate", null);
                    parameters.Add("@dutyId", dutyId);
                    parameters.Add("@feeCash", feeCash);
                    parameters.Add("@feeWechat", feeWechat);
                    parameters.Add("@feeAli", feeAli);

                    int b = con.Execute("Proc_HSPR_TemporaryCarPrecostsDetail_Insert", parameters, null, null, CommandType.StoredProcedure);
                    con.Dispose();
                    if (b > 0)
                    {
                        string Memo = "";
                        if (AppGlobal.StrToDec(feeAli) > 0)
                        {
                            Memo = "支付宝收款";
                            CreateCarFees(AppGlobal.StrToInt(CommID), CustId, RoomId, AppGlobal.StrToDec(feeAli), CorpStanId,
                                          StanId, Memo, CostId, UserCode);
                        }
                        if (AppGlobal.StrToDec(feeWechat) > 0)
                        {
                            Memo = "微信收款";
                            CreateCarFees(AppGlobal.StrToInt(CommID), CustId, RoomId, AppGlobal.StrToDec(feeWechat), CorpStanId,
                                          StanId, Memo, CostId, UserCode);
                        }
                        if (AppGlobal.StrToDec(feeCash) > 0)
                        {
                            Memo = "现金收款";
                            CreateCarFees(AppGlobal.StrToInt(CommID), CustId, RoomId, AppGlobal.StrToDec(feeCash), CorpStanId,
                                          StanId, Memo, CostId, UserCode);
                        }
                        new Logger().WriteLog("鸿坤道闸临停信息请求参数", DateTime.Now.ToString() + "--同步成功 " + Memo);
                        string State        = "true";
                        string ErrorContent = JSONHelper.FromStringHK(false, "同步成功");
                        log.ErrorContent = ErrorContent;
                        log.State        = State;
                        LogAdd(log);
                        return(ErrorContent);
                    }
                    else
                    {
                        new Logger().WriteLog("鸿坤道闸临停信息请求参数", DateTime.Now.ToString() + "--同步失败!");
                        string State        = "false";
                        string ErrorContent = JSONHelper.FromStringHK(false, "同步失败");
                        log.ErrorContent = ErrorContent;
                        log.State        = State;
                        LogAdd(log);
                        return(ErrorContent);
                    }
                }
                catch (Exception ex)
                {
                    new Logger().WriteLog("鸿坤道闸临停信息同步异常", DateTime.Now.ToString() + "--" + ex.ToString());
                    string State        = "false";
                    string ErrorContent = JSONHelper.FromStringHK(false, ex.Message);
                    log.ErrorContent = ErrorContent;
                    log.State        = State;
                    LogAdd(log);
                    return(ErrorContent);
                }
            }
            catch (Exception ex)
            {
                new Logger().WriteLog("鸿坤道闸临停信息同步异常", DateTime.Now.ToString() + "--" + ex.ToString());
                string State        = "false";
                string ErrorContent = JSONHelper.FromStringHK(false, ex.Message);
                log.ErrorContent = ErrorContent;
                log.State        = State;
                LogAdd(log);
                return(ErrorContent);
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method is called 'Ping()' to keep in mind that his responsibility is just to wakup the web service,
        /// nothing more than that.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static LoginResponse Ping(string url)
        {
            //Set the request
            LoginRequestQueue loginRequestQueue = new LoginRequestQueue
            {
                Username = Config.Instance.UserAllowedToUseServiceLogin,
                Password = Config.Instance.UserAllowedToUseServicePassword
            };
            //Get attrubute service
            var attribute = typeof(LoginRequestQueue).GetCustomAttributes(true).OfType <TokenHandler.Attributes.ServiceRequestAttribute>().FirstOrDefault();

            //Call
            if (attribute == null)
            {
                //--------------------------------------------------------------
                // Erreur dans la réponse
                //--------------------------------------------------------------
                var resp = Activator.CreateInstance <LoginResponse>();
                resp.Code        = WindServMessagesConst.AttributeMissingCode;
                resp.Message     = $"{WindServMessagesConst.AttributeMissingMessage} {typeof(LoginRequestQueue).Name}";
                resp.ResponseMsg = null;
                return(resp);
            }
            try
            {
                #region Timeout management
                //ServicePointManager.ServerCertificateValidationCallback += (se, certificate, chain, sslPolicyErrors) => true;
                //httpWebRequest.Timeout = (httpWebRequest.Timeout * 10);
                //httpWebRequest.Timeout = (120);
                #endregion

                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(url + WindServMessagesConst.HttpWebRequestSeparator + attribute.Url);
                httpWebRequest.ContentType = WindServMessagesConst.HttpWebRequestContentType;
                httpWebRequest.Method      = WindServMessagesConst.HttpWebRequestMethod;
                var json = JsonHelp.JsonSerialize(loginRequestQueue);
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(json); }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                //Web server do not respond
                if (httpResponse.StatusCode != HttpStatusCode.OK)
                {
                    var resp = Activator.CreateInstance <LoginResponse>();
                    resp.Code        = WindServMessagesConst.ServerDoNotRespondCode;
                    resp.ResponseMsg = $"{WindServMessagesConst .ServerDoNotRespondMessage} {httpResponse.StatusCode.ToString()}";
                    return(resp);
                }
                //Ok wen service answered something
                var result = Activator.CreateInstance <LoginResponse>();
                using (var respStream = httpResponse.GetResponseStream())
                {
                    if (respStream == null)
                    {
                        return(null);
                    }
                    var reader = new StreamReader(respStream);
                    var rep    = @reader.ReadToEnd().Trim();
                    try
                    {
                        result = (LoginResponse)JsonHelp.JsonDeserialize <LoginResponse>(rep);//response ok
                    }
                    catch (Exception e)
                    {
                        //----------------------------------
                        // Erreur dans le message de retour
                        //----------------------------------
                        var resp = Activator.CreateInstance <LoginResponse>();
                        resp.Code        = WindServMessagesConst.ServerErreurResponseCode;
                        resp.ResponseMsg = e.Message;
                        return(resp);
                    }
                }
                return(result);
            }
            catch (WebException e)
            {
                var resp = Activator.CreateInstance <LoginResponse>();
                resp.Code        = WindServMessagesConst.WebExceptionCode;
                resp.ResponseMsg = e.Message;
                return(resp);
            }
            catch (UriFormatException e)
            {
                var resp = Activator.CreateInstance <LoginResponse>();
                resp.Code        = WindServMessagesConst.UriFormatExceptionCode;
                resp.ResponseMsg = e.Message;
                return(resp);
            }
            catch (Exception e)
            {
                //-------------------------------
                // Erreur générale du Web Service
                //-------------------------------
                var resp = Activator.CreateInstance <LoginResponse>();
                resp.Code        = WindServMessagesConst.GlobalExceptionCode;
                resp.ResponseMsg = e.Message;
                return(resp);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TRequestContractType"></typeparam>
        /// <typeparam name="TResultType"></typeparam>
        /// <param name="dRequest"></param>
        /// <returns></returns>
        public List <TResultType> CallService <TRequestContractType, TResultType>(List <TRequestContractType> dRequest)
            where TResultType : ModelBusiness.Response
            where TRequestContractType : Contracts.BaseContractERP
        {
            var attribute = typeof(TRequestContractType).GetCustomAttributes(true).OfType <ServiceRequestAttribute>().FirstOrDefault();

            if (attribute == null)
            {
                //--------------------------------------------------------------
                // Erreur dans la réponse
                //--------------------------------------------------------------
                var resultError = new List <TResultType>();
                foreach (var r in dRequest)
                {
                    var resp = Activator.CreateInstance <TResultType>();
                    resp.Code              = "9005";
                    resp.Message           = "Attribut RequestContractType manquant pour le type " + typeof(TRequestContractType).Name;
                    resp.ErpOprNumber      = Guid.Empty;
                    resp.DynamicsOprNumber = Guid.Empty;
                    resultError.Add(resp);
                }
                return(resultError);
            }

            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(_clientConfiguration.UriString + "\\" + attribute.Url);
                //httpWebRequest.Timeout = (httpWebRequest.Timeout * 10);
                //httpWebRequest.Timeout = (120);
                httpWebRequest.ContentType = "application/json; charset=utf-8; ";
                httpWebRequest.Method      = "POST";
                var json = JsonHelp.JsonSerialize(dRequest);

                // Envoyer les données au service.
                using (var streamWriter =
                           new StreamWriter(httpWebRequest.GetRequestStream())){ streamWriter.Write(json); }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                if (httpResponse.StatusCode != HttpStatusCode.OK)
                {
                    //--------------------------------------------------------------
                    // Erreur dans la réponse
                    //--------------------------------------------------------------
                    var resultError = new List <TResultType>();
                    foreach (var r in dRequest)
                    {
                        var resp = Activator.CreateInstance <TResultType>();
                        resp.Code              = "9004";
                        resp.Message           = "Aucune réponse : " + httpResponse.StatusCode.ToString();
                        resp.ErpOprNumber      = Guid.Empty;
                        resp.DynamicsOprNumber = Guid.Empty;
                        resultError.Add(resp);
                    }
                    return(resultError);
                }

                List <TResultType> result;
                using (var respStream = httpResponse.GetResponseStream())
                {
                    if (respStream == null)
                    {
                        return(null);
                    }
                    var reader = new StreamReader(respStream);
                    var rep    = @reader.ReadToEnd().Trim();
                    try
                    {
                        result = (List <TResultType>)JsonHelp.JsonDeserialize <List <TResultType> >(rep);
                    }
                    catch (Exception e)
                    {
                        //-----------------------------------------------------------------
                        // Erreur dans le message de retour = Renvoi du message FrameWork
                        //-----------------------------------------------------------------
                        var resultError = new List <TResultType>();
                        foreach (var r in dRequest)
                        {
                            var resp = Activator.CreateInstance <TResultType>();
                            resp.Code              = "9999";
                            resp.Message           = e.Message;
                            resp.ErpOprNumber      = Guid.Empty;
                            resp.DynamicsOprNumber = Guid.Empty;
                            resultError.Add(resp);
                        }
                        return(resultError);
                    }
                }
                return(result);
            }
            catch (WebException e)
            {
                var resultError = new List <TResultType>();
                foreach (var r in dRequest)
                {
                    var resp = Activator.CreateInstance <TResultType>();
                    resp.Code              = "9000";
                    resp.Message           = e.Message;
                    resp.ErpOprNumber      = Guid.Empty;
                    resp.DynamicsOprNumber = Guid.Empty;
                    resultError.Add(resp);
                }
                return(resultError);
            }
            catch (UriFormatException e)
            {
                var resultError = new List <TResultType>();
                foreach (var r in dRequest)
                {
                    var resp = Activator.CreateInstance <TResultType>();
                    resp.Code              = "9001";
                    resp.Message           = e.Message;
                    resp.ErpOprNumber      = Guid.Empty;
                    resp.DynamicsOprNumber = Guid.Empty;
                    resultError.Add(resp);
                }
                return(resultError);
            }
            catch (Exception e)
            {
                //-----------------------------------------------------------------
                // Erreur générale du Web Service le message de retour =
                // Renvoi du message FrameWork
                //-----------------------------------------------------------------
                var resultError = new List <TResultType>();
                foreach (var r in dRequest)
                {
                    var resp = Activator.CreateInstance <TResultType>();
                    resp.Code              = "9999";
                    resp.Message           = e.Message;
                    resp.ErpOprNumber      = Guid.Empty;
                    resp.DynamicsOprNumber = Guid.Empty;
                    resultError.Add(resp);
                }
                return(resultError);
            }
        }