Ejemplo n.º 1
0
 public override HttpResponseMessage DoGet()
 {
     try
     {
         Params4ApiCRUD P = GenCRUDParam4RD();
         if (!VerifyParam(P))
         {
             return(RespFailMsg(new tb_TMS_DD()));
             //return RespMsg(NoDocResp);
         }
         DataSet ds = _BLLInstance.DoGet(P);
         if (ds.Tables[TbName.tb_TMS_DD].Rows.Count <= 0)
         {
             return(RespFailMsg(new tb_TMS_DD()));
             //return RespMsg(NoDocResp);
         }
         string            dataset_json_string = JsonConvert.SerializeObject(ds, _JsonSetting);
         tb_TMS_DD4DataSet dataset_json_class  = (tb_TMS_DD4DataSet)JsonConvert.DeserializeObject(dataset_json_string, typeof(tb_TMS_DD4DataSet));
         return(RespOkMsg(dataset_json_class.tb_TMS_DD[0]));
     }
     catch (Exception ex)
     {
         return(RespExMsg(ex));
     }
 }
Ejemplo n.º 2
0
        public override HttpResponseMessage DoTestGet()
        {
            try
            {
                Params4ApiCRUD P = GenCRUDParam4RD();
                //if (P == null)
                //{
                //    return RespFailMsg(new tb_TMS_DD());
                //    //return RespMsg(NoDocResp);
                //}
                P.chooseDataBase = ChooseDataBase.Test;
                if (!VerifyParam(P))
                {
                    return(RespFailMsg(new tb_TMS_DD()));
                    //return RespMsg(NoDocResp);
                }
                DataSet ds = _BLLInstance.DoGet(P);
                if (ds.Tables[0].Rows.Count <= 0)
                {
                    return(RespFailMsg(new tb_TMS_DD()));
                }
                //return RespOkMsg(ds.Tables[0]);

                //否则日期中间会多出来个T,莫名其妙
                string            dataset_json_string = JsonConvert.SerializeObject(ds, _JsonSetting);
                tb_TMS_DD4DataSet dataset_json_class  = (tb_TMS_DD4DataSet)JsonConvert.DeserializeObject(dataset_json_string, typeof(tb_TMS_DD4DataSet));

                return(RespOkMsg(dataset_json_class.tb_TMS_DD[0]));
            }
            catch (Exception ex)
            {
                return(RespExMsg(ex));
            }
        }
Ejemplo n.º 3
0
        //protected  IGenerateDataBaseCommand CreateDataBaseGenerator(string tableName, DataTable dt, DbProviderType dbProviderType)
        //{
        //    Type ORM = null;
        //    if (tableName == dt_test.__TableName) ORM = typeof(dt_test);
        //    if (ORM == null) throw new Exception(tableName + "表没有ORM模型,请生成此表的Model类!");
        //    return new GenerateDataBaseCommandByTableFields(ORM, dt, dbProviderType);
        //}
        public override DataSet Get(Params4ApiCRUD P)
        {
            DbProvider4DAL dbp = new DAL.DbProvider4DAL("usp_WebApi_Get_tb_TMS_DD", P.chooseDataBase, P.dbProviderType);

            DataProvider.Instance.AddDbParamsByPropertyInfo(dbp.CurrentCommand, P.fromUri);
            DataProvider.Instance.AddDbParamsByCustom(dbp.CurrentCommand, "@CustomerCode", P.UserCode, DbType.String, 32);
            DataSet ds = new DataSet();

            ds = DataProvider.Instance.GetDataSet(dbp);
            ds.Tables[0].TableName = TbName.tb_TMS_DD;
            return(ds);
        }
Ejemplo n.º 4
0
        protected override Params4ApiCRUD GenCRUDParam4RD()
        {
            tb_TMS_DD_Base tb_TMS_DD_Base = FromUri2tb_TMS_DD_Base();
            //if (tb_TMS_DD_Base == null)
            //{
            //    return null;
            //}
            //IniBLLInstance();
            Params4ApiCRUD P = new Params4ApiCRUD();

            P.fromUri = tb_TMS_DD_Base;
            return(P);
        }
Ejemplo n.º 5
0
        protected override Params4ApiCRUD GenCRUDParam4CU()
        {
            tb_TMS_DD _tb_TMS_DD = FromUri2tb_TMS_DD();
            //if (_tb_TMS_DD == null)
            //{
            //    return null;
            //}
            //IniBLLInstance();
            Params4ApiCRUD P = new Params4ApiCRUD();

            P.fromUri = _tb_TMS_DD;
            return(P);
        }
Ejemplo n.º 6
0
        public override DataSet Delete(Params4ApiCRUD P)
        {
            DbProvider4DAL dbp = new DAL.DbProvider4DAL("usp_WebApi_Delete_tb_TMS_DD", P.chooseDataBase, P.dbProviderType);

            DataProvider.Instance.AddDbParamsByPropertyInfo(dbp.CurrentCommand, P.fromUri);
            DataProvider.Instance.AddDbParamsByCustom(dbp.CurrentCommand, "@CustomerCode", P.UserCode, DbType.String, 32);
            DataSet ds = new DataSet();

            using (_Scope = new TransactionScope())
            {
                ds = DataProvider.Instance.GetDataSet(dbp);
                _Scope.Complete();
            }
            return(ds);
        }
Ejemplo n.º 7
0
        protected virtual DataSet Search(Params4ApiCRUD params4ApiCRUD)
        {
            DataSet ds     = new DataSet();
            string  errmsg = GetErrMsg(params4ApiCRUD.fromUri);

            if (!errmsg.IsNullOrEmpty())
            {
                AddErrMsg(ds, errmsg);
            }
            else
            {
                ds = _DALBase.Search(params4ApiCRUD);
            }
            return(ds);
        }
Ejemplo n.º 8
0
        protected virtual DataSet Delete(Params4ApiCRUD params4ApiCRUD)
        {
            DataSet ds     = new DataSet();
            string  errmsg = GetErrMsg(params4ApiCRUD.fromUri);

            if (!errmsg.IsNullOrEmpty())
            {
                AddErrMsg(ds, errmsg);
            }
            else
            {
                ds = this.Delete(params4ApiCRUD);
            }
            return(ds);
        }
Ejemplo n.º 9
0
 public override HttpResponseMessage DoDelete()
 {
     try
     {
         Params4ApiCRUD P = GenCRUDParam4RD();
         if (!VerifyParam(P))
         {
             return(RespMsg(NoDocResp));
         }
         DataSet ds = _BLLInstance.DoDelete(P);
         return(RespMsg4CRUD(ds.Tables[0].Rows[0]));
     }
     catch (Exception ex)
     {
         return(RespExMsg(ex));
     }
 }
Ejemplo n.º 10
0
        private bool VerifyParam(Params4ApiCRUD P, bool VerifyDDNO = true)
        {
            //if (P == null)
            //{
            //    return false;
            //}
            if (VerifyDDNO)
            {
                if (!SimpleVerifyDocNo(DocType.预订单, ((Itb_TMS_DD)P.fromUri).DDNO.ToStringEx()))
                {
                    return(false);
                }
            }
            if (!VerifyUserKey(P))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
0
 private HttpResponseMessage DoRefreshUserKey()
 {
     try
     {
         //if(!IsSysKey())
         //{
         //    return RespFailMsg();
         //}
         Params4ApiCRUD P = new Params4ApiCRUD();
         P.chooseDataBase = ChooseDataBase.System;
         if (!VerifyUserKey(P, 5))
         {
             return(RespFailMsg());
         }
         RAMCache.Instance.RefreshUserKey();
         return(RespOkMsg());
     }
     catch (Exception ex)
     {
         return(RespExMsg(ex));
     }
 }
Ejemplo n.º 12
0
 public override HttpResponseMessage DoTestPut()
 {
     try
     {
         Params4ApiCRUD P = GenCRUDParam4CU();
         if (P == null)
         {
             return(RespMsg(NoDocResp));
         }
         P.chooseDataBase = ChooseDataBase.Test;
         if (!VerifyParam(P))
         {
             return(RespMsg(NoDocResp));
         }
         DataSet ds = _BLLInstance.DoPut(P);
         return(RespMsg4CRUD(ds.Tables[0].Rows[0]));
     }
     catch (Exception ex)
     {
         return(RespExMsg(ex));
     }
 }
Ejemplo n.º 13
0
        //{
        //    throw new NotImplementedException();
        //}

        public abstract DataSet Delete(Params4ApiCRUD params4ApiCRUD);
Ejemplo n.º 14
0
        //{
        //    throw new NotImplementedException();
        //}

        public abstract DataSet Put(Params4ApiCRUD params4ApiCRUD);
Ejemplo n.º 15
0
        //{
        //    throw new NotImplementedException();
        //}

        public abstract DataSet Search(Params4ApiCRUD params4ApiCRUD);
Ejemplo n.º 16
0
 public virtual DataSet DoPut(Params4ApiCRUD params4ApiCRUD)
 {
     return(this.Put(params4ApiCRUD));
 }
Ejemplo n.º 17
0
 public virtual DataSet DoSearch(Params4ApiCRUD params4ApiCRUD)
 {
     return(this.Search(params4ApiCRUD));
 }
Ejemplo n.º 18
0
 public virtual DataSet DoDelete(Params4ApiCRUD params4ApiCRUD)
 {
     return(this.Delete(params4ApiCRUD));
 }
Ejemplo n.º 19
0
 public override DataSet Search(Params4ApiCRUD params4ApiCRUD)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 20
0
        //protected virtual bool IsSysKey()
        //{
        //    try
        //    {
        //        string UserKey = this.Request.Headers.GetValues(WebApiGlobal._USERKEY).ToArray()[0];
        //        //string requestUri = this.Request.RequestUri.OriginalString;
        //        string requestUri = this.Request.Headers.GetValues(WebApiGlobal._ORI_REQUEST_URL).ToArray()[0];
        //        //string requestUri = this.Request.RequestUri.OriginalString;
        //        requestUri = System.Web.HttpUtility.UrlDecode(requestUri);
        //        DataTable dt = RAMCache.Instance.UserKeyAndSalt;
        //        DataRow[] dr = dt.Select(WebApiGlobal._USERKEY + " = '" + UserKey + "'");
        //        if (dr.Length == 1)
        //        {
        //            string keyDataBase = dr[0][WebApiGlobal._DATABASENAME].ToString();
        //            string userCode = dr[0][WebApiGlobal._USERCODE].ToString();

        //            if (keyDataBase == ChooseDataBase.System.ToString())
        //            {
        //                return true;
        //            }
        //            else
        //            {
        //                AutoNLog.Log4Warn(CustomErrorMessage.UserKey跨库使用.ToString() + ",UserCode:" + userCode + ",RequestUri:" + requestUri);
        //                return false;
        //            }
        //        }
        //        else
        //        {
        //            AutoNLog.Log4Warn(CustomErrorMessage.UserKey无效.ToString() + ",UserKey:" + UserKey + ",RequestUri:" + requestUri);
        //            return false;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        AutoNLog.Log4Exception(CustomErrorMessage.发生异常.ToString(), ex);
        //        return false;
        //    }
        //}
        //protected virtual bool VerifyUserKey(Params4ApiCRUD P)
        //{
        //    string UserKey = this.Request.Headers.GetValues(WebApiGlobal._USERKEY).ToArray()[0];
        //    //string SHA512UserKey = Encryption.Instance.StringToSHA512Hash(UserKey);
        //    DataTable dt = RAMCache.Instance.UserKeyAndSalt;
        //    DataRow[] dr = dt.Select(WebApiGlobal._USERKEY + " = '" + UserKey + "'");
        //    string chooseDataBase = DataBaseConnFactory.Instance.GetUserKeyAndDataBase(P.chooseDataBase);
        //    string keyDataBase = dr[0][WebApiGlobal._DATABASENAME].ToString();
        //    string userCode = dr[0][WebApiGlobal._USERCODE].ToString();
        //    if (chooseDataBase == keyDataBase)
        //    {
        //        P.UserCode = userCode;
        //        return true;
        //    }
        //    else
        //    {
        //        string ClientTS = this.Request.Headers.GetValues(WebApiGlobal._TIMESPAN).ToArray()[0];

        //        //string requestUri = this.Request.RequestUri.AbsoluteUri;
        //        string requestUri = this.Request.RequestUri.OriginalString;
        //        requestUri = System.Web.HttpUtility.UrlDecode(requestUri);

        //        string str4Log = "ChooseDataBase:" + chooseDataBase + ",UserCode:" + userCode + ",ClientTS:" + ClientTS + ",requestUri:" + requestUri;

        //        AutoNLog.Log4Warn(CustomErrorMessage.UserKey跨库使用.ToString() + str4Log);
        //        return false;
        //    }
        //}

        protected virtual bool VerifyUserKey(Params4ApiCRUD P, decimal timespan = 600)//默认允许时差十分钟
        {
            try
            {
                bool   iscorrect = false;
                string ClientTS  = this.Request.Headers.GetValues(WebApiGlobal._TIMESPAN).ToArray()[0];
                string ServerTS  = CommonMethod.UTCTS;
                //string requestUri = this.Request.RequestUri.AbsoluteUri;
                string requestUri = this.Request.Headers.GetValues(WebApiGlobal._ORI_REQUEST_URL).ToArray()[0];
                //string requestUri = this.Request.RequestUri.OriginalString;
                requestUri = System.Web.HttpUtility.UrlDecode(requestUri);
                string UserKey = this.Request.Headers.GetValues(WebApiGlobal._USERKEY).ToArray()[0];

                string chooseDataBase = P.chooseDataBase.ToString();

                DataTable dt         = RAMCache.Instance.UserKeyAndSalt;
                DataRow[] dr         = dt.Select(WebApiGlobal._USERKEY + " = '" + UserKey + "'");
                string    str4ErrLog = "";
                if (dr.Length == 1)
                {
                    string UserCode    = dr[0][WebApiGlobal._USERCODE].ToString();
                    string UserSalt    = dr[0][WebApiGlobal._USERSALT].ToString();
                    string OriKey      = dr[0][WebApiGlobal._DECODE_USERKEY].ToString();
                    string KeyDataBase = dr[0][WebApiGlobal._DATABASENAME].ToString();
                    str4ErrLog = "UserCode:" + UserCode + ",ClientTS:" + ClientTS + ",requestUri:" + requestUri;

                    decimal tsc  = ClientTS.ToDecimalEx(0);
                    decimal tss  = ServerTS.ToDecimalEx(0);
                    decimal diff = tss - tsc;
                    if (diff > timespan || diff < -5)
                    {
                        AutoNLog.Log4Warn(CustomErrorMessage.TimeSpan错误.ToString() + str4ErrLog);
                        return(iscorrect);
                    }

                    if (chooseDataBase != KeyDataBase)
                    {
                        AutoNLog.Log4Warn(CustomErrorMessage.UserKey跨库使用.ToString() + "ChooseDataBase:" + chooseDataBase + str4ErrLog);
                        return(iscorrect);
                    }

                    string ClientSHA256Sign = this.Request.Headers.GetValues(WebApiGlobal._SHA256).ToArray()[0];
                    string ServerSHA256Sign = CommonMethod.StringToSHA256Hash(OriKey + requestUri + ClientTS + UserSalt);
                    if (ClientSHA256Sign != ServerSHA256Sign)
                    {
                        AutoNLog.Log4Warn(CustomErrorMessage.Hash校验错误.ToString() + str4ErrLog + ",ClientSHA256Sign:" + ClientSHA256Sign + ",ServerSHA256Sign:" + ServerSHA256Sign);
                        return(iscorrect);
                    }
                    P.UserCode = UserCode;
                    iscorrect  = true;
                    return(iscorrect);
                }
                else
                {
                    AutoNLog.Log4Warn(CustomErrorMessage.UserKey无效.ToString() + UserKey);
                    return(iscorrect);
                }
            }
            catch (Exception ex)
            {
                AutoNLog.Log4Exception(CustomErrorMessage.Hash校验异常.ToString(), ex);
                return(false);
            }
        }