protected override bool getRecords(out List <ProductCirculationRecord> records) { records = new List <ProductCirculationRecord>(); int number = this.dataGridView1.RowCount; double num, price, totalPrice, quantityPerPiece; int pieces; bool isQuantityNull = false, isPiecesNull = false; string unit, comment; bool isInputCorrect = true; foreach (DataGridViewRow row in this.dataGridView1.Rows) { object productID = null; int ID = 0; if (ValidateUtility.getLookupValue(row.Cells["product"], out productID) == false || ValidateUtility.getInt(row.Cells["ID"], false, true, out ID) == false || ValidateUtility.getDouble(row.Cells["quantityPerPiece"], false, true, out quantityPerPiece, out isQuantityNull) == false || ValidateUtility.getInt(row.Cells["pieces"], false, true, out pieces, out isPiecesNull) == false || ValidateUtility.getDouble(row.Cells["num"], true, true, out num) == false || ValidateUtility.getString(row.Cells["unit"], false, out unit) == false || ValidateUtility.getDouble(row.Cells["price"], out price) == false || ValidateUtility.getDouble(row.Cells["totalPrice"], out totalPrice) == false || ValidateUtility.getString(row.Cells["comment"], false, out comment) == false) { return(false); } ProductStainlessCirculationRecord record = new ProductStainlessCirculationRecord(); LookupArg arg = ((row.Cells["product"] as DataGridViewLookupCell).EditedValue as LookupArg); record.ProductID = (int)arg.Value; record.ProductName = arg.Text; record.ID = ID; string serial; ValidateUtility.getString(row.Cells["serial"], false, out serial); record.Serial = serial; record.QuantityPerPiece = quantityPerPiece; record.QuantityNull = isQuantityNull; record.Pieces = pieces; record.PiecesNull = isPiecesNull; record.TotalNum = num; record.Unit = unit; record.Price = price; record.TotalPrice = totalPrice; record.Comment = comment; records.Add(record); } return(isInputCorrect); }
private void button_save_Click(object sender, EventArgs e) { if (this.needSave == true) { //List<CharactorValue> values = new List<CharactorValue>(); foreach (DataGridViewRow row in this.dataGridView1.Rows) { CharactorValue value = new CharactorValue(); string name = null; if (ValidateUtility.getString(row.Cells["name"], true, out name) == false) { return; } value.Name = name; value.CharactorId = charactorId; object id = row.Cells["ID"].Value; if (id == null || id.ToString() == "") { value.Id = -1; int idReturn = CharactorValueDao.getInstance().Insert(value); row.Cells["ID"].Value = idReturn; } else { value.Id = int.Parse(id.ToString()); CharactorValueDao.getInstance().Update(value); } //values.Add(value); } /* * foreach (CharactorValue value in values) { * if (value.Id <= 0) * CharactorValueDao.getInstance().Insert(value); * else * CharactorValueDao.getInstance().Update(value); * }*/ this.modify = true; this.needSave = false; this.button_save.Enabled = false; MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }