void LoadAdditionalLinks(ONLCompetition comp)
 {
     try
     {
         if (comp == null)
         {
             panelAdditionalFiles.Visible = false;
             return;
         }
         var pList = comp.GetBinaryParamLinks(p => p.ParamName.IndexOf(Constants.PDB_COMP_BIN_ADD_FILE) == 0).Where(d => !String.IsNullOrEmpty(d.Value)).ToArray();
         if (pList.Length < 1)
         {
             panelAdditionalFiles.Visible = false;
             return;
         }
         var src = from l in pList
                   select new
         {
             link     = l.Value,
             linktext = (from p in comp.ONLCompetitionParams
                         where p.ParamName.Equals(l.Key + Constants.PDB_PARAM_ADD_INFO)
                         select p.ParamValue).FirstOrDefault()
         };
         panelAdditionalFiles.Visible = true;
         gvAdditionalFiles.DataSource = src;
         gvAdditionalFiles.DataBind();
     }
     catch { panelAdditionalFiles.Visible = false; }
 }
        private static T GetParam <T>(ONLCompetition comp, string paramName, GetNullableParam <T> nullParamFunction, T defValue)
            where T : struct
        {
            Nullable <T> nulRes = nullParamFunction(comp, paramName);

            return(nulRes == null ? defValue : nulRes.Value);
        }
        public static long SetEnumParam <T>(this ONLCompetition comp, string paramName, T value, long?iidToSet = null)
            where T : struct
        {
            Type   underlyingType = Enum.GetUnderlyingType(typeof(T));
            object typeVal        = Convert.ChangeType(value, underlyingType);

            return(comp.SetObjectParam(paramName, typeVal, (c => c.ToString()), iidToSet));
        }
 private Tasks(long compID)
 {
     this.compID = compID;
     dc          = new Entities(WebConfigurationManager.ConnectionStrings["db_Entities"].ConnectionString);
     if (dc.Connection.State != ConnectionState.Open)
     {
         dc.Connection.Open();
     }
     try { comp = dc.ONLCompetitions.First(c => c.iid == this.compID); }
     catch { comp = null; }
 }
        public static Nullable <T> GetEnumParamNullable <T>(this ONLCompetition comp, string paramName)
            where T : struct
        {
            int?val = comp.GetIntParamNullable(paramName);

            if (val == null)
            {
                return(null);
            }
            try { return(new T?((T)Enum.ToObject(typeof(T), val.Value))); }
            catch { return(null); }
        }
        public static string GetStringParam(this ONLCompetition comp, string paramName)
        {
            var ps = from p in comp.ONLCompetitionParams
                     where p.ParamName.ToLower() == paramName.ToLower()
                     select p.ParamValue;

            if (ps == null || ps.Count() < 1)
            {
                return(String.Empty);
            }
            return(ps.First());
        }
        //public static T GetEnumParam<T>(this ONLCompetition comp, string paramName, T defaultValue)
        //    where T : struct
        //{
        //    return GetParam<T>(comp, paramName, GetEnumParamNullable<T>, defaultValue);
        //}

        public static T GetEnumParam <T>(this ONLCompetition comp, string paramName, T defaultValue)
        {
            try
            {
                long?l = comp.GetLongParamNullable(paramName);
                if (l == null || !l.HasValue)
                {
                    return(defaultValue);
                }
                return((T)Enum.ToObject(typeof(T), l.Value));
            }
            catch { return(defaultValue); }
        }
 private static bool GetStyleComp(ONLCompetition comp, string styleIndex)
 {
     try
     {
         string s = comp.GetStringParam(Constants.PDB_COMP_STYLES);
         if (String.IsNullOrEmpty(s))
         {
             return(false);
         }
         return(s.IndexOf(styleIndex) > -1);
     }
     catch { return(false); }
 }
        public static int GetCompYear(this ONLCompetition comp)
        {
            var dt = comp.GetDateParamNullable(Constants.PDB_COMP_START_DATE);

            if (dt == null || !dt.HasValue)
            {
                return(DateTime.UtcNow.Year);
            }
            else
            {
                return(dt.Value.Year);
            }
        }
 public static string GetBinaryParamLink(this ONLCompetition comp, string paramName)
 {
     try
     {
         var ll = comp.GetBinaryParamLinks(p => p.ParamName.Equals(paramName));
         if (ll == null || ll.Count < 1)
         {
             return(String.Empty);
         }
         else
         {
             return(ll[paramName]);
         }
     }
     catch { return(String.Empty); }
 }
        public static Dictionary <string, string> GetBinaryParamLinks(this ONLCompetition comp, Func <ONLCompetitionParam, bool> selector)
        {
            Dictionary <string, string> retVal = new Dictionary <string, string>();

            try
            {
                var selectedPList = comp.ONLCompetitionParams.Where(selector).Where(p => p.ONLCompetitionBinaryParam != null).ToArray();

                foreach (var p in selectedPList)
                {
                    retVal.Add(p.ParamName, p.ONLCompetitionBinaryParam.CheckAndSaveBinaryData());
                }
            }
            catch { }
            return(retVal);
        }
        public static bool?GetBooleanParamNullable(this ONLCompetition comp, string paramName)
        {
            string val = comp.GetStringParam(paramName);

            if (String.IsNullOrEmpty(val))
            {
                return(null);
            }
            bool res;

            if (bool.TryParse(val, out res))
            {
                return(res);
            }
            var ip = comp.GetLongParamNullable(paramName);

            return(ip == null ? null : new bool?(ip.Value > 0));
        }
        public static long?GetClimbersGroup(this ONLCompetition comp, int birthyear, bool genderFemale)
        {
            int age        = comp.GetCompYear() - birthyear;
            var groupsList = (from cl in comp.ONLGroupsCompLinks
                              where cl.ONLGroup.genderFemale == genderFemale &&
                              cl.ONLGroup.oldYear >= age &&
                              cl.ONLGroup.youngYear <= age
                              select cl.iid).ToArray();

            if (groupsList.Length < 1)
            {
                return(null);
            }
            else
            {
                return(new long?(groupsList[0]));
            }
        }
Beispiel #14
0
        private void LoadCompName()
        {
            if (entities.Connection.State != System.Data.ConnectionState.Open)
            {
                entities.Connection.Open();
            }
            var cList = from c in entities.ONLCompetitions
                        where c.iid == compID
                        select c;

            if (cList.Count() < 1)
            {
                currentComp = null;
            }
            else
            {
                currentComp = cList.First();
            }
        }
        public static long?GetLongParamNullable(this ONLCompetition comp, string paramName)
        {
            string val = comp.GetStringParam(paramName);

            if (String.IsNullOrEmpty(val))
            {
                return(null);
            }
            long l;

            if (long.TryParse(val, out l))
            {
                return(l);
            }
            else
            {
                return(null);
            }
        }
        public static DateTime?GetDateParamNullable(this ONLCompetition comp, string paramName)
        {
            string val = comp.GetStringParam(paramName);

            if (String.IsNullOrEmpty(val))
            {
                return(null);
            }
            DateTime dt;

            if (DateTime.TryParse(val, new CultureInfo("ru-RU"), DateTimeStyles.AssumeUniversal, out dt))
            {
                return(dt);
            }
            else
            {
                return(null);
            }
        }
        public static double?GetDoubleParamNullable(this ONLCompetition comp, string paramName)
        {
            string val = comp.GetStringParam(paramName);

            if (String.IsNullOrEmpty(val))
            {
                return(null);
            }
            double res;

            if (double.TryParse(val, out res))
            {
                return(res);
            }
            else
            {
                return(null);
            }
        }
        public static long SetObjectParam(this ONLCompetition comp, string paramName, object value, Func <object, string> stringRepFunc, long?iidToSet = null)
        {
            ONLCompetitionParam ps;

            try { ps = comp.ONLCompetitionParams.First(p => p.ParamName.Equals(paramName, StringComparison.InvariantCultureIgnoreCase)); }
            catch { ps = null; }
            if (ps == null)
            {
                if (value == null)
                {
                    return(-1);
                }
                long pIid;
                if (iidToSet == null)
                {
                    try { pIid = dc.ONLCompetitionParams.OrderByDescending(c => c.iid).First().iid + 1; }
                    catch { pIid = 1; }
                }
                else
                {
                    pIid = iidToSet.Value;
                }
                ONLCompetitionParam p = ONLCompetitionParam.CreateONLCompetitionParam(pIid, comp.iid, paramName);
                p.ParamValue = stringRepFunc(value);
                comp.ONLCompetitionParams.Add(p);
                return(pIid);
            }
            else
            {
                if (value == null)
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = cn;
                    cmd.CommandText = "DELETE FROM ONLCompetitionParams WHERE iid=" + ps.iid;
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    ps.ParamValue = stringRepFunc(value);
                }
                return(-1);
            }
        }
 public static void SetHyperlinkVisible(this HyperLink hyperlink, ONLCompetition comp, string paramName)
 {
     try
     {
         if (comp == null)
         {
             hyperlink.Visible = false;
             return;
         }
         string linkToSet = comp.GetBinaryParamLink(paramName);
         if (String.IsNullOrEmpty(linkToSet))
         {
             hyperlink.Visible = false;
         }
         else
         {
             hyperlink.Visible     = true;
             hyperlink.NavigateUrl = linkToSet;
         }
     }
     catch { }
 }
 static void LoadSponsors(ONLCompetition comp, Panel panel, GridView gridView, string paramName)
 {
     try
     {
         if (comp == null)
         {
             panel.Visible = false;
             return;
         }
         var parList = comp.GetBinaryParamLinks(p => p.ParamName.IndexOf(paramName) == 0).Where(d => !String.IsNullOrEmpty(d.Value)).ToArray();
         if (parList.Length < 1)
         {
             panel.Visible = false;
             return;
         }
         var src = from l in parList
                   select new { img_src = l.Value };
         panel.Visible       = true;
         gridView.DataSource = src;
         gridView.DataBind();
     }
     catch { panel.Visible = false; }
 }
        private static void SetImageLinkVisible(HyperLink link, string paramName, ONLCompetition comp)
        {
            if (comp == null)
            {
                link.Visible = false;
                return;
            }
            string srcToSet = comp.GetBinaryParamLink(paramName);

            if (String.IsNullOrEmpty(srcToSet))
            {
                link.Visible = false;
                return;
            }
            link.ImageUrl = srcToSet;
            string strNavigate = comp.GetStringParam(paramName + Constants.PDB_PARAM_ADD_INFO);

            if (strNavigate == null)
            {
                strNavigate = String.Empty;
            }
            link.NavigateUrl = strNavigate;
            link.Enabled     = !strNavigate.Equals(String.Empty);
        }
 public static int GetIntParam(this ONLCompetition comp, string paramName)
 {
     return(GetParam <int>(comp, paramName, GetIntParamNullable, int.MinValue));
 }
 public static bool Boulder(this ONLCompetition comp)
 {
     return(GetStyleComp(comp, "B"));
 }
 public static bool Speed(this ONLCompetition comp)
 {
     return(GetStyleComp(comp, "S"));
 }
 public static bool Lead(this ONLCompetition comp)
 {
     return(GetStyleComp(comp, "L"));
 }
 public static double GetDoubleParam(this ONLCompetition comp, string paramName)
 {
     return(GetParam <double>(comp, paramName, GetDoubleParamNullable, 0.0));
 }
 public static int GetNextNumberGeneral(this ONLCompetition comp)
 {
     return(comp.ONLClimberCompLinks.Count() < 1 ? 1 :
            comp.ONLClimberCompLinks.OrderByDescending(l => l.secretary_id).First().secretary_id + 1);
 }
 public static bool CheckNumber(this ONLCompetition comp, int number)
 {
     return(comp.ONLClimberCompLinks.Count(lnk => lnk.secretary_id == number) > 0);
 }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string         sStyles = String.Empty;
                ONLCompetition comp;
                if (String.IsNullOrEmpty(lblCompIid.Text))
                {
                    comp = ONLCompetition.CreateONLCompetition(SortingClass.GetNextIID("ONLCompetitions", "iid", cn, null));
                }
                else
                {
                    comp = GetCompByIid(long.Parse(lblCompIid.Text));
                }
                if (comp == null)
                {
                    lblErrMsg.Text = "Ошибка создания объекта";
                    return;
                }
                if (String.IsNullOrWhiteSpace(tbCompPlace.Text))
                {
                    lblErrMsg.Text = "Место проведения не введено";
                    return;
                }
                if (String.IsNullOrWhiteSpace(tbCompShort.Text))
                {
                    lblErrMsg.Text = "Краткое наименование соревнований не введено";
                    return;
                }
                if (String.IsNullOrWhiteSpace(tbCompTitle.Text))
                {
                    lblErrMsg.Text = "Наименование соревнований не введено";
                    return;
                }
                foreach (ListItem li in cbListStyles.Items)
                {
                    if (li.Selected)
                    {
                        sStyles += li.Value;
                    }
                }
                if (sStyles.Equals(String.Empty))
                {
                    lblErrMsg.Text = "Виды не выбраны";
                    return;
                }
                CultureInfo ci = new CultureInfo("ru-RU");
                string      dateTotal = String.Empty;
                DateTime    from = clndFrom.SelectedDate, to = clndTo.SelectedDate;
                if (from.Equals(to))
                {
                    dateTotal = from.ToString("d MMMM yyyy", ci);
                }
                else if (from.Year.Equals(to.Year))
                {
                    if (from.Month.Equals(to.Month))
                    {
                        dateTotal = from.Day.ToString() + " - " + to.ToString("d MMMM yyyy", ci) + " г.";
                    }
                    else
                    {
                        dateTotal = from.ToString("d MMMM", ci) + " - " +
                                    to.ToString("d MMMM yyyy", ci) + " г.";
                    }
                }
                else
                {
                    dateTotal = from.ToString("d MMMM yyyy", ci) + " г. - " +
                                to.ToString("d MMMM yyyy", ci) + " г.";
                }

                comp.name       = tbCompTitle.Text;
                comp.short_name = tbCompShort.Text;
                comp.place      = tbCompPlace.Text;
                comp.date       = dateTotal;

                long?nextIid = null;
                nextIid = comp.SetDateParam(Constants.PDB_COMP_START_DATE, from, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetDateParam(Constants.PDB_COMP_END_DATE, to, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetDateParam(Constants.PDB_COMP_DEADLINE, clndDeadLine.SelectedDate, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetDateParam(Constants.PDB_COMP_DEADLINE_CHANGE, clndCorrectionDeadLine.SelectedDate, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetStringParam(Constants.PDB_COMP_STYLES, sStyles, nextIid);
                nextIid = (nextIid <= 0 ? null : new long?(nextIid.Value + 1));

                nextIid = comp.SetObjectParam(Constants.PDB_COMP_ALLOW_AFTER_DEADLINE,
                                              cbAllowAfterDeadline.Checked, (o => ((bool)o).ToString()), nextIid);

                if (String.IsNullOrWhiteSpace(lblCompIid.Text))
                {
                    dc.ONLCompetitions.AddObject(comp);
                }
                dc.SaveChanges();
                LoadCompList();
                lblErrMsg.Text     = "Соревнования созданы/обновлены";
                panelComps.Visible = !(panelSelectedComp.Visible = false);
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = "Ошибка обновления соревнований:\r\n" + ex.ToString();
            }
        }
 public static bool GetBooleanParam(this ONLCompetition comp, string paramName)
 {
     return(GetParam <bool>(comp, paramName, GetBooleanParamNullable, false));
 }