public void updateLabel(System.Windows.Forms.Label label) { for (int i = 0; i < 100; i++) { Thread.Sleep(200); label.Text = i.ToString(); label.Update(); } }
private void CompareResults_Update_Ds_Str_Exception(DataSet dsResultException,ref Sys.Data.Common.DbDataAdapter dbDA) { int NumberOfAffectedRows = 0; Exception exp = null; Exception e = null; // --------- check for DBConcurrencyException /UniqueConstraint ----------------- // call AcceptChanges after each exception check in order to make sure that we check only the the current row try { BeginCase("DBConcurrencyException - Delete"); dsResultException.Tables[0].Rows.Find(9994).Delete(); //no row with row version delete exists - records affected = 0 NumberOfAffectedRows = -1; try {NumberOfAffectedRows = dbDA.Update(dsResultException,dsResultException.Tables[0].TableName);} catch (DBConcurrencyException dbExp){e = dbExp;} Compare(e.GetType(),typeof(DBConcurrencyException)); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null; e = null;} try { BeginCase("Number Of Affected Rows - Delete Exception"); Compare(NumberOfAffectedRows ,-1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dsResultException.AcceptChanges(); try { BeginCase("DBConcurrencyException - Update"); dsResultException.Tables[0].Rows.Find(9995)["Title"] = "Jack the ripper"; //no row with row version Update exists - records affected = 0 NumberOfAffectedRows = -1; try {NumberOfAffectedRows = dbDA.Update(dsResultException,dsResultException.Tables[0].TableName);} catch (DBConcurrencyException dbExp){e = dbExp;} Compare(e.GetType(),typeof(DBConcurrencyException)); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null; e = null;} try { BeginCase("Number Of Affected Rows - Update Exception"); Compare(NumberOfAffectedRows ,-1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dsResultException.AcceptChanges(); try { BeginCase("DBConcurrencyException - Insert"); dsResultException.Tables[0].Rows.Add(new object[] {9996,"Ofer","Borshtein","Insert"}); //no row with row version Insert exists - records affected = 0 NumberOfAffectedRows = -1; try {NumberOfAffectedRows = dbDA.Update(dsResultException,dsResultException.Tables[0].TableName);} catch (Exception dbExp){e = dbExp;} //throw Sys.Exception Compare(e != null ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null; e = null;} try { BeginCase("Number Of Affected Rows - Insert Exception"); Compare(NumberOfAffectedRows ,-1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dsResultException.AcceptChanges(); }
protected void DbDataAdapter_Update_Ds_Str(Sys.Data.Common.DbDataAdapter dbDA) { int NumberOfAffectedRows = 0; Exception exp = null; // --------- get data from DB ----------------- DataSet ds = PrepareDBData_Update(dbDA); // --------- prepare dataset for update method ----------------- DataSet dsDB1 = ds.Copy(); // --------- prepare dataset for DBConcurrencyException ----------------- DataSet dsDB2 = ds.Copy(); //update dataset dsDB2.Tables[0].Rows.Add(new object[] {9994,"Ofer", "Borshtein", "Delete"}); dsDB2.Tables[0].Rows.Add(new object[] {9995,"Ofer", "Borshtein", "Update"}); dsDB2.Tables[0].Rows.Find(9996).Delete(); dsDB2.AcceptChanges(); dsDB1.Tables[0].Rows.Add(new object[] {9991,"Ofer","Borshtein","Insert"}); dsDB1.Tables[0].Rows.Find(9992).Delete(); dsDB1.Tables[0].Rows.Find(9993)["Title"] = "Jack the ripper"; //execute update to db NumberOfAffectedRows = dbDA.Update(dsDB1,dsDB1.Tables[0].TableName); try { BeginCase("Number Of Affected Rows"); Compare(NumberOfAffectedRows ,3 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //get result from db in order to check them DataSet dsExpected = new DataSet(); //ds.Reset(); dbDA.Fill(dsExpected); dsExpected.Tables[0].PrimaryKey = new DataColumn[] {dsExpected.Tables[0].Columns["EmployeeID"]}; CompareResults_Update(dsDB1,dsDB2,ref dbDA); CompareResults_Update_Ds_Str_Exception(dsDB2,ref dbDA); //Create rows which not exists in the DB but exists in the DS with row state = deleted //this will cause the Update to fail. dsDB1.Tables[0].Rows.Add(new object[] {9997,"Ofer", "Borshtein", "Delete"}); dsDB1.Tables[0].Rows.Add(new object[] {9998,"Ofer", "Borshtein", "Delete"}); dsDB1.AcceptChanges(); dsDB1.Tables[0].Rows.Find(9997).Delete(); dsDB1.Tables[0].Rows.Find(9998).Delete(); //Check Sys.Data.DBConcurrencyException //The exception that is thrown by the DataAdapter during the update operation if the number of rows affected equals zero. try { BeginCase("Check DBConcurrencyException"); try { NumberOfAffectedRows = dbDA.Update(dsDB1,dsDB1.Tables[0].TableName); } catch (DBConcurrencyException ex) {exp=ex;} Compare(exp.GetType(),typeof(DBConcurrencyException) ); exp = null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected void DataAdapter_ContinueUpdateOnError(Sys.Data.Common.DbDataAdapter dbDA) { /* !!!!!! Not working (TestName "ContinueUpdateOnError - true, check value 2")!!!!! If ContinueUpdateOnError is set to true, no exception is thrown when an error occurs during the update of a row. The update of the row is skipped and the error information is placed in the RowError property of the row in error. The DataAdapter continues to update subsequent rows. If ContinueUpdateOnError is set to false, an exception is thrown when an error occurs during the update of a row. */ Exception exp = null; IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; IDbConnection IConn = ICmd.Connection; IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; PrepareDataForTesting( MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString); IConn.Open(); //get the total rows count ICmd.CommandText = "SELECT Count(*) FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; int ExpectedRows = Sys.Convert.ToInt32(ICmd.ExecuteScalar()); try { BeginCase("Check that Expected rows count > 0"); Compare(ExpectedRows > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; DataSet dsMem = new DataSet(); //Disconected dataset DataSet dsDB = new DataSet(); //DataBase data dbDA.AcceptChangesDuringFill = true; //get data from DB try { BeginCase("Execute Fill - check return rows count"); int i = dbDA.Fill(dsMem); Compare(i ,ExpectedRows ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //update data with invalid information (Max. length for Phone is 24) // 123456789012345678901234 string newValue1 = "Very Long String That Will Raise An Error Yep!"; string oldValue1 = dsMem.Tables[0].Rows[3]["Phone"].ToString(); string oldValue2 = dsMem.Tables[0].Rows[4]["Phone"].ToString(); string newValue2 = "03-1234"; dsMem.Tables[0].Rows[3]["Phone"] = newValue1; dsMem.Tables[0].Rows[4]["Phone"] = newValue2; dbDA.ContinueUpdateOnError = true; //will not throw exception try { BeginCase("ContinueUpdateOnError - true, check exception"); try { dbDA.Update(dsMem); } catch(Exception ex){exp = ex;} Compare(exp == null,true); exp = null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dbDA.Fill(dsDB); //get data from DB to check the update operation try { BeginCase("ContinueUpdateOnError - true, check RowError"); Compare(dsMem.Tables[0].Rows[3].RowError.Length > 0 , true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("ContinueUpdateOnError - true, check value 1"); Compare(dsDB.Tables[0].Rows[3]["Phone"] , oldValue1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} /* - Test excluded, it is not working in .NET too! //should continue the update try { BeginCase("ContinueUpdateOnError - true, check value 2"); Compare(dsDB.Tables[0].Rows[4]["Phone"] , newValue2); //--------- NOT WORKING !!! ----------- } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} */ dsMem.Reset(); dsDB.Reset(); dbDA.Fill(dsMem); dsMem.Tables[0].Rows[3]["Phone"] = newValue1 ; dsMem.Tables[0].Rows[4]["Phone"] = newValue2; dbDA.ContinueUpdateOnError = false; try { BeginCase("ContinueUpdateOnError - false, check exception"); try { dbDA.Update(dsMem); } catch(Exception ex){exp = ex;} Compare(exp == null,false); exp = null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dbDA.Fill(dsDB); //get data from DB to check the update operation try { BeginCase("ContinueUpdateOnError - false,check RowError"); Compare(dsMem.Tables[0].Rows[3].RowError.Length > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("ContinueUpdateOnError - false,check value 1"); Compare(dsDB.Tables[0].Rows[3]["Phone"] , oldValue1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("ContinueUpdateOnError - false,check value 2"); Compare(dsDB.Tables[0].Rows[4]["Phone"] , oldValue2 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (Status) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + PanelDescription + "', composition='" + PanelComposition + "', standard='" + PanelStandard + "', color='" + PanelColor + "', size=" + PanelSize + ", sizeUnits='" + PanelSizeUnits + "', maxWidth=" + PanelMaxWidth + ", widthUnits='" + MaxWidthUnits + "', maxLength='" + PanelMaxLength + "', usdPrice=" + UsdPrice + ", cadPrice=" + CadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (Status) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET width =" + VinylRollWidth + ", widthUnits='" + VinylRollWidthUnits + "', weight=" + VinylRollWeight + ", weightUnits='" + VinylRollWeightUnits + "', usdPrice=" + UsdPrice + ", cadPrice=" + CadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
public static void AnimateControl(System.Windows.Forms.Control control, bool show, int animationTime, Rectangle rectStart, Rectangle rectEnd) { control.Bounds = rectStart; if (!control.Visible) control.Visible = true; bool directSet = false; TimeSpan time = new TimeSpan(0, 0, 0, 0, animationTime); int dxLoc, dyLoc; int dWidth, dHeight; dxLoc = dyLoc = dWidth = dHeight = 0; if (rectStart.Left == rectEnd.Left && rectStart.Top == rectEnd.Top && rectStart.Right == rectEnd.Right && rectStart.Height != rectEnd.Height) { dHeight = (rectEnd.Height > rectStart.Height ? 1 : -1); } else if (rectStart.Left == rectEnd.Left && rectStart.Top == rectEnd.Top && rectStart.Bottom == rectEnd.Bottom && rectStart.Width != rectEnd.Width) { dWidth = (rectEnd.Width > rectStart.Width ? 1 : -1); } else if (rectStart.Right == rectEnd.Right && rectStart.Top == rectEnd.Top && rectStart.Bottom == rectEnd.Bottom && rectStart.Width != rectEnd.Width) { dxLoc = (rectEnd.Width > rectStart.Width ? -1 : 1); dWidth = (rectEnd.Width > rectStart.Width ? 1 : -1); } else if (rectStart.Right == rectEnd.Right && rectStart.Left == rectEnd.Left && rectStart.Bottom == rectEnd.Bottom && rectStart.Height != rectEnd.Height) { dyLoc = (rectEnd.Height > rectStart.Height ? -1 : 1); dHeight = (rectEnd.Height > rectStart.Height ? 1 : -1); } else if (rectEnd.X != rectStart.X && rectEnd.Y == rectStart.Y && rectStart.Height == rectEnd.Height && rectEnd.Width == rectStart.Width) { // Simple to left move of the control dxLoc = (rectEnd.X > rectStart.X ? 1 : -1); } else if (rectEnd.Y != rectStart.Y && rectEnd.X == rectStart.X && rectStart.Height == rectEnd.Height && rectEnd.Width == rectStart.Width) { // Simple to left move of the control dxLoc = (rectEnd.Y > rectStart.Y ? 1 : -1); } else directSet = true; if (directSet) { control.Bounds = rectEnd; } else { int speedFactor = 1; int totalPixels = (rectStart.Width != rectEnd.Width) ? Math.Abs(rectStart.Width - rectEnd.Width) : Math.Abs(rectStart.Height - rectEnd.Height); if (totalPixels == 0 && rectStart.Width == rectEnd.Width && rectStart.Height == rectEnd.Height) { if (rectEnd.X - rectStart.X != 0) totalPixels = Math.Abs(rectStart.X - rectEnd.X); else if (rectEnd.Y - rectStart.Y != 0) totalPixels = Math.Abs(rectStart.Y - rectEnd.Y); } int remainPixels = totalPixels; DateTime startingTime = DateTime.Now; Rectangle rectAnimation = rectStart; while (rectAnimation != rectEnd) { DateTime startPerMove = DateTime.Now; rectAnimation.X += dxLoc * speedFactor; rectAnimation.Y += dyLoc * speedFactor; rectAnimation.Width += dWidth * speedFactor; rectAnimation.Height += dHeight * speedFactor; if (Math.Sign(rectEnd.X - rectAnimation.X) != Math.Sign(dxLoc)) rectAnimation.X = rectEnd.X; if (Math.Sign(rectEnd.Y - rectAnimation.Y) != Math.Sign(dyLoc)) rectAnimation.Y = rectEnd.Y; if (Math.Sign(rectEnd.Width - rectAnimation.Width) != Math.Sign(dWidth)) rectAnimation.Width = rectEnd.Width; if (Math.Sign(rectEnd.Height - rectAnimation.Height) != Math.Sign(dHeight)) rectAnimation.Height = rectEnd.Height; control.Bounds = rectAnimation; if (control.Parent != null) control.Parent.Update(); else control.Update(); remainPixels -= speedFactor; while (true) { TimeSpan elapsedPerMove = DateTime.Now - startPerMove; TimeSpan elapsedTime = DateTime.Now - startingTime; if ((time - elapsedTime).TotalMilliseconds <= 0) { speedFactor = remainPixels; break; } else { if ((int)(time - elapsedTime).TotalMilliseconds == 0) speedFactor = 1; else { try { speedFactor = remainPixels * (int)elapsedPerMove.TotalMilliseconds / (int)((time - elapsedTime).TotalMilliseconds); } catch { } } } if (speedFactor >= 1) break; } } } if (!show) { control.Visible = false; control.Bounds = rectStart; } }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (InsulatedFloorStatus) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + InsulatedFloorDescription + "', composition='" + InsulatedFloorComposition + "', size=" + InsulatedFloorSize + ", sizeUnits='" + InsulatedFloorSizeUnits + "', maxWidth=" + InsulatedFloorMaxWidth + ", widthUnits='" + InsulatedFloorMaxWidthUnits + "', maxLength='" + InsulatedFloorMaxLength + "', usdPrice=" + InsulatedFloorUsdPrice +", cadPrice=" + InsulatedFloorCadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string partNum) { int bitStatus; if (SchematicStatus) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE tblSchematics SET description ='" + SchematicDescription + "', usdPrice=" + SchematicUsdPrice + ", cadPrice=" + SchematicCadPrice + ", status=" + bitStatus + " WHERE schematicNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string partNum) { dataSource.UpdateCommand = "UPDATE tblSchematicParts SET usdPrice=" + PartUsdPrice + ", cadPrice=" + PartCadPrice + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
public void updateLabel(System.Windows.Forms.Label textlabel) { while (timerIsRunning) { if (textlabel.InvokeRequired) //if the thread acessing the text label is not the same as the thread that created the text label { textlabel.Invoke((MethodInvoker)(() => textlabel.Text = this.ToString())); //Runs this command as if it was running in the parent thread textlabel.Invoke((MethodInvoker)(() => textlabel.Update())); //Runs this command as if it was running in the parent thread //Invoke command referenced from http://tinyurl.com/m6nz8n8 } else { textlabel.Text = this.ToString(); textlabel.Update(); } if (seconds > 0) { seconds--; } else { if (minutes > 0) { minutes--; seconds = 59; } else { if (hours > 0) { hours--; minutes = 59; seconds = 59; } else { this.stopTimer(); } } } System.Threading.Thread.Sleep(1000); //delay for one second (1000 miliseconds) } }
public static string Learn(System.Windows.Forms.TextBox status) { CancelLearn = false; string irCode = ""; Controller mc = new Controller(); learnCompletedEventArgs = null; mc.Learning += new UsbUirt.Controller.LearningEventHandler(mc_Learning); mc.LearnCompleted += new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted); try { try { mc.LearnAsync(CodeFormat.Pronto, LearnCodeModifier.None, learnCompletedEventArgs); } catch (Exception ex) { throw; } while (learnCompletedEventArgs == null) { string s = Console.ReadLine(); if (CancelLearn == true) { if (learnCompletedEventArgs == null) { mc.LearnAsyncCancel(learnCompletedEventArgs); Thread.Sleep(1000); break; } } else { status.Text = LearnState; status.Update(); Thread.Sleep(100); } } if (learnCompletedEventArgs != null && learnCompletedEventArgs.Cancelled == false && learnCompletedEventArgs.Error == null) { irCode = learnCompletedEventArgs.Code; } } finally { mc.Learning -= new UsbUirt.Controller.LearningEventHandler(mc_Learning); mc.LearnCompleted -= new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted); } return irCode; }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (Status) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + ExtrusionDescription + "', size=" + ExtrusionSize + ", sizeUnits='" + SizeUnits + "', extrusionAngleA=" + AngleA + ", angleAUnits='" + AngleAUnits + "', extrusionAngleB=" + AngleB + ", angleBUnits='" + AngleBUnits + "', extrusionAngleC=" + AngleC + ", angleCUnits='" + AngleCUnits + "', maxLength=" + ExtrusionMaxLength + ", lengthUnits='" + MaxLengthUnits + "', usdPrice=" + UsdPrice + ", cadPrice=" + CadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (Sunrail300Status) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + Sunrail300Description + "', maxLengthFeet=" + Sunrail300MaxLengthFeet + ", maxLengthInches=" + Sunrail300MaxLengthInches + ", usdPrice=" + Sunrail300UsdPrice + ", cadPrice=" + Sunrail300CadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (Sunrail300AccessoriesStatus) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + Sunrail300AccessoriesDescription + "', usdPrice=" + Sunrail300AccessoriesUsdPrice + ", cadPrice=" + Sunrail300AccessoriesCadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (Status) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + SuncrylicDescription + "', maxLength=" + SuncrylicMaxLength + ", lengthUnits='" + SuncrylicLengthUnits + "', usdPrice=" + UsdPrice + ", cadPrice=" + CadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }
//Database update public void Update(System.Web.UI.WebControls.SqlDataSource dataSource, string table, string partNum) { int bitStatus; if (accessoryStatus) { bitStatus = 1; } else { bitStatus = 0; } dataSource.UpdateCommand = "UPDATE " + table + " SET description ='" + AccessoryDescription + "', packQuantity=" + AccessoryPackQuantity + ", width=" + AccessoryWidth + ", widthUnits='" + AccessoryWidthUnits + "', length=" + AccessoryLength + ", lengthUnits='" + AccessoryLengthUnits + "', size=" + AccessorySize + ", sizeUnits='" + AccessorySizeUnits + "', usdPrice=" + AccessoryUsdPrice + ", cadPrice=" + AccessoryCadPrice + ", status=" + bitStatus + " WHERE partNumber = '" + partNum + "'"; dataSource.Update(); }