public static bool AddGroupForUser(int userId, GroupModel group)
        {
            var startDateStr = Convert.ToDateTime(group.Start).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
            var endDateStr = Convert.ToDateTime(group.End).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

            var sql = "INSERT IGNORE INTO " + TblGroupsForUsers
                      + " (`UserID`, `GroupID`, `GroupName`, `TimeFrame`, `Start`, `End`, `CntType`, `Privilege`, `AppType`,`IsDaily`, `IsMonthly`,`IsPart`,`WeekDays`,`MonthDays`,`TimePeriods`)"
                      + "VALUES('" + userId + "',"
                      + " '" + group.GroupId + "',"
                      + " '" + group.GroupName + "',"
                      + " '" + group.TimeFrame + "',"
                      + " '" + startDateStr + "',"
                      + " '" + endDateStr + "',"
                      + " '" + group.CntType + "',"
                      + " '" + GroupPrivilege.Creator + "',"
                      + " '" + ApplicationType.DataNet.ToString() + "',"

                      + " " + group.IsDaily + ","
                      + " " + group.IsMonthly + ","
                      + " " + group.IsPart + ","
                      + " '" + group.WeekDays + "',"
                      + " '" + group.MonthDays + "',"
                      + " '" + group.TimePeriods + "'"

                      + ");COMMIT;";

            return DoSql(sql);
        }
Esempio n. 2
0
        public EditListControl(int groupId, GroupModel groupModel)
        {
            GroupId = groupId;
            AGroupModel = groupModel;
            InitializeComponent();

            cmbContinuationType.Items.Clear();
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctNoContinuation);
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctStandard);
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctStandardByMonth);
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctActive);
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctActiveByMonth);
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctAdjusted);
            cmbContinuationType.Items.Add(eTimeSeriesContinuationType.tsctAdjustedByMonth);
        }
        public static List<GroupModel> GetGroupsForUser(int userId)
        {
            var groupList = new List<GroupModel>();

            string sql = "SELECT * FROM " + TblGroupsForUsers + " WHERE UserID = '" + userId + "' ; COMMIT;";
            var reader = GetReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    var symbol = new GroupModel
                    {
                        GroupId = reader.GetInt32(2),
                        GroupName = reader.GetString(3),
                        TimeFrame = reader.GetString(4),
                        Start = reader.GetDateTime(5),
                        End = reader.GetDateTime(6),
                        CntType = reader.GetString(7),

                        IsDaily = reader.GetBoolean(10),
                        IsMonthly = reader.GetBoolean(11),
                        IsPart = reader.GetBoolean(12),
                        WeekDays = reader.GetString(13),
                        MonthDays = reader.GetString(14),
                        TimePeriods = reader.GetString(15),
                    };

                    GroupPrivilege privilege;
                    ApplicationType appType;
                    Enum.TryParse(reader.GetString(8), out privilege);
                    Enum.TryParse(reader.GetString(9), out appType);

                    symbol.Privilege = privilege;
                    symbol.AppType = appType;

                    groupList.Add(symbol);
                }
                reader.Close();
            }
            return groupList;
        }
        public static List<GroupModel> GetAllGroups()
        {
            var groupList = new List<GroupModel>();

            const string sql = "SELECT * FROM " + TblSymbolsGroups;

            var reader = GetReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    var group = new GroupModel
                    {
                        GroupId = reader.GetInt32(0),
                        GroupName = reader.GetString(1),
                        TimeFrame = reader.GetString(2),
                        Start = reader.GetDateTime(3),
                        End = reader.GetDateTime(4),
                        CntType = reader.GetString(5),
                        AppType = ApplicationType.DataNet,
                        Privilege = GroupPrivilege.Creator
                    };

                    groupList.Add(group);
                }

                reader.Close();
            }
            return groupList;
        }
        public static bool EditGroupOfSymbols(int groupId, GroupModel group)
        {
            string startDateStr = Convert.ToDateTime(group.Start).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
            string endDateStr = Convert.ToDateTime(group.End).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

            String query = "UPDATE " + TblSymbolsGroups
                        + " SET GroupName = '" + group.GroupName
                        + "', TimeFrame = '" + group.TimeFrame
                        + "', Start = '" + startDateStr
                        + "', End = '" + endDateStr
                        + "', CntType = '" + group.CntType
                        + "' WHERE ID = '" + groupId + "' ; COMMIT;";

            if (DoSql(query))
            {
                query = "UPDATE " + TblGroupsForUsers
                    + " SET GroupName = '" + group.GroupName
                    + "', TimeFrame = '" + group.TimeFrame
                    //+ "', Start = '" + startDateStr
                    //+ "', End = '" + endDateStr
                    + "', CntType = '" + group.CntType

                    + "', IsDaily = " + group.IsDaily
                    + ", IsMonthly = " + group.IsMonthly
                    + ", IsPart = " + group.IsPart

                    + ", WeekDays = '" + group.WeekDays
                    + "', MonthDays = '" + group.MonthDays
                    + "', TimePeriods = '" + group.TimePeriods

                    + "' WHERE GroupID = '" + groupId + "' ; COMMIT;";

                return DoSql(query);
            }

            return false;
        }
        public static bool AddGroupOfSymbols(GroupModel group)
        {
            string startDateStr = Convert.ToDateTime(group.Start).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
            string endDateStr = Convert.ToDateTime(group.End).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

            String query = "INSERT IGNORE INTO " + TblSymbolsGroups;
            query += "(GroupName, TimeFrame, Start, End, CntType) VALUES";
            query += "('" + group.GroupName + "',";
            query += " '" + group.TimeFrame + "',";
            query += " '" + startDateStr + "',";
            query += " '" + endDateStr + "',";
            query += " '" + group.CntType + "');COMMIT;";
            return DoSql(query);
        }
Esempio n. 7
0
        private static DateTime GetScheduledDateTime(GroupModel groupModel)
        {
            DateTime firstDt, secondDt, schDateTime = new DateTime();

            GetNextTwoDays(groupModel, out firstDt, out secondDt);
            var maxTime = GetMaxTodayTime(groupModel);
            if (firstDt.Date != DateTime.Today)
            {
                var tm = GetMinTime(groupModel);

                schDateTime = firstDt.Date.AddMinutes(tm.TimeOfDay.TotalMinutes);
            }
            else if (maxTime.TimeOfDay > DateTime.Now.TimeOfDay && firstDt.Date == DateTime.Today)
            {

                var tm = GetFirstTimeFromNow(groupModel);

                schDateTime = firstDt.Date.AddMinutes(tm.TimeOfDay.TotalMinutes);

            }
            else
            {
                var tm = GetMinTime(groupModel);

                schDateTime = secondDt.Date.AddMinutes(tm.TimeOfDay.TotalMinutes);
            }
            /*

            var test = GetScheduledTime(groupItem, schDateTime);

            {
                if (test.TimeOfDay > DateTime.Now.TimeOfDay)
                {
                    schDateTime = schDateTime.AddMinutes(test.TimeOfDay.TotalMinutes);
                }
                else
                {
                    var sch = GetScheduledDate(groupItem.GroupModel, true);
                    schDateTime = GetScheduledTime(groupItem, sch);
                }
            }
            */
            return schDateTime;
        }
Esempio n. 8
0
        private static DateTime GetScheduledDate(GroupModel groupModel, bool needSecond = false)
        {
            var now = needSecond ? DateTime.Now.AddDays(1) : DateTime.Now;
            var schDateTime = DateTime.Today;

            if (groupModel.IsDaily)
            {
                schDateTime = GetMinDateFromToday(groupModel.WeekDays, needSecond);
            }
            else
            {
                DateTime minDt = DateTime.Today;
                var dates = groupModel.MonthDays.Split(',');
                foreach (string date in dates)
                {
                    if (date != "")
                    {
                        var dt = Convert.ToDateTime(date);

                        if (dt > now && minDt > dt)
                        {
                            minDt = dt;
                        }
                    }
                }
                if (minDt != now.Date)
                {
            //found
                    schDateTime = minDt.Date;
                }

            }
            return schDateTime;
        }
Esempio n. 9
0
        private static void GetNextTwoDays(GroupModel groupModel, out DateTime firstDt, out DateTime secondDt)
        {
            firstDt = DateTime.Today;
            secondDt = DateTime.Today.AddDays(1);

            if (groupModel.IsDaily)
            {
                firstDt = GetMinDateFromToday(groupModel.WeekDays, false);
                secondDt = GetMinDateFromToday(groupModel.WeekDays, true);

            }
            else
            {
                DateTime minDt = DateTime.Today;
                DateTime minDtSecond = DateTime.Today.AddDays(1);
                var dates = groupModel.MonthDays.Split(',');
                foreach (string date in dates)
                {
                    if (date != "")
                    {
                        var dt = Convert.ToDateTime(date);

                        if (dt > DateTime.Today && minDt > dt)
                        {
                            minDt = dt;
                        }
                        if (dt > DateTime.Today.AddDays(1) && minDtSecond > dt)
                        {
                            minDtSecond = dt;
                        }
                    }
                }

                if (minDt.Date != DateTime.Today)
                {
                    firstDt = minDt.Date;
                    secondDt = minDtSecond.Date;
                }

            }
        }
Esempio n. 10
0
        private static DateTime GetMinTime(GroupModel groupModel)
        {
            var res = DateTime.Today.AddDays(1).AddMinutes(-1);

            if (groupModel.IsPart)
            {
                var times = groupModel.TimePeriods.Split(',');

                for (int i = 0; i < times.Length; i++)
                {
                    string time = times[i];
                    if (time != "")
                    {
                        var ss = time.Split('-');
                        if (ss.Count() > 1)
                        {
                            var timeE = Convert.ToDateTime(ss[0]);

                            if (res.TimeOfDay > timeE.TimeOfDay)
                            {
                                res = timeE;
                            }
                        }
                    }
                }
            }
            return res;
        }
Esempio n. 11
0
        private void EditListControl_SaveClick(object sender, EventArgs e)
        {
            var mList = _editListControl.checkedListBox_rd.CheckedItems.Cast<String>();

            var enumerable = mList as IList<string> ?? mList.ToList();
            var weekDays = enumerable.Aggregate<string, string>(null, (current, item) => current + (item + ","));

            var aList = _editListControl.GetDates();
            enumerable = aList as IList<string> ?? aList.ToList();
            var monthDays = enumerable.Aggregate<string, string>(null, (current, item) => current + (item + ","));

            var group = new GroupModel
            {
                GroupName = _editListControl.textBoxXListName.Text,
                TimeFrame = _editListControl.cmbHistoricalPeriod.SelectedItem.ToString(),
                Start = new DateTime(),
                End = new DateTime(),
                CntType = _editListControl.cmbContinuationType.SelectedItem.ToString(),
                IsDaily = _editListControl.checkBoxX_repeat_dialy.Checked,
                IsMonthly = !_editListControl.checkBoxX_repeat_dialy.Checked,
                IsPart = _editListControl.checkBoxX_parttime.Checked,
                WeekDays = weekDays,
                MonthDays = monthDays,
                TimePeriods = _editListControl.GetTimePeriods()
            };

            var oldGroupName = _editListControl.OldGroupName;

            if ((!_groups.Exists(a => a.GroupName == group.GroupName) && _groups.Exists(a => a.GroupName == oldGroupName)) || (group.GroupName == oldGroupName && _groups.Exists(a => a.GroupName == oldGroupName)))
            {
                var groupId = _groups.Find(a => a.GroupName == oldGroupName).GroupId;
                DataNetClientDataManager.EditGroupOfSymbols(groupId, group);
                var symbolsInGroup = DataNetClientDataManager.GetSymbolsInGroup(groupId);
                foreach (var item in _editListControl.lbSelList.Items)
                {
                    if (!symbolsInGroup.Exists(a => a.SymbolName == item.ToString()) && _symbols.Exists(a => a.SymbolName == item.ToString()))
                    {
                        var symbol = _symbols.Find(a => a.SymbolName == item.ToString());
                        DataNetClientDataManager.AddSymbolIntoGroup(groupId, symbol);

                    }
                }

                symbolsInGroup = DataNetClientDataManager.GetSymbolsInGroup(groupId);
                foreach (var symbol in symbolsInGroup)
                {
                    var exist = false;
                    foreach (var item in _editListControl.lbSelList.Items)
                    {
                        if (symbol.SymbolName == item.ToString()) exist = true;
                    }
                    if (!exist) DataNetClientDataManager.DeleteSymbolFromGroup(groupId, symbol.SymbolId);
                }

                RefreshGroups();

                foreach (var item in ui_listBox_groups.Items)
                {
                    if (item.ToString() == group.GroupName)
                    {
                        ui_listBox_groups.SelectedItem = item;
                        break;
                    }
                }

                CloseEditListControl();
            }
            else
            {
                ToastNotification.Show(_editListControl, @"List with this name is already exists!");
            }
        }
Esempio n. 12
0
        private void AddListControl_SaveClick(object sender, EventArgs e)
        {
            var group = new GroupModel
            {
                GroupName = _addListControl.textBoxXListName.Text,
                TimeFrame = _addListControl.cmbHistoricalPeriod.SelectedItem.ToString(),
                Start = new DateTime(),
                End = new DateTime(),
                CntType = _addListControl.cmbContinuationType.SelectedItem.ToString()
            };

            if (!_groups.Exists(a => a.GroupName == group.GroupName) && !DataNetClientDataManager.GetAllGroups().Exists(a => a.GroupName == group.GroupName))
            {
                if (DataNetClientDataManager.AddGroupOfSymbols(group))
                {
                    group.GroupId = DataNetClientDataManager.GetGroupIdByName(group.GroupName);

                    DataNetClientDataManager.AddGroupForUser(_client.UserID, group);
                    RefreshGroups();

                    _clientService.ServiceProxy.onSymbolGroupListRecieved("");
                    foreach (var item in ui_listBox_groups.Items)
                    {
                        if (item.ToString() == group.GroupName)
                        {
                            ui_listBox_groups.SelectedItem = item;
                            break;
                        }
                    }

                    CloseAddListControl();
                }
            }
            else
            {
                ToastNotification.Show(_addListControl, @"List with this name is already exists!");
            }
        }