Esempio n. 1
0
        protected virtual void LoadConfig(WebParameter p, GoData d)
        {
            foreach (var item in MyConfig.GetConfigurationList("ConnectionStrings"))
            {
                p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
            }
            p.DBConnectionString = ComFunc.nvl(p[DomainKey.CONFIG, "DefaultConnection"]);
            bool bvalue = true;

            foreach (var item in MyConfig.GetConfigurationList("EFFC"))
            {
                if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue))
                {
                    p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value));
                }
                else if (DateTimeStd.IsDateTime(item.Value))
                {
                    p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value;
                }
                else
                {
                    p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
                }
            }
        }
Esempio n. 2
0
        public string ConvertTo(object obj)
        {
            if (obj == null)
            {
                return("");
            }

            string             rtn = "";
            UnitDataCollection udc = null;

            if (obj is UnitDataCollection)
            {
                udc = (UnitDataCollection)obj;
            }
            else
            {
                throw new Exception("QueryByPage2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }

            if (udc.QueryTable != null)
            {
                JsonObjectCollection jsonrtn = new JsonObjectCollection();
                //jsonrtn.Add(new JsonStringValue("Count_Of_OnePage", udc.Count_Of_OnePage + ""));
                jsonrtn.Add(new JsonStringValue("page", udc.CurrentPage + ""));
                //jsonrtn.Add(new JsonStringValue("total", udc.TotalPage + ""));
                jsonrtn.Add(new JsonStringValue("total", udc.TotalRow + ""));

                DataTableStd        dts     = udc.QueryTable;
                JsonArrayCollection jsonobj = new JsonArrayCollection("rows");
                for (int j = 0; j < dts.RowLength; j++)
                {
                    JsonObjectCollection jac = new JsonObjectCollection();
                    foreach (string colname in dts.ColumnNames)
                    {
                        if (dts.ColumnDateType(colname).FullName == typeof(DateTime).FullName)
                        {
                            DateTimeStd dtime = DateTimeStd.ParseStd(dts[j, colname]);
                            jac.Add(new JsonStringValue(colname, dtime != null ? dtime.Value.ToString("yyyy/MM/dd HH:mm:ss") : ""));
                        }
                        else
                        {
                            jac.Add(new JsonStringValue(colname, ComFunc.nvl(dts[j, colname])));
                        }
                    }
                    jsonobj.Add(jac);
                }
                jsonrtn.Add(jsonobj);



                rtn = jsonrtn.ToString();
            }

            return(rtn);
        }
Esempio n. 3
0
        /// <summary>
        /// 獲得一個webrequest的實例
        /// </summary>
        /// <returns></returns>
        protected virtual HttpWebRequest GetRequestInstance()
        {
            HttpWebRequest hr           = (HttpWebRequest)WebRequest.Create(new Uri(_url));
            string         cookieheader = "";

            if (hr.CookieContainer != null)
            {
                cookieheader = hr.CookieContainer.GetCookieHeader(new Uri(_url));
            }

            CookieContainer cookieCon = new CookieContainer();

            hr.CookieContainer = cookieCon;
            hr.CookieContainer.SetCookies(new Uri(_url), cookieheader);

            hr.KeepAlive = false;
            hr.Method    = _requestmethod;
            hr.Proxy     = _proxy;
            if (_cert != null)
            {
                hr.ClientCertificates.Add(_cert);
            }
            //添加header
            foreach (var k in _header.Keys)
            {
                if (k.ToLower() == "date")
                {
                    hr.Date = DateTimeStd.IsDateTime(_header.GetValue(k)) ? DateTimeStd.ParseStd(ComFunc.nvl(_header.GetValue(k))).Value : DateTime.Now;
                }
                else if (k.ToLower() == "content-length")
                {
                    hr.ContentLength = long.Parse(ComFunc.nvl(_header.GetValue(k)));
                }
                else if (k.ToLower() == "user-agent")
                {
                    hr.UserAgent = ComFunc.nvl(_header.GetValue(k));
                }
                else
                {
                    if (ComFunc.nvl(hr.Headers[k]) != "")
                    {
                        hr.Headers[k] = ComFunc.nvl(_header.GetValue(k));
                    }
                    else
                    {
                        hr.Headers.Add(k, ComFunc.nvl(_header.GetValue(k)));
                    }
                }
            }
            return(hr);
        }
Esempio n. 4
0
        object DoSyncSummaryPerDay17()
        {
            lock (lockobj)
            {
                DateTime start = DateTimeStd.ParseStd($"{DateTime.Now.ToString("yyyy-MM-dd")} 09:00:00").Value;
                DateTime end   = DateTimeStd.ParseStd($"{DateTime.Now.ToString("yyyy-MM-dd")} 17:00:00").Value;
                var      up    = DB.NewDBUnitParameter();
                //BeginTrans();
                var msg = "";
                if (!DoSyncAPPSummaryPerDay(up, start, end, ref msg))
                {
                    return(new
                    {
                        issuccess = false,
                        msg
                    });
                }
                if (!DoSyncRetailSummaryPerDay(up, start, end, ref msg))
                {
                    return(new
                    {
                        issuccess = false,
                        msg
                    });
                }
                if (!DoSyncChannelSummaryPerDay(up, start, end, ref msg))
                {
                    return(new
                    {
                        issuccess = false,
                        msg
                    });
                }
                if (!DoSyncPlatSummaryPerDay(up, start, end, ref msg))
                {
                    return(new
                    {
                        issuccess = false,
                        msg
                    });
                }

                //CommitTrans();
                return(new
                {
                    code = "success",
                    msg = "执行成功"
                });
            }
        }
Esempio n. 5
0
        public string ConvertTo(object obj)
        {
            string rtn = "";

            if (obj == null)
            {
                return("");
            }

            DataSet ds = null;

            if (obj is DataSet)
            {
                ds = (DataSetStd)obj;
            }
            else
            {
                throw new Exception("DataSet2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }

            JsonObjectCollection jsonrtn = new JsonObjectCollection();

            for (int i = 0; i < ds.Tables.Count; i++)
            {
                DataTableStd        dts     = DataTableStd.ParseStd(ds.Tables[i]);
                JsonArrayCollection jsonobj = new JsonArrayCollection("TableData" + i);
                for (int j = 0; j < dts.RowLength; j++)
                {
                    JsonObjectCollection jac = new JsonObjectCollection();
                    foreach (string colname in dts.ColumnNames)
                    {
                        if (dts.ColumnDateType(colname).FullName == typeof(DateTime).FullName)
                        {
                            DateTimeStd dtime = DateTimeStd.ParseStd(dts[j, colname]);
                            jac.Add(new JsonStringValue(colname, dtime != null ? dtime.Value.ToString("yyyy/MM/dd HH:mm:ss") : ""));
                        }
                        else
                        {
                            jac.Add(new JsonStringValue(colname, ComFunc.nvl(dts[j, colname])));
                        }
                    }
                    jsonobj.Add(jac);
                }
                jsonrtn.Add(jsonobj);
            }

            rtn = "{" + jsonrtn.ToString() + "}";
            return(rtn);
        }
Esempio n. 6
0
 private void SetPropertyValue <M>(ref M m, PropertyInfo fi, object value)
 {
     if (fi.PropertyType.FullName == typeof(DateTime).FullName)
     {
         fi.SetValue(m, DateTimeStd.ParseStd(value).Value, null);
     }
     else if (fi.GetCustomAttributes(typeof(ConvertorAttribute), false).Length > 0)
     {
         ConvertorAttribute ca = (ConvertorAttribute)Attribute.GetCustomAttribute(fi, typeof(ConvertorAttribute), false);
         fi.SetValue(m, ca.Convertor.ConvertTo(value), null);
     }
     else
     {
         fi.SetValue(m, value, null);
     }
 }
Esempio n. 7
0
        public JsonCollection ConvertTo(object obj)
        {
            if (obj == null)
            {
                return(new JsonObjectCollection());
            }

            DataTableStd dtt = null;

            if (obj is DataTable)
            {
                dtt = DataTableStd.ParseStd(obj);
            }
            else if (obj is DataTableStd)
            {
                dtt = (DataTableStd)obj;
            }
            else
            {
                throw new Exception("DataTable2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }

            JsonArrayCollection jsonobj = new JsonArrayCollection("rows");

            for (int i = 0; i < dtt.RowLength; i++)
            {
                JsonObjectCollection jac = new JsonObjectCollection();
                foreach (string colname in dtt.ColumnNames)
                {
                    if (dtt.ColumnDateType(colname).FullName == typeof(DateTime).FullName)
                    {
                        DateTimeStd dtime = DateTimeStd.ParseStd(dtt[i, colname]);
                        jac.Add(new JsonStringValue(colname, dtime != null ? dtime.Value.ToString("yyyy/MM/dd HH:mm:ss") : ""));
                    }
                    else
                    {
                        jac.Add(new JsonStringValue(colname, ComFunc.nvl(dtt[i, colname])));
                    }
                }
                jsonobj.Add(jac);
            }


            return(jsonobj);
        }
Esempio n. 8
0
        protected override void LoadConfig(WebParameter p, GoData d)
        {
            base.LoadConfig(p, d);
            bool bvalue = true;

            foreach (var item in MyConfig.GetConfigurationList("Weixin"))
            {
                if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue))
                {
                    p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value));
                }
                else if (DateTimeStd.IsDateTime(item.Value))
                {
                    p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value;
                }
                else
                {
                    p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
                }
            }
        }
        protected override ParameterStd ConvertParameters(object[] obj)
        {
            var p = new ConsoleParameter();

            if (obj != null & obj.Length > 0)
            {
                var command = ComFunc.nvl(obj[0]).ToLower();
                if (command == "stop")
                {
                    p.ExtentionObj.stop = true;
                }
            }
            //config
            foreach (var item in MyConfig.GetConfigurationList("ConnectionStrings"))
            {
                p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
            }
            p.DBConnectionString = ComFunc.nvl(p[DomainKey.CONFIG, "DefaultConnection"]);
            bool bvalue = true;

            foreach (var item in MyConfig.GetConfigurationList("EFFC"))
            {
                if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue))
                {
                    p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value));
                }
                else if (DateTimeStd.IsDateTime(item.Value))
                {
                    p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value;
                }
                else
                {
                    p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
                }
            }

            return(p);
        }
Esempio n. 10
0
        /// <summary>
        /// 通过xml建立动态对象,最简单的xml结构,如下:
        /// <xxx>
        ///     <n1></n1>
        ///     <n2></n2>
        ///     <nodes>
        ///         <nn1></nn1>
        ///         <nnn></nnn>
        ///     </nodes>
        ///     <nn></nn>
        /// </xxx>
        /// </summary>
        /// <param name="node"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        private static dynamic BuildLoopXml(XmlNodeList nodelist, FrameDLRFlags flags)
        {
            FrameDLRObject rtn = new FrameDLRObject();

            if ((flags & FrameDLRFlags.SensitiveCase) != 0)
            {
                rtn.ignorecase = false;
            }
            else
            {
                rtn.ignorecase = true;
            }

            foreach (XmlNode item in nodelist)
            {
                if (item.HasChildNodes && item.FirstChild.NodeType == XmlNodeType.Element)
                {
                    FrameDLRObject rtnloop = BuildLoopXml(item.ChildNodes, flags);
                    rtn.SetValue(item.Name, rtnloop);
                }
                else
                {
                    if (DateTimeStd.IsDateTime(item.InnerText))
                    {
                        rtn.SetValue(item.Name, DateTimeStd.ParseStd(item.InnerText).Value);
                    }
                    else
                    {
                        rtn.SetValue(item.Name, item.InnerText);
                    }
                }
            }


            return(rtn);
        }
        protected override ParameterStd ConvertParameters(object[] obj)
        {
            var p = new ConsoleParameter();

            if (obj != null & obj.Length > 0)
            {
                var la = ComFunc.nvl(obj[0]).Split('.', StringSplitOptions.RemoveEmptyEntries);
                p.CallLogicName = la.Length > 0 ? la[0] : "";
                p.CallAction    = la.Length > 1 ? la[1] : "";
            }
            //config
            foreach (var item in MyConfig.GetConfigurationList("ConnectionStrings"))
            {
                p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
            }
            p.DBConnectionString = ComFunc.nvl(p[DomainKey.CONFIG, "DefaultConnection"]);
            bool bvalue = true;

            foreach (var item in MyConfig.GetConfigurationList("EFFC"))
            {
                if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue))
                {
                    p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value));
                }
                else if (DateTimeStd.IsDateTime(item.Value))
                {
                    p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value;
                }
                else
                {
                    p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
                }
            }

            return(p);
        }
        /// <summary>
        /// 从session中获取对象
        /// </summary>
        /// <param name="session"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object GetObject(this ISession session, string key)
        {
            var str = session.GetString(key);

            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }
            var arr = str.Split(';');

            if (arr.Length != 2)
            {
                return(null);
            }
            var assemblefullname = arr[0];
            var base64           = arr[1];

            var value        = ComFunc.Base64DeCode(base64.Replace(" ", "+"));
            var typefullname = assemblefullname.Substring(0, assemblefullname.IndexOf(","));
            var t            = Type.GetType(assemblefullname);

            if (typefullname == typeof(string).FullName)
            {
                return(value);
            }
            if (typefullname == typeof(FrameDLRObject).FullName)
            {
                return((FrameDLRObject)FrameDLRObject.CreateInstance(value, FrameDLRFlags.SensitiveCase));
            }
            if (t.GetTypeInfo().GetInterface(typeof(IJSONParsable).Name, true) != null)
            {
                var obj = (IJSONParsable)Activator.CreateInstance(t);
                obj.TryParseJSON(value);
                return(obj);
            }
            if (typefullname == typeof(int).FullName)
            {
                return(int.Parse(value));
            }
            if (typefullname == typeof(long).FullName)
            {
                return(long.Parse(value));
            }
            if (typefullname == typeof(float).FullName)
            {
                return(float.Parse(value));
            }
            if (typefullname == typeof(double).FullName)
            {
                return(double.Parse(value));
            }
            if (typefullname == typeof(decimal).FullName)
            {
                return(decimal.Parse(value));
            }
            if (typefullname == typeof(DateTime).FullName)
            {
                return(DateTimeStd.ParseStd(value, "yyyy/MM/dd HH:mm:ss fff").Value);
            }
            if (typefullname == typeof(bool).FullName)
            {
                return(bool.Parse(value));
            }


            FrameDLRObject dobj = FrameDLRObject.CreateInstance(value, FrameDLRFlags.SensitiveCase);

            return(dobj.ToModel(t));
        }
Esempio n. 13
0
        protected void SetControlValue(Control c, object value)
        {
            if (value is string)
            {
                value = value.ToString().Trim();
            }

            if (c is TextBox)
            {
                ((TextBox)c).Text = ComFunc.nvl(value);
            }
            else if (c is Label)
            {
                ((Label)c).Text = ComFunc.nvl(value);
            }
            else if (c is DropDownList)
            {
                if (value != null)
                {
                    if (value is string)
                    {
                        string v = ComFunc.nvl(value);
                        if (((DropDownList)c).Items.FindByValue(v) != null)
                        {
                            ((DropDownList)c).SelectedValue = ComFunc.nvl(value);
                        }
                    }
                }
            }
            else if (c is RadioButton)
            {
                ((RadioButton)c).Checked = value != null?bool.Parse(ComFunc.nvl(value)) : false;
            }
            else if (c is RadioButtonList)
            {
                ((RadioButtonList)c).SelectedValue = ComFunc.nvl(value);
            }
            else if (c is CalendarInput)
            {
                if (value is DateTime)
                {
                    ((CalendarInput)c).SelectedDate = DateTimeStd.ParseStd(value).Value;
                }
                else if (value is DateTimeStd)
                {
                    ((CalendarInput)c).SelectedDate = DateTimeStd.ParseStd(value);
                }
                else
                {
                    ((CalendarInput)c).Text = ComFunc.nvl(value);
                }
            }
            else if (c is CheckBox)
            {
                ((CheckBox)c).Checked = value != null?bool.Parse(ComFunc.nvl(value)) : false;
            }
            else if (c is CheckBoxList)
            {
                string stempvalue = (string)value;
                if (stempvalue != null)
                {
                    List <string> ltemp       = new List <string>();
                    string[]      splitvalues = stempvalue.Split(',');
                    foreach (string v in splitvalues)
                    {
                        ltemp.Add(v);
                    }
                    foreach (ListItem item in ((CheckBoxList)c).Items)
                    {
                        if (ltemp.Contains(item.Value))
                        {
                            item.Selected = true;
                        }
                    }
                }
            }
            else if (c is HiddenField)
            {
                ((HiddenField)c).Value = ComFunc.nvl(value);
            }
        }
Esempio n. 14
0
        private FrameDLRObject copyPOItem(dynamic source)
        {
            var rtn = FrameDLRObject.CreateInstance();

            rtn.hw_contract_no         = source.hw_contract_no;
            rtn.cust_contract_no       = source.cust_contract_no;
            rtn.version                = source.version;
            rtn.status                 = source.status;
            rtn.hw_frame_contract_no   = source.hw_frame_contract_no;
            rtn.cust_frame_contract_no = source.cust_frame_contract_no;
            rtn.hw_sign_entity         = source.hw_sign_entity;
            rtn.cust_sign_entity       = source.cust_sign_entity;
            rtn.cust_type_lv1          = source.cust_type_lv1;
            rtn.cust_type_lv2          = source.cust_type_lv2;
            rtn.trade_terms            = source.trade_terms;
            rtn.transport_mode         = source.transport_mode;
            rtn.payment_terms          = source.payment_terms;
            rtn.is_vat_included        = source.is_vat_included;
            rtn.contract_amount_cny    = DoubleStd.IsDouble(source.contract_amount_cny) ? DoubleStd.ParseStd(source.contract_amount_cny).Value : null;
            rtn.contract_amount_usd    = DoubleStd.IsDouble(source.contract_amount_usd) ? DoubleStd.ParseStd(source.contract_amount_usd).Value : null;
            rtn.retail_sample          = source.retail_sample;
            rtn.created_by             = source.created_by;
            rtn.created_date           = DateTimeStd.IsDateTime(source.created_date) ? DateTimeStd.ParseStd(source.created_date).Value.ToString("yyyyMMddHHmmss") : null;
            rtn.accepted_date          = DateTimeStd.IsDateTime(source.accepted_date) ? DateTimeStd.ParseStd(source.accepted_date).Value.ToString("yyyyMMddHHmmss") : null;
            rtn.review_completed_date  = DateTimeStd.IsDateTime(source.review_completed_date) ? DateTimeStd.ParseStd(source.review_completed_date).Value.ToString("yyyyMMddHHmmss") : null;
            rtn.signed_date            = DateTimeStd.IsDateTime(source.signed_date) ? DateTimeStd.ParseStd(source.signed_date).Value.ToString("yyyyMMddHHmmss") : null;
            return(rtn);
        }
        protected override bool DoValid(EWRAParameter ep, EWRAData ed)
        {
            if (fields == null)
            {
                return(true);
            }
            else
            {
                foreach (var f in fields)
                {
                    var ispostdata    = ep.ContainsKey(DomainKey.POST_DATA, f);
                    var isquerystring = ep.ContainsKey(DomainKey.QUERY_STRING, f);
                    var v             = ComFunc.nvl(ep[DomainKey.POST_DATA, f]);
                    v = v == "" ? ComFunc.nvl(ep[DomainKey.QUERY_STRING, f]) : v;
                    if (is_check_empty_error)
                    {
                        if (!DateTimeStd.IsDateTime(v))
                        {
                            return(false);
                        }
                        else
                        {
                            if (is_convert)
                            {
                                if (ispostdata)
                                {
                                    ep[DomainKey.POST_DATA, f] = DateTimeStd.ParseStd(v).Value;
                                }
                                if (isquerystring)
                                {
                                    ep[DomainKey.QUERY_STRING, f] = DateTimeStd.ParseStd(v).Value;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (v != "" && !DateTimeStd.IsDateTime(v))
                        {
                            return(false);
                        }
                        else
                        {
                            if (v != "")
                            {
                                if (is_convert)
                                {
                                    if (ispostdata)
                                    {
                                        ep[DomainKey.POST_DATA, f] = DateTimeStd.ParseStd(v).Value;
                                    }
                                    if (isquerystring)
                                    {
                                        ep[DomainKey.QUERY_STRING, f] = DateTimeStd.ParseStd(v).Value;
                                    }
                                }
                            }
                        }
                    }
                }

                return(true);
            }
        }
Esempio n. 16
0
        private bool AdminLogin(string id)
        {
            var up = DB.NewDBUnitParameter();
            var pw = PostDataD.pw;
            //登录模式,以下几种:Password-密码登录,AuthCode-验证码登录,OpenID-微信的OpenID方式登录;MP-微信小程序方式登录; 默认Password
            string login_mode = ComFunc.nvl(PostDataD.login_mode);

            if (login_mode == "")
            {
                login_mode = "Password";
            }
            if (!new string[] { "Password", "AuthCode", "OpenID", "MP" }.Contains(login_mode))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(id))
            {
                id = ComFunc.UrlDecode(ComFunc.nvl(PostDataD.id).ToLower());
            }
            //小程序登录需要通过id(即jscode)换取openid和sessionkey,然后写入db
            var weixin_union_id      = "";
            var weixinmp_session_key = "";

            if (login_mode == "MP")
            {
                var     jscode = id;
                dynamic result = WeixinMP.GetSessionByCode(jscode);
                if (result != null && (ComFunc.nvl(result.errcode) == "" || result.errcode == 0))
                {
                    id = result.openid;
                    weixin_union_id      = result.unionid;
                    weixinmp_session_key = result.session_key;
                }
                else
                {
                    id = "";
                }
            }

            var s = from t in DB.LamdaTable(up, "user_info", "a")
                    join t2 in DB.LamdaTable(up, "Auth_Code", "b").LeftJoin() on t.userid equals t2.AuthKey
                    where t.userid == id || t.WeixinID == id || t.PlatformID == id || t.Mobile == id || t.QQ == id || t.WeixinMPID == id || t.WeixinPlatUnionID == id
                    select new
            {
                t.UserID,
                t.LoginPass,
                t.UserName,
                t.UserSex,
                t.WeixinID,
                t.WeixinMPID,
                t.WeixinPlatUnionID,
                t.HeadImgUrl,
                t.PlatformID,
                t2.AuthCode,
                t2.ValidSeconds,
                t2.StartTime,
                t2.IsUsed
            };

            BeginTrans();
            lock (lockobj)
            {
                var list = s.GetQueryList(up);
                if (login_mode == "MP")
                {
                    if (list.Count <= 0 && id != "")
                    {
                        var new_userid = NewUserID(up);;

                        DB.QuickInsert(up, "user_info", new
                        {
                            userid            = new_userid,
                            WeixinMPID        = id,
                            WeixinPlatUnionID = weixin_union_id,
                            add_id            = new_userid,
                            add_ip            = ClientInfo.IP,
                            add_name          = "",
                            add_time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            last_id           = new_userid,
                            last_ip           = ClientInfo.IP,
                            last_name         = "",
                            last_time         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                        });


                        list = s.GetQueryList(up);
                    }
                }

                if (list.Count != 1)
                {
                    return(false);
                }
                dynamic logininfo = list.First();

                var is_valid = false;
                if (login_mode == "Password" && logininfo.loginpass == pw)
                {
                    is_valid = true;
                }
                if (login_mode == "AuthCode")
                {
                    DateTime start_time    = DateTimeStd.ParseStd(logininfo.StartTime).Value;
                    int      valid_seconds = IntStd.IsNotIntThen(logininfo.ValidSeconds, 30);
                    if (start_time.AddSeconds(valid_seconds).CompareTo(DateTime.Now) >= 0 && pw == ComFunc.nvl(logininfo.AuthCode))
                    {
                        is_valid = true;
                    }
                }
                if (login_mode == "OpenID" && logininfo.WeixinID == id)
                {
                    is_valid = true;
                }
                if (login_mode == "MP" && logininfo.WeixinMPID == id)
                {
                    DB.QuickDelete(up, "WeixinMP_SessionKey", new
                    {
                        UserID = logininfo.UserID
                    });
                    DB.QuickInsert(up, "WeixinMP_SessionKey", new
                    {
                        UserID     = logininfo.UserID,
                        SessionKey = weixinmp_session_key,
                        add_id     = logininfo.UserID,
                        add_ip     = ClientInfo.IP,
                        add_name   = "",
                        add_time   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        last_id    = logininfo.UserID,
                        last_ip    = ClientInfo.IP,
                        last_name  = "",
                        last_time  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                    });

                    is_valid = true;
                }

                if (!is_valid)
                {
                    if (login_mode != "MP")
                    {
                        DB.QuickUpdate(up, "user_info", new
                        {
                            ErrorTime     = IntStd.IsNotIntThen(logininfo.ErrorTime) + 1,
                            LastLoginDate = DateTime.Now,
                            LastLoginIP   = ClientInfo.IP
                        }, new { UserID = logininfo.UserID });
                    }

                    return(false);
                }

                DB.QuickUpdate(up, "user_info", new
                {
                    ErrorTime     = 0,
                    LastLoginDate = DateTime.Now,
                    LastLoginIP   = ClientInfo.IP
                }, new { UserID = logininfo.UserID });
                var private_info = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
                private_info.weixin_id       = logininfo.weixinid;
                private_info.weixinmp_id     = logininfo.WeixinMPID;
                private_info.weixin_union_id = logininfo.WeixinPlatUnionID;
                private_info.platform_id     = logininfo.PlatformID;
                //登录者的唯一编码
                SetClaimSaveParameter("user_id", logininfo.userid);
                SetClaimSaveParameter("sex", logininfo.UserSex);
                SetClaimSaveParameter("username", ComFunc.UrlEncode(logininfo.UserName));
                SetClaimSaveParameter("p_info", EncryptByPublicKey(((FrameDLRObject)private_info).ToJSONString(true)));
            }
            CommitTrans();
            return(true);
        }
        /// <summary>
        /// 獲得一個webrequest的實例
        /// </summary>
        /// <returns></returns>
        protected HttpWebRequest GetRequestInstance(HttpParameter hp, ResponseObject hd)
        {
            var handler = new HttpClientHandler();

            HttpWebRequest hr           = (HttpWebRequest)WebRequest.Create(new Uri(hp.ToUrl));
            string         cookieheader = "";

            if (hr.CookieContainer != null)
            {
                cookieheader = hr.CookieContainer.GetCookieHeader(new Uri(hp.ToUrl));
            }

            CookieContainer cookieCon = new CookieContainer();

            hr.CookieContainer = cookieCon;
            hr.CookieContainer.SetCookies(new Uri(hp.ToUrl), cookieheader);
            hr.Method = hp.RequestMethod;
            hr.Proxy  = hp.HttpWebProxy;
            //if (_cert != null)
            //{
            //    hr.ClientCertificates.Add(_cert);
            //}
            //添加header
            foreach (var k in hp.Header.Keys)
            {
                if (k.ToLower() == "date")
                {
                    hr.Headers["Date"] = DateTimeStd.IsDateTime(hp.Header.GetValue(k)) ? DateTimeStd.ParseStd(ComFunc.nvl(hp.Header.GetValue(k))).Value.ToUniversalTime().ToString("r") : DateTime.Now.ToString("r");
                }
                else if (k.ToLower() == "content-length")
                {
                    hr.Headers["Content-Length"] = ComFunc.nvl(hp.Header.GetValue(k));
                }
                else if (k.ToLower() == "user-agent")
                {
                    hr.Headers["User-Agent"] = ComFunc.nvl(hp.Header.GetValue(k));
                }
                else
                {
                    hr.Headers[k] = ComFunc.nvl(hp.Header.GetValue(k));
                }
            }


            return(hr);
        }
Esempio n. 18
0
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string   postbackstr = postCollection[base.UniqueID];
            DateTime d           = string.IsNullOrEmpty(postbackstr) ? DateTime.MinValue : DateTimeStd.ParseStd(postbackstr).Value;

            this.SelectedDate = d;
            if (d.CompareTo(PreDateTime) == 0)
            {
                IsTextChanged = false;
                return(false);
            }
            else
            {
                IsTextChanged = true;
                return(true);
            }
        }