Example #1
0
        public void OnLogined(sys_user user)
        {
            // 记录登录日志
            using (var db = new SysContext())
            {
                var    hostIp     = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                string clientName = null;
                try
                {
                    System.Net.IPAddress   address = System.Net.IPAddress.Parse(hostIp);
                    System.Net.IPHostEntry ipInfor = System.Net.Dns.GetHostEntry(address);
                    clientName = ipInfor.HostName;
                }
                catch { }
                db.sys_loginHistory.Add(new sys_loginHistory
                {
                    UserCode  = user.UserCode,
                    UserName  = user.UserName,
                    HostIP    = hostIp,
                    HostName  = clientName,
                    LoginDate = DateTime.Now
                });
                db.SaveChanges();
            }

            // 执行 Session 初始化
            Dictionary <string, OneConnection> openConnections = new Dictionary <string, OneConnection>();

            foreach (var s in SysSessions)
            {
                try
                {
                    // 准备连接
                    var           connName = string.IsNullOrEmpty(s.Connection) ? DefaultConnection.Name : s.Connection;
                    OneConnection conn     = null;
                    if (openConnections.ContainsKey(connName))
                    {
                        conn = openConnections[connName];
                    }
                    else
                    {
                        conn = openConnections[connName] = CreateOneConnection(connName);
                    }

                    if (!string.IsNullOrEmpty(s.Condition))
                    {
                        // 进行条件测试
                        object val = conn.ExecuteScalar(FruitExpression.Replace(s.Condition));
                        if (val is bool && (bool)val == false)
                        {
                            continue;
                        }
                    }

                    if (!string.IsNullOrEmpty(s.T_SQL))
                    {
                        // 运行查询
                        object val = conn.ExecuteScalar(FruitExpression.Replace(s.T_SQL));
                        if (val != DBNull.Value && val != null)
                        {
                            HttpContext.Current.Session[s.SessionName] = val.ToString();
                            continue;
                        }
                    }

                    if (!string.IsNullOrEmpty(s.DefaultValue))
                    {
                        // 默认值
                        HttpContext.Current.Session[s.SessionName] = FruitExpression.Replace(s.DefaultValue);
                    }
                }
                catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e);
                }
            }
            // 关闭所有打开过的连接
            foreach (var conn in openConnections.Values)
            {
                conn.Dispose();
            }
        }
Example #2
0
        public static MGraph gMileageConnection; // 用于计算里程

        /// <summary>
        /// 由数据库或远程服务器读入三维中线的数据,这儿无效,在工具中使用,
        /// </summary>
        /// <param name="fileName"></param>
        //public static void CreateLinelistFromExcel(string dbPath)
        //{
        //    double[] m, x, y, z;
        //    double fromMeter, toMeter;
        //    //double fromX, toX, fromY, toY;
        //    int chainIndex;
        //    int chainType;
        //    string dkcode, dkcode2;
        //    //bool isRight = false;
        //    //bool isDouble = true;
        //    int count;

        //    DataTable dt1, dt2, dt3;

        //    //本地sqlite数据库读取里程数据
        //    //#if DEBUG
        //    //            Helper.LogHelper.WriteLog("SQlite Database" + dbPath);
        //    //#endif

        //    dt1 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select chainIndex, fromMeter, toMeter,DKCode,DKCode2,chainType from [ChainInfo$] order by chainIndex");
        //    dt2 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select fromChain, toChain from [ExtraConnection$] ");
        //    List<OneConnection> connectionList = new List<OneConnection>();
        //    foreach (DataRow dr in dt2.Rows)
        //    {
        //        OneConnection aCon = new OneConnection();
        //        aCon.fromIndex = Convert.ToInt32(dr["fromChain"]);
        //        aCon.toIndex = Convert.ToInt32(dr["toChain"]);
        //        //aCon.isRealConnect = Convert.ToInt32(dr["isConnect"])==0 ? true:false;
        //        //aCon.mileageOffset = Convert.ToDouble(dr["mileageOffset"]);
        //        connectionList.Add(aCon);
        //    }
        //    //int index = 0;

        //    foreach (DataRow dr in dt1.Rows)
        //    {
        //        chainIndex = Convert.ToInt32(dr["chainIndex"]);
        //        fromMeter = Convert.ToDouble(dr["fromMeter"]);
        //        toMeter = Convert.ToDouble(dr["toMeter"]);
        //        dkcode = (string)dr["DKCode"];
        //        dkcode2 = dr["DKCode2"].ToString();
        //        chainType = Convert.ToInt32(dr["chainType"]);
        //        //  isReverse = Convert.ToBoolean(dr["IsReverse"]);
        //        string strOrder = (fromMeter < toMeter) ? "" : " desc ";
        //        string tableName = "sheet" + chainIndex;
        //        dt3 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select Mileage, Longitude,Latitude,Altitude from [" + tableName + "$] order by mileage " + strOrder);
        //        count = dt3.Rows.Count;
        //        if (count < 2) continue;

        //        m = new double[count];
        //        x = new double[count];
        //        y = new double[count];
        //        z = new double[count];
        //        //xMars = new double[count];
        //        //yMars = new double[count];
        //        int j = 0;
        //        foreach (DataRow dr2 in dt3.Rows)
        //        {

        //            m[j] = Math.Abs(Convert.ToDouble(dr2["Mileage"]) - fromMeter);
        //            x[j] = Convert.ToDouble(dr2["Longitude"]);
        //            y[j] = Convert.ToDouble(dr2["Latitude"]);
        //            z[j] = Convert.ToDouble(dr2["Altitude"]);
        //            j++;
        //            //xMars[j] = Convert.ToDouble(dr2["LongitudeMars"]);
        //            //yMars[j] = Convert.ToDouble(dr2["LatitudeMars"]);
        //        }
        //        mLineList.Add(new CRailwayLine(chainIndex, dkcode, dkcode2, fromMeter, toMeter, chainType, count, m, x, y, z));
        //    }


        //    gRealConnection = new MGraph();
        //    gMileageConnection = new MGraph();

        //    ShortestPathFloyd.initPathGraph(mLineList, gRealConnection, null);
        //    ShortestPathFloyd.initPathGraph(mLineList, gMileageConnection, connectionList);
        //}

        /// <summary>
        /// 由数据库或远程服务器读入三维中线的数据
        /// </summary>
        /// <param name="fileName"></param>
        public static void CreateLinelistFromSqlite(string dbPath)
        {
            double[] m, x, y, z;
            double   fromMeter, toMeter;
            //double fromX, toX, fromY, toY;
            int    chainIndex;
            int    chainType;
            string dkcode, dkcode2;
            //bool isRight = false;
            //bool isDouble = true;
            int count;

            DataTable dt1, dt2, dt3;

            //本地sqlite数据库读取里程数据
            //#if DEBUG
            //            Helper.LogHelper.WriteLog("SQlite Database" + dbPath);
            //#endif

            dt1 = DatabaseWrapper.ExecuteDataTable(dbPath, @"select chainIndex, fromMeter, toMeter,DKCode,DKCode2,chainType from ChainInfo order by chainIndex; ");
            dt2 = DatabaseWrapper.ExecuteDataTable(dbPath, @"select fromChain, toChain from ExtraConnection; ");

            //dt1 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select chainIndex, fromMeter, toMeter,DKCode,DKCode2,chainType from [ChainInfo$] order by chainIndex");
            //dt2 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select fromChain, toChain from [ExtraConnection$] ");
            List <OneConnection> connectionList = new List <OneConnection>();

            foreach (DataRow dr in dt2.Rows)
            {
                OneConnection aCon = new OneConnection();
                aCon.fromIndex = Convert.ToInt32(dr["fromChain"]);
                aCon.toIndex   = Convert.ToInt32(dr["toChain"]);
                //aCon.isRealConnect = Convert.ToInt32(dr["isConnect"])==0 ? true:false;
                //aCon.mileageOffset = Convert.ToDouble(dr["mileageOffset"]);
                connectionList.Add(aCon);
            }
            //int index = 0;

            foreach (DataRow dr in dt1.Rows)
            {
                chainIndex = Convert.ToInt32(dr["chainIndex"]);
                fromMeter  = Convert.ToDouble(dr["fromMeter"]);
                toMeter    = Convert.ToDouble(dr["toMeter"]);
                dkcode     = (string)dr["DKCode"];
                if (dr["DKCode2"] == null)
                {
                    dkcode2 = "";
                }
                else
                {
                    dkcode2 = dr["DKCode2"].ToString();
                }
                chainType = Convert.ToInt32(dr["chainType"]);
                //  isReverse = Convert.ToBoolean(dr["IsReverse"]);
                string strOrder = (fromMeter < toMeter) ? "" : " desc ";
                //string tableName = "sheet" + chainIndex;
                dt3   = DatabaseWrapper.ExecuteDataTable(dbPath, @"select Mileage, Longitude,Latitude,Altitude from MileageInfo where MileagePrefix=" + chainIndex + "  order by mileage " + strOrder);
                count = dt3.Rows.Count;
                if (count < 2)
                {
                    continue;
                }

                m = new double[count];
                x = new double[count];
                y = new double[count];
                z = new double[count];
                //xMars = new double[count];
                //yMars = new double[count];
                int j = 0;
                foreach (DataRow dr2 in dt3.Rows)
                {
                    m[j] = Math.Abs(Convert.ToDouble(dr2["Mileage"]) - fromMeter);
                    x[j] = Convert.ToDouble(dr2["Longitude"]);
                    y[j] = Convert.ToDouble(dr2["Latitude"]);
                    z[j] = Convert.ToDouble(dr2["Altitude"]);
                    j++;
                    //xMars[j] = Convert.ToDouble(dr2["LongitudeMars"]);
                    //yMars[j] = Convert.ToDouble(dr2["LatitudeMars"]);
                }
                mLineList.Add(new CRailwayLine(chainIndex, dkcode, dkcode2, fromMeter, toMeter, chainType, count, m, x, y, z));
            }

            gRealConnection    = new MGraph();
            gMileageConnection = new MGraph();

            ShortestPathFloyd.initPathGraph(mLineList, gRealConnection, null);
            ShortestPathFloyd.initPathGraph(mLineList, gMileageConnection, connectionList);
        }