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