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); }