public void Material_FindFound() { //This object must exist on BD aMatID = 51; aMatName = "Epic MTB"; aMatModel = "Epic Comp"; aMatBrand = "Specialized"; aMatSize = "17"; aMatWeight = 12.5M; aMatBuyDate = Convert.ToDateTime("01/04/2011"); aMatCost = (SqlMoney)600.00F; aMatInitTime = 0; aMatInitDist = 2500.000M; aMatRecTime = "1000:00:00"; aMatRecDist = 10000.000M; aMatBuyMemo = "Comprada"; aUserID = 85; Material aMatToLoad = new Material(); aMatToLoad.LoadData(aMatID, aMatName, aMatModel, aMatBrand, aMatSize, aMatWeight, aMatBuyDate, aMatCost, aMatInitTime, aMatInitDist, aMatRecTime, aMatRecDist, aMatBuyMemo, aUserID); aMatToLoad = aMatToLoad.findMatByMatID(connString, aMatID); Assert.AreEqual(aMatID, aMatToLoad.MatID); Assert.AreEqual(aMatName, aMatToLoad.MatName); Assert.AreEqual(aMatModel, aMatToLoad.MatModel); Assert.AreEqual(aMatBrand, aMatToLoad.MatBrand); Assert.AreEqual(aMatSize, aMatToLoad.MatSize); Assert.AreEqual(aMatWeight, aMatToLoad.MatWeight); Assert.AreEqual(aMatBuyDate, aMatToLoad.MatBuyDate); Assert.AreEqual(aMatCost, aMatToLoad.MatCost); Assert.AreEqual(aMatInitTime, aMatToLoad.MatInitTime); Assert.AreEqual(aMatInitDist, aMatToLoad.MatInitDist); Assert.AreEqual(aMatRecTime, aMatToLoad.MatRecTime); Assert.AreEqual(aMatRecDist, aMatToLoad.MatRecDist); Assert.AreEqual(aMatBuyMemo, aMatToLoad.MatBuyMemo); Assert.AreEqual(aUserID, aMatToLoad.UserID); }
private void tsBtnSave_Click(object sender, EventArgs e) { string mensaje = "¿Desea guardar la ficha creada?"; DialogResult delMat = MessageBox.Show(mensaje, "Atención", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (delMat == DialogResult.OK) { //Load data into model. Material aMat = new Material(); aMat = LoadObject(); this.Validate(); this.materialsBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.trainITDataSet); setNormalMode(); fillDataForMaterial(); MessageBox.Show("Ficha guardada corectamente"); } }
private Material LoadObject() { //Loads the object in the screen into the model. Material aMat = new Material(); try { aMat.MatID = Convert.ToInt64(txtID.Text); } catch { aMat.MatID = -1; } aMat.MatName = txtName.Text; aMat.MatModel = txtModel.Text; aMat.MatBrand = txtBrand.Text; aMat.MatSize = txtSize.Text; if (mtxtWeight.Text == "") aMat.MatWeight = 0.00M; else { try { aMat.MatWeight = Convert.ToDecimal(mtxtWeight.Text); } catch (Exception) { aMat.MatWeight = 0.00M; } } aMat.MatBuyDate = dtpBuyDate.Value; if (txtCost.Text == "") aMat.MatCost = (SqlMoney)0.00F; else { try { aMat.MatCost = (SqlMoney)Convert.ToDouble(txtCost.Text); } catch (Exception) { aMat.MatCost = (SqlMoney)0.00F; } } try { aMat.MatInitTime = Time.ConvertStringTimeToDouble(mtxtInitTimeShort.Text); } catch (Exception) { aMat.MatInitTime = 0; } if (txtInitDist.Text == "") aMat.MatInitDist = 0.000M; else { try { aMat.MatInitDist = Convert.ToDecimal(txtInitDist.Text); } catch (Exception) { throw; } } aMat.MatRecTime = mtxtRecTime.Text; if (txtRecDist.Text == "") aMat.MatRecDist = 0.000M; else { try { aMat.MatRecDist = Convert.ToDecimal(txtRecDist.Text); } catch (Exception) { throw; } } aMat.MatBuyMemo = txtBuyMemo.Text; aMat.UserID = userIDWorking; return aMat; }
public Material LoadDataFromView(string aMatID, string aMatName, string aMatModel, string aMatBrand, string aMatSize, string aMatWeight, string aMatBuyDate, string aMatCost, string aMatInitTime, string aMatInitDist, string aMatRecTime, string aMatRecDist, string aMatBuyMemo, string aUserID) { Material aM = new Material(); bool sigue = true; try { matID = Convert.ToInt64(aMatID); } catch (Exception) { sigue = false; } if (sigue) { try { matWeight = Convert.ToDecimal(aMatWeight); } catch (Exception) { sigue = false; } } if (sigue) { try { matBuyDate = Convert.ToDateTime(aMatBuyDate); } catch (Exception) { sigue = false; } } if (sigue) { try { matCost = Convert.ToDecimal(aMatCost); } catch (Exception) { sigue = false; } } if (sigue) { try { matInitDist = Convert.ToDecimal(aMatInitDist); } catch (Exception) { sigue = false; } } if (sigue) { try { matRecDist = Convert.ToDecimal(aMatRecDist); } catch (Exception) { sigue = false; } } if (sigue) { try { userID = Convert.ToInt64(aUserID); } catch (Exception) { sigue = false; } } if (sigue) { matName = aMatName; matModel = aMatModel; matBrand = aMatBrand; matSize = aMatSize; matInitTime = Time.ConvertStringTimeToLong(aMatInitTime); matRecTime = aMatRecTime; matBuyMemo = aMatBuyMemo; } else aM.Reset(); return aM; }
public Material findMatByMatID(string connString, Int64 matID) { //Find a Material by MatID, returns object found or an object with ID=-1 if not found Material aMaterial = new Material(); using (SqlConnection conn = new SqlConnection(connString)) { string query = "select * from Materials where MatID = @matID"; using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add(new SqlParameter("@matID", SqlDbType.BigInt)); cmd.Parameters["@matID"].Value = matID; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // Create a buffer to hold the bytes, and then long len = reader.GetBytes(14, 0, null, 0, 0); Byte[] image = new Byte[len]; // read the bytes from the DataTableReader. reader.GetBytes(14, 0, image, 0, (int)len); aMaterial.LoadData(reader.GetInt64(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetDecimal(5), Convert.ToDateTime(reader.GetDateTime(6)), reader.GetSqlMoney(7), reader.GetDouble(8), reader.GetDecimal(9), reader.GetString(10), reader.GetDecimal(11), reader.GetString(12), reader.GetInt64(13)); } reader.Close(); } } return aMaterial; }
public void Material_LoadFromData() { Material aMatToLoad = new Material(); aMatToLoad.LoadData(aMatID,aMatName,aMatModel,aMatBrand,aMatSize,aMatWeight,aMatBuyDate,aMatCost,aMatInitTime,aMatInitDist, aMatRecTime, aMatRecDist, aMatBuyMemo, aUserID); Assert.AreEqual(aMatID, aMatToLoad.MatID); Assert.AreEqual(aMatName, aMatToLoad.MatName); Assert.AreEqual(aMatModel, aMatToLoad.MatModel); Assert.AreEqual(aMatBrand, aMatToLoad.MatBrand); Assert.AreEqual(aMatSize, aMatToLoad.MatSize); Assert.AreEqual(aMatWeight, aMatToLoad.MatWeight); Assert.AreEqual(aMatBuyDate, aMatToLoad.MatBuyDate); Assert.AreEqual(aMatCost, aMatToLoad.MatCost); Assert.AreEqual(aMatInitTime, aMatToLoad.MatInitTime); Assert.AreEqual(aMatInitDist, aMatToLoad.MatInitDist); Assert.AreEqual(aMatRecTime, aMatToLoad.MatRecTime); Assert.AreEqual(aMatRecDist, aMatToLoad.MatRecDist); Assert.AreEqual(aMatBuyMemo, aMatToLoad.MatBuyMemo); Assert.AreEqual(aUserID, aMatToLoad.UserID); }
public void Material_FindNotFound() { Material aMatToLoad = new Material(); aMatToLoad.LoadData(aMatID, aMatName, aMatModel, aMatBrand, aMatSize, aMatWeight, aMatBuyDate, aMatCost, aMatInitTime, aMatInitDist, aMatRecTime, aMatRecDist, aMatBuyMemo, aUserID); aMatToLoad = aMatToLoad.findMatByMatID(connString, aMatID); Assert.AreEqual(-1, aMatToLoad.MatID); }