Ejemplo n.º 1
0
        private CustomObject GetMainFormulaObject(DP_DataRepository mainDataItem)
        {
            CustomObject formulaObject = new CustomObject();

            if (!mainDataItem.IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue(mainDataItem) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues(mainDataItem))
            {
                SearchRequestManager searchProcessor = new SearchRequestManager();
                DP_SearchRepository  searchDataItem  = new DP_SearchRepository(mainDataItem.TargetEntityID);
                foreach (var property in mainDataItem.GetProperties())
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }

                //سکوریتی داده اعمال میشود
                //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط
                DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(Requester, searchDataItem);
                var result = searchProcessor.Process(request);
                if (result.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    formulaObject.DataItem = result.ResultDataItems.FirstOrDefault(); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                }
                else if (result.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    throw (new Exception(result.Message));
                }
            }
            else
            {
                formulaObject.DataItem = mainDataItem;
            }
            return(formulaObject);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 今日App计时器 Key为AppName+AppPath, Value为今日剩余时间
        /// </summary>
        //public Dictionary<string, TimeSpan> AppTimers = new Dictionary<string, TimeSpan>();

        /// <summary>
        /// 获取今日小结,即为时间线内相同软件使用时间合并后的列表
        /// </summary>
        /// <returns>今日小结 - Dictionary<string, TimeSpan></returns>
        public Dictionary <string, Software> GetOverView()
        {
            List <MyTimeDuration>         myTimeDurations = new List <MyTimeDuration>(TimeLine.ToArray());
            Dictionary <string, Software> overView        = new Dictionary <string, Software>();

            foreach (MyTimeDuration item in myTimeDurations)
            {
                string nowAppName = item.TimeDurationTask.ApplicationName;
                if (string.IsNullOrEmpty(nowAppName) || nowAppName == "Frogy")
                {
                    continue;
                }

                TimeSpan duration = item.Duration;
                if (overView.ContainsKey(nowAppName))
                {
                    overView[nowAppName].Duration += duration;
                }

                else
                {
                    Software result =
                        new Software()
                    {
                        Duration = item.Duration,
                        Name     = nowAppName,
                        Icon     = MyDataHelper.BitmapToBitmapImage(
                            MyDataHelper.Base64StringToImage(item.TimeDurationTask.ApplicationIcon_Base64))
                    };
                    overView.Add(nowAppName, result);
                }
            }
            return(overView);
        }
Ejemplo n.º 3
0
        public void Save()
        {
            Saving = true;

            Directory.CreateDirectory(storagePath);

            string savePath = Path.Combine(storagePath, DateTime.Today.ToString("yyyyMMdd") + ".json");
            string tempPath = Path.Combine(storagePath, DateTime.Today.ToString("yyyyMMdd") + "temp.json");
            string content  = MyDataHelper.CoverObjectToJson(AllDays[DateTime.Today]);

            MyDataHelper.WriteFile(tempPath, content);
            MyDataHelper.RenameFile(tempPath, savePath);

            Saving = false;
        }
Ejemplo n.º 4
0
        private static DP_DataRepository GetMainDateItem(DR_Requester requester, DP_BaseData dataItem)
        {
            bool getDataItem = false;

            if (dataItem is DP_DataView)
            {
                getDataItem = true;
            }
            else
            {
                if (!(dataItem as DP_DataRepository).IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue((dataItem as DP_DataRepository)) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues((dataItem as DP_DataRepository)))
                {
                    getDataItem = true;
                }
            }

            if (getDataItem)
            {
                SearchRequestManager searchProcessor = new SearchRequestManager();
                DP_SearchRepository  searchDataItem  = new DP_SearchRepository(dataItem.TargetEntityID);
                foreach (var property in dataItem.KeyProperties)
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }

                //سکوریتی داده اعمال میشود
                //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط
                DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(requester, searchDataItem);
                var result = searchProcessor.Process(request);
                if (result.Result != Enum_DR_ResultType.ExceptionThrown)
                {
                    return(result.ResultDataItems.FirstOrDefault()); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                }
                else
                {
                    throw (new Exception(result.Message));
                }
            }
            else
            {
                return(dataItem as DP_DataRepository);
            }
        }
        public FormulaObject(DP_DataRepository dataItem, DR_Requester requester, bool isDefinitionFormulaObject = false)
        {
            Requester = requester;
            bool getFromDB = false;

            if (isDefinitionFormulaObject == false)
            {
                if (!dataItem.IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue(dataItem) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues(dataItem))
                {
                    getFromDB = true;
                }
            }
            if (getFromDB)
            {
                SearchRequestManager searchProcessor = new SearchRequestManager();
                DP_SearchRepository  searchDataItem  = new DP_SearchRepository(dataItem.TargetEntityID);
                foreach (var property in dataItem.GetProperties())
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }

                //سکوریتی داده اعمال میشود
                //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط
                DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(Requester, searchDataItem);
                var result = searchProcessor.Process(request);
                if (result.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    dataItem = result.ResultDataItems.FirstOrDefault(); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                }
                else if (result.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    throw (new Exception(result.Message));
                }
            }
            DataItem = dataItem;
            this.PropertyGetCalled   += FormulaObject_PropertyGetCalled;
            IsDefinitionFormulaObject = isDefinitionFormulaObject;

            var entity     = bizTableDrivedEntity.GetPermissionedEntity(Requester, DataItem.TargetEntityID);
            var properties = FormulaInstanceInternalHelper.GetProperties(entity, null, false, true);

            SetProperties(properties);
        }
        public double CalculateTotalBalance()
        {
            string sql = $"select coalesce(sum(balance), 0) from participant_event group by eventNr having eventNr = {myEvent.Id}; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public int GetNextVisitorNr()
        {
            string sql = "select coalesce(max(participantNr), 499) from participant"; // visitorNr starts from 499

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToInt32(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public int GetNextEmployeeNr()
        {
            string sql = "select coalesce(max(empNr), 199) from employee"; // EmpNr starts from 200

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToInt32(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public int GetNextLogFileId()
        {
            string sql = "select coalesce(max(logNr), 0) from atm_log_file"; // logNr starts from 1

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToInt32(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public int GetNextOrderNumber()
        {
            string sql = "select coalesce(max(orderNr), 99) from `order`"; // orderNr starts from 100

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToInt32(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public double CalculateRevenueFromAServicePoint(ServicePoint point)
        {
            string sql = $"select coalesce(sum(totalToPay), 0) from `order` group by shopId having shopId = {point.PointId}";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public int GetQuantitySoldOrTimesRented(EventItem item)
        {
            string sql = $"select coalesce(sum(quantity), 0) from order_line_item group by sku having sku = {item.Sku}; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToInt32(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public double CalculateRevenueFromVendingMachines()
        {
            string sql = $"select coalesce(sum(totalToPay), 0) from `order` join service_point on `order`.shopId = service_point.id group by type having type = 'vending_machine'; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public double CalculateTotalFine(Visitor v)
        {
            string sql = $"select coalesce(sum(paidFine), 0) from `returned_item` group by ticketNr having ticketNr = {v.TicketNr}; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public double CalculateTotalBuyingRenting(Visitor v)
        {
            string sql = $"select coalesce(sum(totalToPay), 0) from `order` group by ticketNr having ticketNr = {v.TicketNr}; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public double CalculateTotalTopUp()
        {
            string sql = $"select coalesce(sum(amount), 0) from transaction; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        public double CalculateRevenueFromFine()
        {
            string sql = $"select coalesce(sum(paidFine), 0) from returned_item; ";

            try
            {
                MyDataHelper.OpenConnection();
                return(Convert.ToDouble(myDataHelper.ExecuteScalar(sql)));
            }

            catch
            {
                return(-1);
            }

            finally
            {
                MyDataHelper.CloseConnection();
            }
        }
        private void AddShopIdForEmpLevel3()
        {
            string sql = "SELECT * FROM employee WHERE work_place = 'shop'";

            try
            {
                myDataHelper.OpenConnection();
                MySqlDataReader reader = MyDataHelper.DataReader(sql);
                while (reader.Read())
                {
                    ((Employee)myEvent.GetPersonById(Convert.ToInt32(reader["empNr"]))).ChangeShop(myEvent.GetShopById(Convert.ToInt32(reader["SERVICE_POINT_id"])));
                }
            }
            catch
            {
                return;
            }
            finally
            {
                myDataHelper.CloseConnection();
            }
        }
Ejemplo n.º 19
0
        public void Load(DateTime date)
        {
            if (!AllDays.ContainsKey(date))
            {
                string loadPath = Path.Combine(storagePath, date.ToString("yyyyMMdd") + ".json");
                if (File.Exists(loadPath))
                {
                    string json;
                    try
                    {
                        if (File.Exists(loadPath + ".bak"))
                        {
                            json = MyDataHelper.ReadFile(loadPath + ".bak");
                        }
                        else
                        {
                            json = MyDataHelper.ReadFile(loadPath);
                        }
                        AllDays.Add(date, JsonConvert.DeserializeObject <MyDay>(json));
                    }
                    catch (Newtonsoft.Json.JsonReaderException)
                    {
                        ((App)Application.Current).ShowNotification(
                            LanguageHelper.InquireLocalizedWord("TaskBar_AppName"),
                            LanguageHelper.InquireLocalizedWord("System_ExcptionBadData") + date.ToString("yyyy/MM/dd"),
                            BalloonIcon.Error);

                        File.Delete(loadPath);
                        AllDays.Add(date, new MyDay());
                    }
                }
                else
                {
                    AllDays.Add(date, new MyDay());
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 主逻辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainLogicLoop_Tick(object sender, EventArgs e)
        {
            TimeSpan now = new TimeSpan(
                DateTime.Now.Hour,
                DateTime.Now.Minute,
                DateTime.Now.Second);

            DateTime today = DateTime.Today;

            //运行时遇到日期变更,则增加新key
            if (!AllDays.ContainsKey(today))
            {
                AllDays.Add(today, new MyDay());
            }

            List <MyTimeDuration> todayTimeLine = AllDays[today].TimeLine;

            //如果设备状态不为1
            if (MyDeviceHelper.DeviceState != 1)
            {
                if (todayTimeLine.Count == 0 || todayTimeLine.Last().TimeDurationTask.ComputerStatus != MyDeviceHelper.DeviceState)
                {
                    MyTimeDuration duration = new MyTimeDuration()
                    {
                        StartTime        = now,
                        TimeDurationTask = new MyTask()
                        {
                            ComputerStatus = MyDeviceHelper.DeviceState
                        },
                        StopTime = now
                    };

                    todayTimeLine.Add(duration);
                }
                else
                {
                    todayTimeLine.Last().StopTime = now;
                }
                AllDays[today].TimeLine = todayTimeLine;
                return;
            }

            IntPtr nowFocusWindow      = MyWindowHelper.GetFocusWindow();
            string nowFocusWindowTitle = MyWindowHelper.GetWindowTitle(nowFocusWindow);

            //如果今天还未记录到任务 或 切换了任务
            if (todayTimeLine.Count == 0 || todayTimeLine.Last().TimeDurationTask.ApplicationTitle != nowFocusWindowTitle)
            {
                Process nowFocusProcess = MyProcessHelper.GetWindowPID(nowFocusWindow);
                if (nowFocusProcess.Id == 0)
                {
                    return;
                }

                string nowFocusProcessName = MyProcessHelper.GetProcessName(nowFocusProcess);
                if (string.IsNullOrEmpty(nowFocusProcessName))
                {
                    return;
                }

                MyTask nowFocusTask =
                    new MyTask()
                {
                    ApplicationName        = nowFocusProcessName,
                    ApplicationFilePath    = MyProcessHelper.GetProcessPath(nowFocusProcess),
                    ApplicationTitle       = MyWindowHelper.GetWindowTitle(nowFocusWindow),
                    ApplicationIcon_Base64 = MyDataHelper.ImgToBase64String(MyProcessHelper.GetProcessIcon(nowFocusProcess))
                };

                MyTimeDuration nowTimeDuration =
                    new MyTimeDuration()
                {
                    StartTime        = now,
                    StopTime         = now,
                    TimeDurationTask = nowFocusTask
                };

                if (todayTimeLine.Count != 0)
                {
                    todayTimeLine.Last().StopTime = now;
                }

                todayTimeLine.Add(nowTimeDuration);
            }
            else
            {
                todayTimeLine.Last().StopTime = now;
            }

            AllDays[today].TimeLine = todayTimeLine;
        }
        private List <Person> GetEmployees()
        {
            string        sql  = "SELECT * FROM employee";
            List <Person> temp = new List <Person>();

            try
            {
                MyDataHelper.OpenConnection();
                MySqlDataReader reader = myDataHelper.DataReader(sql);
                while (reader.Read())
                {
                    Gender g;
                    Person emp;
                    if (reader["gender"].ToString() == "F")
                    {
                        g = Gender.Female;
                    }
                    else
                    {
                        g = Gender.Male;
                    }
                    if (reader["level"].ToString() == "level_3")
                    {
                        WorkPlaceForLevel3 place;
                        if (reader["work_place"].ToString() == "shop")
                        {
                            place = WorkPlaceForLevel3.Shop;
                        }
                        else if (reader["work_place"].ToString() == "entrance check")
                        {
                            place = WorkPlaceForLevel3.EntranceCheck;
                        }
                        else
                        {
                            place = WorkPlaceForLevel3.Other;
                        }
                        emp = new Employee(Convert.ToInt32(reader["empNr"]), reader["first_name"].ToString(), reader["last_name"].ToString(),
                                           Convert.ToDateTime(reader["dob"]), g, reader["address"].ToString(), reader["email"].ToString(), reader["userName"].ToString(),
                                           reader["password"].ToString(), place);
                    }
                    else
                    {
                        EmpLevel lvl;
                        if (reader["level"].ToString() == "level_2")
                        {
                            lvl = EmpLevel.Level2;
                        }
                        else
                        {
                            lvl = EmpLevel.Level1;
                        }
                        emp = new Employee(Convert.ToInt32(reader["empNr"]), reader["first_name"].ToString(), reader["last_name"].ToString(),
                                           Convert.ToDateTime(reader["dob"]), g, reader["address"].ToString(), reader["email"].ToString(), reader["userName"].ToString(),
                                           reader["password"].ToString(), lvl);
                    }
                    temp.Add(emp);
                }
                return(temp);
            }
            catch
            {
                return(null);
            }
            finally
            {
                MyDataHelper.CloseConnection();
            }
        }