Esempio n. 1
0
        private static bool GetBooleanParam(SqlConnection cn, SqlTransaction tran, string columnName, bool defaultValue)
        {
            string def;

            if (defaultValue)
            {
                def = "1";
            }
            else
            {
                def = "0";
            }
            if (!SortingClass.CheckColumn("CompetitionData", columnName, "BIT NOT NULL DEFAULT " + def, cn, tran))
            {
                return(defaultValue);
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "SELECT " + columnName + " FROM CompetitionData(NOLOCK)";
            try { return(Convert.ToBoolean(cmd.ExecuteScalar())); }
            catch
            {
                cmd.CommandText = "UPDATE CompetitionData SET " + columnName + " = " + def;
                cmd.ExecuteNonQuery();
                return(defaultValue);
            }
        }
        //protected override void GetFormDataKeys(out string typeName, out string hostName)
        //{
        //    String sTypeName;
        //    base.GetFormDataKeys(out sTypeName, out hostName);
        //    typeName = String.Format("{0}.{1}", sTypeName, list_id);
        //    if (typeName.Length > BaseForm.FORM_CLASS_FIELD_LENGTH)
        //        typeName = typeName.Substring(0, BaseForm.FORM_CLASS_FIELD_LENGTH);
        //}

        protected string GetListOwner()
        {
            if (cn == null || cn.ConnectionString.Length < 1)
            {
                return("");
            }
            try
            {
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }
                SortingClass.CheckColumn("lists", "IsLocked", "VARCHAR(255) NULL", cn);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "SELECT IsLocked FROM lists WHERE iid=" + listID.ToString();
                object oTmp = cmd.ExecuteScalar();
                if (oTmp == null || oTmp == DBNull.Value)
                {
                    return("");
                }
                return(oTmp.ToString());
            }
            catch { return(""); }
        }
Esempio n. 3
0
 public static void CheckGlobalIDColumns(SqlConnection cn)
 {
     SortingClass.CheckColumn("Participants", "global_climber_id", "NVARCHAR(50) NULL", cn);
     SortingClass.CheckColumn("Participants", "global_app_id", "NVARCHAR(50) NULL", cn);
     SortingClass.CheckColumn("Groups", "global_group_id", "NVARCHAR(50) NULL", cn);
     SortingClass.CheckColumn("Teams", "global_team_id", "NVARCHAR(50) NULL", cn);
 }
Esempio n. 4
0
        public static SpeedSystemType GetCurrentSystem(SqlConnection cn)
        {
            if (!SortingClass.CheckColumn("CompetitionData", "SpeedType", "VARCHAR(3) NOT NULL DEFAULT '" + SpeedSystemType.EKB.ToString() + "'", cn))
            {
                return(SpeedSystemType.EKB);
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandText = "SELECT SpeedType FROM CompetitionData(NOLOCK)";
            string str = cmd.ExecuteScalar().ToString();

            try
            {
#if FULL
                return((SpeedSystemType)Enum.Parse(typeof(SpeedSystemType), str, true));
#else
                SpeedSystemType st = (SpeedSystemType)Enum.Parse(typeof(SpeedSystemType), str, true);
                if (st == SpeedSystemType.IVN)
                {
                    throw new Exception();
                }
                return(st);
#endif
            }
            catch
            {
                cmd.CommandText = "UPDATE CompetitionData SET SpeedType = '" + SpeedSystemType.EKB.ToString() + "'";
                cmd.ExecuteNonQuery();
                return(SpeedSystemType.EKB);
            }
        }
Esempio n. 5
0
        public static void SetFlashShowMode(FlashShowMode val, SqlConnection cn)
        {
            SortingClass.CheckColumn("CompetitionData", "FlashShowMode", "VARCHAR(3) NOT NULL DEFAULT '" + FlashShowMode.NOT.ToString() + "'", cn);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandText = "UPDATE CompetitionData SET FlashShowMode='" + val.ToString() + "'";
            cmd.ExecuteNonQuery();
        }
Esempio n. 6
0
        public static void SetAutoNum(AutoNum val, SqlConnection cn)
        {
            SortingClass.CheckColumn("CompetitionData", "AutoNum", "VARCHAR(3) NOT NULL DEFAULT '" + AutoNum.GRP.ToString() + "'", cn);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandText = "UPDATE CompetitionData SET AutoNum='" + val.ToString() + "'";
            cmd.ExecuteNonQuery();
        }
Esempio n. 7
0
        private static void SetIntParam(SqlConnection cn, SqlTransaction tran, string columnName, int val, int defaultValue)
        {
            SortingClass.CheckColumn("CompetitionData", columnName, "INT NOT NULL DEFAULT " + defaultValue.ToString(), cn, tran);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "UPDATE CompetitionData SET " + columnName + "=" + val.ToString();
            cmd.ExecuteNonQuery();
        }
        public OnlineBroadcast(/*string remoteConn,*/ SqlConnection localBaseCon, MainForm parent)
            : base(localBaseCon, parent.competitionTitle, null)
        {
            InitializeComponent();
            this.parent = parent;
            //this.cn = cn;
            //XmlClientWrapper wrapper;
            //compForService = StaticClass.ParseServString(remoteConn, out wrapper);
            //if (wrapper != null)
            //{
            //    client = wrapper.CreateClient(cn);
            //    compForService = wrapper.CompetitionId;
            //    remoteConnection = null;
            //}
            //else if (compForService == null)
            //    remoteConnection = new SqlConnection(remoteConn);
            //else
            //    remoteConn = null;
            ////if (this.cn.State != ConnectionState.Open)
            ////    this.cn.Open();

            SortingClass.CheckColumn("Participants", "changed", "BIT NOT NULL DEFAULT 1", this.cn);
            SortingClass.CheckColumn("lists", "changed", "BIT NOT NULL DEFAULT 1", this.cn);
            SortingClass.CheckColumn("routeResults", "changed", "BIT NOT NULL DEFAULT 1", this.cn);
            SortingClass.CheckColumn("speedResults", "changed", "BIT NOT NULL DEFAULT 1", this.cn);
            SortingClass.CheckColumn("boulderResults", "changed", "BIT NOT NULL DEFAULT 1", this.cn);
            StaticClass.CheckChangedTriggers(this.cn);

            da = new SqlDataAdapter(new SqlCommand(
                                        "SELECT l.iid AS [№],l.style AS Вид,g.name AS Группа,l.round AS Раунд, " +
                                        "l.routeNumber AS [Число трасс], " +
                                        "l.online AS [Доступ на сайте],l.allowView AS [Прямая трансляция], g.iid gr_id " +
                                        "FROM lists l(NOLOCK) INNER JOIN groups g(NOLOCK) ON l.group_id=g.iid " +
#if FULL
                                        " WHERE l.style IN ('Трудность','Скорость','Боулдеринг') " +
#else
                                        " WHERE l.style = 'Скорость' " +
#endif
                                        "ORDER BY " +
                                        "l.iid DESC", this.cn));
            try { da.Fill(dt); }
            catch { }
            dg.DataSource = dt;
            dg.Columns["gr_id"].Visible = false;
            da.UpdateCommand            = new SqlCommand("UPDATE lists SET online=@onl WHERE iid=@iid", this.cn);
            da.UpdateCommand.Parameters.Add("@onl", SqlDbType.Bit, 1, "Доступ на сайте");
            da.UpdateCommand.Parameters.Add("@iid", SqlDbType.Int, 4, "№");
            try { dg.Columns["Прямая трансляция"].ReadOnly = true; }
            catch { }
#if !DEBUG
            cbLoadJudges.Visible = false;
#endif
        }
Esempio n. 9
0
        public static SpeedRules GetCompRules(SqlConnection cn, SqlTransaction tran = null)
        {
            SqlConnection cnToUse = (tran == null ? cn : tran.Connection);

            SortingClass.CheckColumn("CompetitionData", "SpeedRulesGeneral",
                                     String.Format("INT NOT NULL DEFAULT {0}", (int)SpeedRules.DefaultAll), cnToUse, tran);
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection  = cnToUse;
                cmd.Transaction = tran;
                cmd.CommandText = "SELECT SpeedRulesGeneral FROM CompetitionData(NOLOCK)";
                return(GetEnumValueFromObject <SpeedRules, int>(cmd.ExecuteScalar(), SpeedRules.DefaultAll));
            }
        }
Esempio n. 10
0
        public static void SetCurrentSystem(SpeedSystemType val, SqlConnection cn)
        {
            SortingClass.CheckColumn("CompetitionData", "SpeedType", "VARCHAR(3) NOT NULL DEFAULT '" + SpeedSystemType.EKB.ToString() + "'", cn);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = cn;
#if FULL
            cmd.CommandText = "UPDATE CompetitionData SET SpeedType='" + val.ToString() + "'";
#else
            SpeedSystemType sVal = (val == SpeedSystemType.IVN) ? SpeedSystemType.EKB : val;
            cmd.CommandText = "UPDATE CompetitionData SET SpeedType='" + sVal.ToString() + "'";
#endif
            cmd.ExecuteNonQuery();
        }
Esempio n. 11
0
        public static bool SetCompRules(SpeedRules value, SqlConnection cn, SqlTransaction tran = null)
        {
            SqlConnection cnToUse = (tran == null) ? cn : tran.Connection;

            SortingClass.CheckColumn("CompetitionData", "SpeedRulesGeneral", "INT NOT NULL DEFAULT " +
                                     ((int)SpeedRules.DefaultAll).ToString(), cnToUse, tran);
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection  = cnToUse;
                cmd.Transaction = tran;
                cmd.CommandText = String.Format("UPDATE CompetitionData SET SpeedRulesGeneral = {0}", ((int)value));
                cmd.ExecuteNonQuery();
                return(true);
            }
        }
Esempio n. 12
0
        private static void SetStringParam(SqlConnection cn, SqlTransaction tran, string columnName, string val, string defaultValue = null)
        {
            SortingClass.CheckColumn("CompetitionData", columnName, "VARCHAR(4096) DEFAULT " + (defaultValue == null ? "NULL" : "'" + defaultValue + "'"), cn, tran);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "UPDATE CompetitionData SET " + columnName + " = @val";
            cmd.Parameters.Add("@val", SqlDbType.VarChar, 4096);
            if (val == null)
            {
                cmd.Parameters[0].Value = DBNull.Value;
            }
            else
            {
                cmd.Parameters[0].Value = val;
            }
            cmd.ExecuteNonQuery();
        }
Esempio n. 13
0
        private static void SetBooleanParam(bool val, SqlConnection cn, string columnName, bool defaultValue)
        {
            string def;

            if (defaultValue)
            {
                def = "1";
            }
            else
            {
                def = "0";
            }
            SortingClass.CheckColumn("CompetitionData", columnName, "BIT NOT NULL DEFAULT " + def, cn);
            SqlCommand cmd = new SqlCommand("UPDATE CompetitionData SET " + columnName + " = @s", cn);

            cmd.Parameters.Add("@s", SqlDbType.Bit);
            cmd.Parameters[0].Value = val;
            cmd.ExecuteNonQuery();
        }
Esempio n. 14
0
        public static FlashShowMode GetFlashShowMode(SqlConnection cn, SqlTransaction tran)
        {
            if (!SortingClass.CheckColumn("CompetitionData", "FlashShowMode", "VARCHAR(3) NOT NULL DEFAULT '" + FlashShowMode.NOT.ToString() + "'", cn, tran))
            {
                return(FlashShowMode.NOT);
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "SELECT FlashShowMode FROM CompetitionData(NOLOCK)";
            string str = cmd.ExecuteScalar().ToString();

            try { return((FlashShowMode)Enum.Parse(typeof(FlashShowMode), str, true)); }
            catch
            {
                cmd.CommandText = "UPDATE CompetitionData SET FlashShowMode = '" + FlashShowMode.NOT.ToString() + "'";
                cmd.ExecuteNonQuery();
                return(FlashShowMode.NOT);
            }
        }
Esempio n. 15
0
        public static AutoNum GetAutoNum(SqlConnection cn, SqlTransaction tran)
        {
            if (!SortingClass.CheckColumn("CompetitionData", "AutoNum", "VARCHAR(3) NOT NULL DEFAULT '" + AutoNum.GRP.ToString() + "'", cn, tran))
            {
                return(AutoNum.GRP);
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "SELECT AutoNum FROM CompetitionData(NOLOCK)";
            string str = cmd.ExecuteScalar().ToString();

            try { return((AutoNum)Enum.Parse(typeof(AutoNum), str, true)); }
            catch
            {
                cmd.CommandText = "UPDATE CompetitionData SET AutoNum = '" + AutoNum.GRP + "'";
                cmd.ExecuteNonQuery();
                return(AutoNum.GRP);
            }
        }
Esempio n. 16
0
        private static string GetStringParam(SqlConnection cn, SqlTransaction tran, string columnName, string defaultValue)
        {
            if (!SortingClass.CheckColumn("CompetitionData", columnName, "VARCHAR(4096) DEFAULT " + (defaultValue == null ? "NULL" : "'" + defaultValue + "'"), cn, tran))
            {
                return(defaultValue);
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "SELECT " + columnName + " FROM CompetitionData";
            object oTmp = cmd.ExecuteScalar();

            if (oTmp == null || oTmp == DBNull.Value)
            {
                return(String.Empty);
            }
            else
            {
                return(oTmp.ToString());
            }
        }
 protected void SetLock(bool setLock)
 {
     if (cn == null || cn.ConnectionString.Length < 1)
     {
         return;
     }
     try
     {
         if (listID < 1 || listID == EMPTY_LIST)
         {
             return;
         }
         SortingClass.CheckColumn("lists", "IsLocked", "VARCHAR(255) NULL", cn);
         SqlCommand cmd = new SqlCommand();
         cmd.Connection  = cn;
         cmd.CommandText = "UPDATE lists SET IsLocked = " + (setLock ? "'" + HostName + "'" : "NULL") +
                           " WHERE iid = " + listID.ToString();
         cmd.ExecuteNonQuery();
         this.lockSet = setLock;
     }
     catch { }
 }
        private SecurityOperations(SqlConnection _cn, bool show, bool newCn)
        {
            if (newCn)
            {
                this.ownConnection = true;
                this.cn            = new SqlConnection(_cn.ConnectionString);
                this.cn.Open();
            }
            else
            {
                this.ownConnection = false;
                this.cn            = _cn;
            }

            SortingClass.CheckColumn("CompetitionData", "signature", "image null", cn);
            SortingClass.CheckColumn("CompetitionData", "opwd", "image null", cn);
            SortingClass.CheckColumn("CompetitionData", "touse", "smallint not null default 0", cn);
            if (show)
            {
                InitializeComponent();
            }
        }
Esempio n. 19
0
        //public static bool GetUseBestSpeed(SqlConnection cn, SqlTransaction tran = null)
        //{
        //    return GetBooleanParam(cn, tran, "BestSpeed", false);
        //}

        //public static void SetUseBestSpeed(bool val, SqlConnection cn)
        //{
        //    SetBooleanParam(val, cn, "BestSpeed", false);
        //}

        //public static bool GetUseBestQf(SqlConnection cn)
        //{
        //    return GetUseBestQf(cn, null);
        //}

        //public static bool GetUseBestQf(SqlConnection cn, SqlTransaction tran)
        //{
        //    return GetBooleanParam(cn, tran, "UseBestQf", false);
        //}

        //public static void SetUseBestQf(bool val, SqlConnection cn)
        //{
        //    SetBooleanParam(val, cn, "UseBestQf", false);
        //}

        private static int GetIntParam(SqlConnection cn, SqlTransaction tran, string columnName, int defaultValue)
        {
            if (!SortingClass.CheckColumn("CompetitionData", columnName, "INT NOT NULL DEFAULT " + defaultValue.ToString(), cn, tran))
            {
                return(defaultValue);
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.Transaction = tran;
            cmd.CommandText = "SELECT " + columnName + " FROM CompetitionData";
            object oTmp = cmd.ExecuteScalar();

            if (oTmp == null || oTmp == DBNull.Value)
            {
                cmd.CommandText = "UPDATE CompetitionData SET " + columnName + "=" + defaultValue.ToString();
                cmd.ExecuteNonQuery();
                return(defaultValue);
            }
            else
            {
                return(Convert.ToInt32(oTmp));
            }
        }
        public SelectTeamType(SqlConnection baseCon, int list_id, string competitionTitle) : base(baseCon, competitionTitle)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            rbGroup.Checked = true;
            this.list_id    = list_id;
            //this.cn = cn;
            //if (this.cn.State != System.Data.ConnectionState.Open)
            //    cn.Open();
            SqlCommand cmd = new SqlCommand("SELECT style FROM lists(NOLOCK) WHERE iid = " + list_id.ToString(), cn);

            style = cmd.ExecuteScalar().ToString();
            switch (style)
            {
            case "��������� - ��":
                this.tRes.lead  = true;
                this.tRes.speed = this.tRes.boulder = false;
                break;

            case "��������� - �":
                this.tRes.boulder = true;
                this.tRes.speed   = this.tRes.lead = false;
                break;

            case "��������� - ��":
                this.tRes.speed   = true;
                this.tRes.boulder = this.tRes.lead = false;
                break;

#if !FULL
            case "���������":
                goto case "��������� - ��";
#endif
            default:
                cmd.CommandText = "SELECT COUNT(*) FROM lists(NOLOCK) WHERE style = '���������' AND round = '�������� ��������'";
                tRes.lead       = (Convert.ToInt32(cmd.ExecuteScalar()) > 0);
                cmd.CommandText = "SELECT COUNT(*) FROM lists(NOLOCK) WHERE style = '��������' AND round = '�������� ��������'";
                tRes.speed      = (Convert.ToInt32(cmd.ExecuteScalar()) > 0);
                cmd.CommandText = "SELECT COUNT(*) FROM lists(NOLOCK) WHERE style = '����������' AND round = '�������� ��������'";
                tRes.boulder    = (Convert.ToInt32(cmd.ExecuteScalar()) > 0);
                break;
            }
            double coef2ndTeam = 1.0;
            try
            {
                SortingClass.CheckColumn("lists_hdr2", "coef2ndTeam", "FLOAT NOT NULL DEFAULT 1.0", cn);
                cmd.CommandText = "SELECT use_group, male, female, coef2ndTeam FROM lists_hdr2(NOLOCK) WHERE list_id = " + list_id.ToString();
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        bool b = Convert.ToBoolean(rdr[0]);
                        rbGroup.Checked      = b;
                        radioButton1.Checked = !b;
                        int nMale = Convert.ToInt32(rdr[1]);
                        if (b)
                        {
                            nM.Text = nMale.ToString();
                            nF.Text = rdr[2].ToString();
                        }
                        else
                        {
                            nG.Text = nMale.ToString();
                        }
                        coef2ndTeam = Convert.ToDouble(rdr["coef2ndTeam"]);
                    }
                }
            }
            catch
            {
                try
                {
                    cmd.CommandText = "CREATE TABLE [dbo].[lists_hdr2] (" +
                                      "	[list_id] [int] NOT NULL ," +
                                      "	[use_group] [bit] NOT NULL ," +
                                      "	[male] [int] NOT NULL ," +
                                      "	[female] [int] NULL ," +
                                      "   [coef2ndTeam] FLOAT NOT NULL DEFAULT 1.0," +
                                      "	CONSTRAINT [PK_lists_hdr2] PRIMARY KEY  CLUSTERED " +
                                      "	(" +
                                      "		[list_id]"+
                                      "	)  ON [PRIMARY] ," +
                                      "	CONSTRAINT [FK_lists_hdr2_lists] FOREIGN KEY " +
                                      "	(" +
                                      "		[list_id]"+
                                      "	) REFERENCES [dbo].[lists] (" +
                                      "		[iid]"+
                                      "	) ON DELETE CASCADE  ON UPDATE CASCADE" +
                                      ")";
                    cmd.ExecuteNonQuery();
                }
                catch { }
            }
            tRes.Qf2nd  = coef2ndTeam;
            tbCoef.Text = coef2ndTeam.ToString("0.0#");
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }