예제 #1
0
        /// <summary>
        /// </summary>
        public ArrayList GetPropertiesToSQLParms(SQLAction action)
        {
            bool includeInParamsList;

            PropertyInfo[] properties = this.GetType().GetProperties();
            ArrayList      procParms  = new ArrayList();

            for (int i = 0; i < properties.Length; i++)
            {
                includeInParamsList = true;
                object[] attrs = properties[i].GetCustomAttributes(false);
                foreach (SQLParamAttribute a in attrs)
                {
                    if (action == SQLAction.INSERT)
                    {
                        includeInParamsList = a.insertParm;
                    }
                    else
                    {
                        includeInParamsList = a.updateParm;
                    }
                }

                // Create a sql parameter for all public properties
                if (properties[i].MemberType == MemberTypes.Property && includeInParamsList)
                {
                    procParms.Add(new SqlParameter(properties[i].Name, properties[i].GetValue(this, null)));
                }
            }
            return(procParms);
        }
예제 #2
0
        internal void AddCity(string queryText)
        {
            var task = ThreadPool.RunAsync((work) =>
            {
                lock (lockable)
                {
                    newlist    = null;
                    var list   = SQLAction.GetAll();
                    var result = list.Find((x) =>
                    {
                        return(x.CountryCode == "CN" ? x.CityZh.Equals(queryText, StringComparison.OrdinalIgnoreCase) : x.CityEn.Equals(queryText, StringComparison.OrdinalIgnoreCase));
                    });
                    if (result != null)
                    {
                        if (Array.Exists(Cities.SavedCities, x =>
                        {
                            return(x.Id == result.Id);
                        }))
                        {
                            return;
                        }
                        else
                        {
                            newlist = new List <CitySettingsModel>();
                            newlist.AddRange(Cities.SavedCities);
                            newlist.Add(new CitySettingsModel(result));
                            Cities.Save(newlist.ToArray());
                        }
                    }
                }
            });

            task.Completed = new AsyncActionCompletedHandler(AddCityComplete);
        }
        public ActionResult Redirect()
        {
            // Get parameters from browser, store as variables
            NameValueCollection incomingQuery = Request.QueryString;

            if (incomingQuery.HasKeys())
            {
                string clientid = incomingQuery["clientid"];
                string id       = incomingQuery["id"];
                string ts       = incomingQuery["ts"];
                string slotId   = incomingQuery["slotId"];
                string q        = incomingQuery["q"];
                string u        = incomingQuery["u"];
                string ty       = incomingQuery["ty"];

                // Query ClientDB, obtain URL
                Dictionary <string, string> ParamsList = new Dictionary <string, string>();
                ParamsList.Add("clientid", clientid);

                string clientURL = SQLAction.GetURL(ParamsList);

                // Substitute values
                StringBuilder substitute = new StringBuilder(clientURL);
                substitute.Replace("!!clientid!!", clientid);
                substitute.Replace("!!id!!", id);
                substitute.Replace("!!ts!!", ts);
                substitute.Replace("!!slotId!!", slotId);
                substitute.Replace("!!q!!", q);
                substitute.Replace("!!u!!", u);
                substitute.Replace("!!ty!!", ty);
                clientURL = substitute.ToString();

                // Send redirect to browser
                Response.StatusCode = 302;
                Response.Status     = "302 Moved Temporarily";
                if (String.IsNullOrEmpty(clientURL))
                {
                    return(HttpNotFound("ClientID doesn't exist in database."));
                }
                else
                {
                    return(Redirect(clientURL));
                }
            }

            //Return 404 if no variables found
            return(HttpNotFound("The URL has no parameters.  Maybe you should enter some."));
        }
예제 #4
0
        public void DoWork(SQLAction sqlAction)
        {
            int WaitSleepTime = 1;

            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.InfoMessage += (sender, e) => { Console.WriteLine($"warning or info {e.Message}"); };

                connection.StateChange += (sender, e) => { Console.WriteLine($"DBconnectionStatus: {e.OriginalState} --> {e.CurrentState}"); };


                for (int i = 0; i < 100; i++)
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        isOKOpen   = false;
                        datasource = "None";
                        System.Threading.Thread.Sleep(WaitSleepTime);
                        connection.Open();
                    }
                    else
                    {
                        isOKOpen   = true;
                        datasource = connection.DataSource;
                        break;
                    }
                }

                switch (sqlAction)
                {
                case SQLAction.InsertRow:
                    InsertRowToDB(connection);
                    break;

                case SQLAction.GetRowCnt:
                    GetDBRowCount(connection);
                    break;

                case SQLAction.Nothing:
                    break;

                default:
                    break;
                }
            }
        }
예제 #5
0
        public void load()
        {
            lb_TenMon.ForeColor  = Color.Black;
            lb_GiaTien.ForeColor = Color.Black;
            lb_MoTa.ForeColor    = Color.Black;
            lb_DanhMuc.ForeColor = Color.Black;
            txtTenMon.ResetText();
            txtMoTa.ResetText();
            txtGiaTien.ResetText();
            SQLAction LayDanhMuc = new SQLAction();
            DataSet   table      = LayDanhMuc.GetCategory();

            for (int i = 0; i < table.Tables[0].Rows.Count; i++)
            {
                cbb_DanhMuc.Items.Add(table.Tables[0].Rows[i][0].ToString());
            }
        }
예제 #6
0
파일: Location.cs 프로젝트: soiOL/hello
        public static City GetNearsetLocation(Location source)
        {
            var   list = SQLAction.GetAll();
            float dis  = float.MaxValue;
            City  fi   = null;

            foreach (var item in list)
            {
                var cal = CalcDistance(item.Latitude, item.Longitude, source);
                if (dis > cal)
                {
                    dis = cal;
                    fi  = item;
                }
            }
            return(fi);
        }
예제 #7
0
        internal List <City> Search_TextChanged(string text)
        {
            var           searcharray = text.Split(' ');
            StringBuilder searchsb    = new StringBuilder(@".*");

            foreach (var search in searcharray)
            {
                searchsb.Append(search);
                searchsb.Append(@".*");
            }
            var pattern = searchsb.ToString();
            var list    = SQLAction.GetAll();

            return(list.FindAll((x) =>
            {
                return x.CountryCode == "CN" ? (Regex.IsMatch(x.CityZh, pattern, RegexOptions.IgnoreCase) || Regex.IsMatch(x.CityEn, pattern, RegexOptions.IgnoreCase)) : Regex.IsMatch(x.CityEn, pattern, RegexOptions.IgnoreCase);
            }));
        }
예제 #8
0
        private void load()
        {
            SQLAction laydanhmuc = new SQLAction();
            DataSet   table      = laydanhmuc.GetCategory();


            if (table.Tables[0].Rows.Count > 0 && table.Tables.Count > 0)
            {
                for (int i = 0; i < table.Tables[0].Rows.Count; i++)
                {
                    Button button = new Button();
                    button.Size = new Size(80, 50);
                    button.Text = table.Tables[0].Rows[i][0].ToString();
                    pl_Chon.Controls.Add(button);
                    string DM = table.Tables[0].Rows[i][0].ToString();

                    button.Click += (sender, args) =>
                    {
                        pl_Menu.Controls.Clear();
                        FlowLayoutPanel pl = new FlowLayoutPanel();
                        pl.Size = new Size(400, 430);

                        DTO_Food food = new DTO_Food();
                        food.DanhMuc = button.Text;
                        SQLAction getfood = new SQLAction();
                        DataSet   result  = new DataSet();
                        result = getfood.GetFoodInfo(food);
                        for (int k = 0; k < result.Tables[0].Rows.Count; k++)
                        {
                            ChooseFood choose = new ChooseFood();
                            choose.TENMON  = result.Tables[0].Rows[k][1].ToString();
                            choose.GIATIEN = int.Parse(result.Tables[0].Rows[k][3].ToString());
                            System.Byte[] arr = (result.Tables[0].Rows[k][4]) as System.Byte[];
                            choose.HINHANH = arr;
                            pl.Controls.Add(choose);
                        }
                        pl_Menu.Controls.Add(pl);
                    };
                }
            }
        }
예제 #9
0
파일: Program.cs 프로젝트: terius/GongBei
        /// <summary>
        /// 初始化
        /// </summary>
        static void Init()
        {
            Console.WriteLine("系统开始初始化....");
            CheckPath();
            sqlAction            = new SQLAction();
            client               = new SocketClient();
            client.OnReceiveData = (res) =>
            {
                switch (res.ReceiveDataType)
                {
                case Infrastructure.ReceiveDataType.None:
                    break;

                case Infrastructure.ReceiveDataType.ctHeartBeatResponse:
                    client.RestartTime();
                    break;

                case Infrastructure.ReceiveDataType.ctBarcodeMessage:
                    break;

                case Infrastructure.ReceiveDataType.ctConclusionResult:
                    SavectConclusionResult(res);
                    break;

                case Infrastructure.ReceiveDataType.ctDeviceStatus:
                    SavectDeviceStatus(res);
                    break;

                default:
                    break;
                }
                Console.WriteLine("获取到返回信息:" + res.ReceiveDataType.ToString());
                FileHelper.WriteLog(res.DataStr, "收到数据");
            };
            client.Start();
        }
예제 #10
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            DTO_Login account = new DTO_Login();

            account.UserName = txtUserName.Text;
            account.PassWord = txtPassword.Text;
            SQLAction action = new SQLAction();
            DataSet   result = action.Login(account);

            if (result.Tables.Count > 0 && result.Tables[0].Rows.Count > 0)
            {
                MessageBox.Show("Đăng nhập thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MenuForm menu = new MenuForm();
                this.Hide();
                menu.USERNAME = result.Tables[0].Rows[0][0].ToString();
                menu.ShowDialog();
                this.Close();
            }
            else
            {
                MessageBox.Show("Tên tài khoản hoặc mật khẩu không đúng!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                load();
            }
        }
예제 #11
0
        private async void DismissedEventHandler(SplashScreen sender, object args)
        {
            dismissed = true;
            await SQLAction.CheckDB();

            SetLongTimeTimer();
            var settings = SettingsModel.Current;
            var license  = new License.License();

            if (!license.IsPurchased)
            {
                settings.Preferences.EnableAlarm   = false;
                settings.Preferences.EnableEvening = false;
                settings.Preferences.EnableMorning = false;
                settings.Preferences.Set(240);
            }

            if (settings.Preferences.MainColor.A > 0)
            {
                App.MainColor = settings.Preferences.MainColor;
                await Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() =>
                {
                    App.ChangeThemeColor(settings.Preferences.MainColor);
                    ChangeThemeColor(settings.Preferences.MainColor);
                }));
            }
            if (!settings.Inited)
            {
                NavigatetoStart();
                return;
            }
            if (!this.args.IsNullorEmpty())
            {
                settings.Cities.ChangeCurrent(this.args);
            }
            try
            {
                if (settings.Cities.GetCurrentCity() == null)
                {
                    NavigatetoStart();
                    return;
                }
            }
            catch (Exception)
            {
            }

            if (settings.Cities.CurrentIndex == -1 && settings.Cities.EnableLocate)
            {
                try
                {
                    var accessStatus = await Geolocator.RequestAccessAsync();

                    if (accessStatus == GeolocationAccessStatus.Allowed)
                    {
                        await Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(async() =>
                        {
                            var l = new ResourceLoader();
                            SplashWelcome.Text = l.GetString("Locating");
                            try
                            {
                                var _geolocator = new Geolocator();
                                var pos = await _geolocator.GetGeopositionAsync();
                                if ((_geolocator.LocationStatus != PositionStatus.NoData) && (_geolocator.LocationStatus != PositionStatus.NotAvailable) && (_geolocator.LocationStatus != PositionStatus.Disabled))
                                {
                                    var t = ThreadPool.RunAsync(async(w) =>
                                    {
                                        await CalcPosition(pos, settings);
                                        GetCityListandCompelte(settings);
                                    });
                                }
                                else
                                {
                                    GetCityListandCompelte(settings);
                                }
                            }
                            catch (Exception)
                            {
                                GetCityListandCompelte(settings);
                            }
                        }));
                    }
                    else
                    {
                        if (!settings.Cities.SavedCities.IsNullorEmpty())
                        {
                            settings.Cities.CurrentIndex = 0;
                        }
                        else
                        {
                            GetCityListandCompelte(settings);
                        }
                    }
                }
                catch (Exception)
                {
                    NavigatetoStart();
                }
            }
            else if (settings.Cities.CurrentIndex >= 0 && !settings.Cities.SavedCities.IsNullorEmpty())
            {
                foreach (var citty in settings.Cities.SavedCities)
                {
                    if (citty.Latitude == 0 && citty.Longitude == 0)
                    {
                        var tar = SQLAction.Find(citty.Id);
                        citty.Latitude  = tar.Latitude;
                        citty.Longitude = tar.Longitude;
                    }
                }
                settings.Cities.Save();
                GetCityListandCompelte(settings);
            }
            else
            {
                NavigatetoStart();
                return;
            }
        }
예제 #12
0
        public async Task GetLocation(double lat, double lon)
        {
            City final = null;

            switch (args)
            {
            case LocateRoute.unknown:
                var near = Models.Location.GetNearsetLocation(new Models.Location((float)lat, (float)lon));
                final = near;
                break;

            case LocateRoute.Amap:
                var acontract = await Models.Location.AmapReGeoAsync(lat, lon);

                if (acontract != null)
                {
                    var li = new City
                    {
                        CityEn      = acontract.regeocode.addressComponent.district,
                        CityZh      = acontract.regeocode.addressComponent.district,
                        LeaderEn    = acontract.regeocode.addressComponent.city,
                        LeaderZh    = acontract.regeocode.addressComponent.city,
                        CountryCode = "CN",
                        CountryEn   = acontract.regeocode.addressComponent.country,
                        //Id = await Models.Location.HeWeatherGeoLookup(acontract.regeocode.addressComponent.district),
                        Latitude   = (float)lat,
                        Longitude  = (float)lon,
                        ProvinceEn = acontract.regeocode.addressComponent.province,
                        ProvinceZh = acontract.regeocode.addressComponent.province
                    };
                    final = li;
                }
                break;

            case LocateRoute.Omap:
                var ocontract = await Models.Location.OpenMapReGeoAsync(lat, lon);

                if (ocontract != null && !ocontract.results.IsNullorEmpty())
                {
                    var li = new City
                    {
                        CityEn      = ocontract.results[0].components.county,
                        CityZh      = ocontract.results[0].components.county,
                        LeaderEn    = ocontract.results[0].components.region,
                        LeaderZh    = ocontract.results[0].components.region,
                        CountryCode = ocontract.results[0].components.country_code,
                        CountryEn   = ocontract.results[0].components.country,
                        //Id = await Models.Location.HeWeatherGeoLookup(ocontract.results[0].components.county),
                        Latitude   = (float)lat,
                        Longitude  = (float)lon,
                        ProvinceEn = ocontract.results[0].components.state,
                        ProvinceZh = ocontract.results[0].components.state
                    };
                    final = li;
                }
                break;

            case LocateRoute.IP:
                var id = await Models.Location.ReGeobyIpAsync();

                if (id != null)
                {
                    var f = SQLAction.Find(id.CityId);
                    if (f != null)
                    {
                        final = f;
                    }
                }
                break;

            case LocateRoute.Gmap:
                throw new NotImplementedException("Google map api not implement");
            }

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() =>
            {
                if (final == null)
                {
                    City = new City
                    {
                        CityEn = "定位失败",
                        Latitude = (float)lat,
                        Longitude = (float)lon,
                        CountryCode = "",
                        Id = "",
                    };
                    return;
                }
                City = final;
                Location = new Models.Location(City.Latitude, City.Longitude);
            }));
        }
예제 #13
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtMaMon.Text))
     {
         lb_MaMon.ForeColor = Color.Red;
     }
     else
     {
         lb_MaMon.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(txtTenMon.Text))
     {
         lb_TenMon.ForeColor = Color.Red;
     }
     else
     {
         lb_TenMon.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(txtMoTa.Text))
     {
         lb_MoTa.ForeColor = Color.Red;
     }
     else
     {
         lb_MoTa.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(txtGiaTien.Text))
     {
         lb_GiaTien.ForeColor = Color.Red;
     }
     else
     {
         lb_GiaTien.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(cbb_DanhMuc.Text))
     {
         lb_DanhMuc.ForeColor = Color.Red;
     }
     else
     {
         lb_DanhMuc.ForeColor = Color.Black;
     }
     if (lb_MaMon.ForeColor == Color.Black && lb_DanhMuc.ForeColor == Color.Black && lb_MoTa.ForeColor == Color.Black && lb_GiaTien.ForeColor == Color.Black && lb_TenMon.ForeColor == Color.Black)
     {
         DTO_Food addfood = new DTO_Food();
         addfood.MaMon   = txtMaMon.Text;
         addfood.TenMon  = txtTenMon.Text;
         addfood.DanhMuc = cbb_DanhMuc.Text;
         addfood.MoTa    = txtMoTa.Text;
         addfood.GiaTien = (int)double.Parse(txtGiaTien.Text);
         //xử lí hình ảnh
         Image        img    = Image.FromFile(file);
         MemoryStream stream = new MemoryStream();
         img.Save(stream, ImageFormat.Jpeg);
         stream.Seek(0, SeekOrigin.Begin);
         byte[] imgByte = System.IO.File.ReadAllBytes(file);
         int    sizeImg = imgByte.Length;
         stream.Read(imgByte, 0, sizeImg);
         addfood.HinhAnh = imgByte;
         SQLAction add = new SQLAction();
         if (add.AddFood(addfood) != -1)
         {
             MessageBox.Show("Thêm món thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("Thất Bại, vui lòng thử lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Điền thiếu thông tin, vui lòng kiểm tra lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #14
0
파일: Location.cs 프로젝트: soiOL/hello
        public async static Task <City> ReverseGeoCode(float lat, float lon, LocateRoute[] routes)
        {
            City final = null;

            foreach (var r in routes)
            {
                switch (r)
                {
                case LocateRoute.unknown:
                    var near = GetNearsetLocation(new Location(lat, lon));
                    final = near;
                    break;

                case LocateRoute.Amap:
                    var acontract = await AmapReGeoAsync(lat, lon);

                    if (acontract != null)
                    {
                        var li = new City
                        {
                            CityEn      = acontract.regeocode.addressComponent.district,
                            CityZh      = acontract.regeocode.addressComponent.district,
                            LeaderEn    = acontract.regeocode.addressComponent.city,
                            LeaderZh    = acontract.regeocode.addressComponent.city,
                            CountryCode = "CN",
                            CountryEn   = acontract.regeocode.addressComponent.country,
                            //Id = await Models.Location.HeWeatherGeoLookup(acontract.regeocode.addressComponent.district),
                            Latitude   = (float)lat,
                            Longitude  = (float)lon,
                            ProvinceEn = acontract.regeocode.addressComponent.province,
                            ProvinceZh = acontract.regeocode.addressComponent.province
                        };
                        final = li;
                    }
                    break;

                case LocateRoute.Omap:
                    var ocontract = await OpenMapReGeoAsync(lat, lon);

                    if (ocontract != null && !ocontract.results.IsNullorEmpty())
                    {
                        var li = new City
                        {
                            CityEn      = ocontract.results[0].components.county,
                            CityZh      = ocontract.results[0].components.county,
                            LeaderEn    = ocontract.results[0].components.region,
                            LeaderZh    = ocontract.results[0].components.region,
                            CountryCode = ocontract.results[0].components.country_code,
                            CountryEn   = ocontract.results[0].components.country,
                            //Id = await HeWeatherGeoLookup(ocontract.results[0].components.county),
                            Latitude   = lat,
                            Longitude  = lon,
                            ProvinceEn = ocontract.results[0].components.state,
                            ProvinceZh = ocontract.results[0].components.state
                        };
                        final = li;
                    }
                    break;

                case LocateRoute.IP:
                    var id = await ReGeobyIpAsync();

                    if (id != null)
                    {
                        final = SQLAction.Find(id.CityId);
                    }
                    break;

                case LocateRoute.Gmap:

                    break;

                default:
                    break;
                }
                if (final != null)
                {
                    break;
                }
            }

            if (final != null)
            {
                return(final);
            }
            else
            {
                throw new Exception("Locate Failed.");
            }
        }