protected override void btnNextRound_Click(object sender, EventArgs e) { if (dtStart.Rows.Count > 0) { if (MessageBox.Show("���� ��� ���������������� ����������. �� ����� ������� ��������� ��������?", "������", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } try { switch (cbNxtRound.SelectedIndex) { case 0: ResultListSpeed.SecondQf(listID, cn); return; case 1: ResultListSpeed.Pairing(listID, cn, false, true); return; default: MessageBox.Show("����������, �������� �����"); return; } } catch (Exception ex) { MessageBox.Show("������ �������� ���������� ��������� �� ��������� �����.\r\n" + ex.Message); } }
protected override void ds_SetOneRouteEvent(object sender, SetOneRouteResultEventArgs e) { if (sender == null || !(sender is DataFromSystem)) { return; } DataFromSystem ds = (DataFromSystem)sender; if (e.Route == 1) { leftRoute1.Text = e.Res; if (EnterFirstRoute()) { SetEditMode(false); ResultListSpeed.RefreshTable(listID, baseIID, RefreshData, cn, CR); fromEvent = true; try { SetNextClimber(); } finally { fromEvent = false; } if (leftIID.Text.Length > 0 && leftName.Text.Length > 0) { ds.Route1 = leftIID.Text + " " + leftName.Text + " (��.� " + leftStart.Text + ")"; } else { ds.Route1 = ""; } } } else if (e.Route == 2 && IFSC_WR && (e.Res.IndexOf("�/�") > -1)) { string iidLeft = leftIID.Text, resLeft = leftRoute1.Text, res2left = leftRoute2.Text, sumLeft = leftSum.Text; leftIID.Text = lblIID.Text; leftRoute1.Text = e.Res; if (EnterFirstRoute(true)) { SetEditMode(false); ResultListSpeed.RefreshTable(listID, baseIID, RefreshData, cn, CR); fromEvent = true; try { SetNextClimber(); } finally { fromEvent = false; } if (!String.IsNullOrEmpty(lblIID.Text) && !String.IsNullOrEmpty(lblName.Text)) { ds.Route2 = lblIID.Text + " " + lblName.Text + " (��.� " + lblStart.Text + ")"; } else { ds.Route2 = String.Empty; } } } }
private void DoTranAction(int climberID, string climberName, TransactionAction action, byte routeToClean) { long?activeTranID, nextTranID, toCheck; try { ResultListSpeed.GetSpeedTransactions(climberID, listID, out activeTranID, out nextTranID, cn); toCheck = (action == TransactionAction.ROLLBACK) ? activeTranID : nextTranID; string message = (action == TransactionAction.ROLLBACK) ? "��������" : "�������"; if (toCheck == null || !toCheck.HasValue) { MessageBox.Show(this, "���������� " + message + " ���������"); return; } if (MessageBox.Show(this, "�� �������, ��� ������ " + message + " ��������� �������� ��������� (" + climberName + ")?", message + " ���������?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No) { return; } SqlTransaction tran = cn.BeginTransaction(); try { bool res; if (action == TransactionAction.ROLLBACK) { res = StaticClass.RollbackTransaction(toCheck.Value, cn, tran); } else { res = StaticClass.RestoreLogicTransaction(toCheck.Value, cn, tran); } if (res) { ResultListSpeed.RefreshTable(listID, baseIID, RefreshData, cn, CR, tran, false); tran.Commit(); RefreshData(); ClearClimberOnRoute(routeToClean); } else { MessageBox.Show("���������� ������� ����������� ���������� ������� SQL Server"); tran.Rollback(); } } catch (Exception ex) { try { tran.Rollback(); } catch { } throw ex; } } catch (Exception ex) { MessageBox.Show("������ ���������� �������:\r\n" + ex.Message); } }
private void rbSystem_CheckedChanged(object sender, EventArgs e) { if (!rbSystem.Checked) { StaticClass.mSpeed.WaitOne(1000, true); try { ResultListSpeed sr = new ResultListSpeed(listID, cn, competitionTitle); sr.WM = this.WM; sr.MdiParent = this.MdiParent; sr.Show(); this.Invoke(new EventHandler(CloseF)); } finally { StaticClass.mSpeed.ReleaseMutex(); } } }
private static void SetTransactionButtonsEnabled(Control labelControl, Control rollback, Control restore, out long?activeTranID, out long?nextTranID, SqlConnection cn, int listID, SqlTransaction tran = null) { activeTranID = null; nextTranID = null; rollback.Enabled = restore.Enabled = false; int clmID; if (!int.TryParse(labelControl.Text, out clmID)) { return; } ResultListSpeed.GetSpeedTransactions(clmID, listID, out activeTranID, out nextTranID, cn, tran); rollback.Enabled = (activeTranID != null && activeTranID.HasValue); restore.Enabled = (nextTranID != null && nextTranID.HasValue); }
private bool EnterBothRoutes(ref string route1, ref string route2, ref string sum, string climberID) { try { if (cn.State != ConnectionState.Open) { cn.Open(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } string cNme = StaticClass.GetClimberName(climberID, this.cn); if (cNme.Length < 1) { return(false); } if (route1.Length > 0 && route2.Length == 0 && sum.Length == 0) { if (MessageBox.Show("�� ������������� ������ ������� ��������� 2�� ������ � ��������� " + cNme + "?", "������� ���������", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } return(ResultListSpeed.ClearClimber(2, climberID, listID, cn)); } //string route1 = tbRoute1.Text, route2 = tbRoute2.Text, sum = tbSum.Text; long r1 = 0, r2 = 0, nSum = 0; if ((!String.IsNullOrEmpty(route1) || UseBestRoute) && !String.IsNullOrEmpty(route2)) { r1 = ResultListSpeed.ParseString(ref route1); //if (r1 >= 6000000) // return EnterFirstRoute(); r2 = ResultListSpeed.ParseString(ref route2, true); if (UseBestRoute) { nSum = Math.Min(r1, r2); sum = (r1 < r2) ? route1 : route2; } else if (r2 < 6000000) { nSum = r1 + r2; sum = ResultListSpeed.CreateString(nSum / 100); } else { if (baseIID > 0) { r2 = 6000000; } nSum = r1 + r2; sum = "*" + route1; } } else { bool b = false; if (route2 != "" && sum != "") { route1 = route2; b = true; } if (route1 != "" && sum != "") { r1 = ResultListSpeed.ParseString(ref route1); nSum = ResultListSpeed.ParseString(ref sum, true); if (r1 < 6000000) { if (nSum < 6000000) { r2 = nSum - r1; route2 = ResultListSpeed.CreateString(r2 / 100); } else { if (baseIID > 0) { nSum = 6000000; } r2 = nSum; route2 = sum; nSum = r1 + r2; sum = "*" + route1; } } else { if (baseIID > 0) { r1 = 6000000; } nSum = 2 * r1; r2 = r1; sum = route1; route2 = ""; } if (b) { long nTmp = r1; string rTmp = route1; route1 = route2; r1 = r2; route2 = rTmp; r2 = nTmp; } } } /*tbRoute1.Text = route1; * tbRoute2.Text = route2; * tbSum.Text = sum;*/ if (!UseBestRoute && (nSum < r1 || nSum < r2)) { MessageBox.Show("��������� ������������ ����� �����"); return(false); } int prevPos = 0; cmd.Parameters.Clear(); //if (baseIID > 0) //{ // cmd.CommandText = "SELECT pos FROM speedResults WHERE (list_id=" + baseIID.ToString() + ") AND (climber_id=" + // climberID + ")"; // try { prevPos = Convert.ToInt32(cmd.ExecuteScalar()); } // catch { prevPos = 99; } //} cmd.CommandText = "UPDATE speedResults SET res=@res,route1=@r1,route1_text=@r1t,route2=@r2," + "route2_text=@r2t, resText=@rt WHERE (list_id=" + listID.ToString() + ") AND (climber_id=" + climberID + ")"; cmd.Parameters.Add("@res", SqlDbType.BigInt); cmd.Parameters[0].Value = nSum + prevPos; cmd.Parameters.Add("@r1", SqlDbType.BigInt); cmd.Parameters[1].Value = r1; cmd.Parameters.Add("@r2", SqlDbType.BigInt); cmd.Parameters[2].Value = r2; cmd.Parameters.Add("@rt", SqlDbType.VarChar); cmd.Parameters[3].Value = sum; cmd.Parameters.Add("@r1t", SqlDbType.VarChar); cmd.Parameters[4].Value = route1; cmd.Parameters.Add("@r2t", SqlDbType.VarChar); cmd.Parameters[5].Value = route2; try { cmd.ExecuteNonQuery(); cmd.CommandText = "UPDATE lists SET nowClimbing3 = " + climberID + ",nowClimbingTmp = NULL WHERE iid = " + listID.ToString(); cmd.ExecuteNonQuery(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
private bool EnterFirstRoute(bool swapRoutes = false) { try { if (cn.State != ConnectionState.Open) { cn.Open(); } } catch (Exception ex) { MessageBox.Show("������ ��������� ���������� � ��\r\n" + ex.Message); return(false); } string route1 = leftRoute1.Text; if (route1.Length < 1) { string cNme = StaticClass.GetClimberName(leftIID.Text, this.cn); if (cNme.Length < 1) { return(false); } if (MessageBox.Show("�� ������������� ������ ������� ��������� 1�� ������ � ��������� " + cNme + "?", "������� ���������", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } return(ResultListSpeed.ClearClimber(1, leftIID.Text, this.listID, cn)); } long r1 = ResultListSpeed.ParseString(ref route1); leftRoute1.Text = route1; SqlCommand cmd = new SqlCommand(); if (r1 >= 6000000 && (!UseBestRoute || route1.ToLower().IndexOf("�/�") > -1)) { string rs2 = ""; string rsSum = route1; string toSet1, toSet2; if (swapRoutes) { toSet1 = rs2; toSet2 = route1; } else { toSet1 = route1; toSet2 = rs2; } return(EnterBothRoutes(ref toSet1, ref toSet2, ref rsSum, leftIID.Text)); } string sRouteN = swapRoutes ? "route2" : "route1"; cmd.CommandText = "UPDATE speedResults SET " + sRouteN + "=@r1," + sRouteN + "_text=@r1t "; if (UseBestRoute) { cmd.CommandText += ",res=@r1, resText=@r1t "; } cmd.CommandText += " WHERE (list_id=" + listID.ToString() + ") AND (climber_id=" + leftIID.Text + ")"; cmd.Parameters.Clear(); cmd.Parameters.Add("@r1", SqlDbType.BigInt); cmd.Parameters[0].Value = r1; cmd.Parameters.Add("@r1t", SqlDbType.VarChar); cmd.Parameters[1].Value = route1; try { cmd.Connection = cn; cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("������ ����� ���������� �� 1 ������\r\n" + ex.Message); return(false); } sRouteN = swapRoutes ? "Tmp" : String.Empty; cmd.CommandText = "UPDATE lists SET nowClimbing" + sRouteN + " = NULL WHERE iid = " + listID.ToString(); try { cmd.ExecuteNonQuery(); } catch { } return(true); }
protected override void btnEdit_Click(object sender, EventArgs e) { if (btnEdit.Text == "������") { SetEditMode(true); return; } bool error = false; bool br = false; Dictionary <string, string> valLeft = null, valRight = null; int nTmp; long?resIdLeft, resIdRight; try { if (int.TryParse(leftIID.Text, out nTmp)) { resIdLeft = ResultListSpeed.GetClimbersResSpeed(nTmp, listID, cn, out valLeft); } else { resIdLeft = null; } } catch { resIdLeft = null; } try { if (int.TryParse(lblIID.Text, out nTmp)) { resIdRight = ResultListSpeed.GetClimbersResSpeed(nTmp, listID, cn, out valRight); } else { resIdRight = null; } } catch { resIdRight = null; } try { if (leftIID.Text.Length > 0) { //if (leftRoute1.Text.Length > 0) //{ if (leftRoute1.Text.IndexOf("�/�") > -1 || !UseBestRoute && (leftRoute1.Text.IndexOf("����") > -1 || leftRoute1.Text.IndexOf("�����") > -1)) { leftRoute2.Text = leftSum.Text = ""; } if (leftRoute2.Text.Length > 0 || leftSum.Text.Length > 0) { if (leftSum.Text.IndexOf("����") > -1 || leftSum.Text.IndexOf("�/�") > -1 || leftSum.Text.IndexOf("�����") > -1) { leftSum.Text = ""; ResultListSpeed.ClearClimber(3, leftIID.Text, listID, cn); error = !EnterFirstRoute(); } else { if (leftRoute2.Text.Length > 0 && leftSum.Text.Length > 0) { leftSum.Text = ""; } error = !EnterBothRoutes(leftIID, leftRoute1, leftRoute2, leftSum); } } else { error = !EnterFirstRoute(); } //} //else //{ // error = true; // MessageBox.Show("������� ��������� �� 1 ������"); //} } if (lblIID.Text.Length > 0) { //if (rightRoute2.Text.Length > 0 || rightSum.Text.Length > 0) error = error || (!(br = EnterBothRoutes())); //else //{ // error = true; // MessageBox.Show("������� ��������� 2 ������ ��� �����"); //} } } catch (Exception ex) { error = true; MessageBox.Show("������ ����� �����������\r\n" + ex.Message); } if (br && (!error)) { SqlCommand cmd = new SqlCommand(); } if (!error) { SetEditMode(false); ResultListSpeed.RefreshTable(listID, baseIID, RefreshData, cn, CR); if (resIdLeft != null && resIdLeft.HasValue || resIdRight != null && resIdRight.HasValue) { SqlTransaction tran = cn.BeginTransaction(); try { Dictionary <string, string> newVals; if (resIdLeft != null && resIdLeft.HasValue) { ResultListSpeed.GetClimbersResSpeed(resIdLeft.Value, cn, out newVals, tran); ResultListSpeed.AddTransaction(resIid: resIdLeft.Value, oldValues: valLeft, newValues: newVals, cn: cn, tran: tran); } if (resIdRight != null && resIdRight.HasValue) { ResultListSpeed.GetClimbersResSpeed(resIdRight.Value, cn, out newVals, tran); ResultListSpeed.AddTransaction(resIid: resIdRight.Value, oldValues: valRight, newValues: newVals, cn: cn, tran: tran); } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch { } MessageBox.Show(this, "������ ���������� ������� ����������:\r\n" + ex.Message); } } RefreshData(); } }