DamaiDataSet.ShipmentDetailDataTable CreateNewShipmentDetailDataTable(int id, int productClass) { DamaiDataSet.ShipmentDetailDataTable dt = new DamaiDataSet.ShipmentDetailDataTable(); foreach (DataRowView item in productBindingSource) { DataRow dr = item.Row as DataRow; DamaiDataSet.ProductRow pr = dr as DamaiDataSet.ProductRow; if (pr.Class != productClass) { continue; } DamaiDataSet.ShipmentDetailRow r = dt.NewRow() as DamaiDataSet.ShipmentDetailRow; r.ProductID = pr.ProductID; r.ShipmentID = id; r.Volume = 0; r.ID = Guid.NewGuid(); r.Cost = 0; dt.AddShipmentDetailRow(r); } return(dt); }
private void shipmentDetailDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { DataGridView view = (DataGridView)sender; string cellName = view.Columns[e.ColumnIndex].Name; if (cellName == "dgvCostColumn") { this.costTextBox.Text = CostTotal().ToString(); } else if (cellName == "dgvColumnProductID") { DataGridViewRow dgRow = view.Rows[e.RowIndex]; DataGridViewCell cell = dgRow.Cells[e.ColumnIndex]; if (cell.ValueType != typeof(int)) { return; // IngridentCode是int } if (cell.Value == null || cell.Value == DBNull.Value) { return; } int productID = (int)cell.Value; try { //string str="ID="+code.ToString(); //VEDataSet.IngredientRow[] row = (VEDataSet.IngredientRow[])vEDataSet.Ingredient.Select(str); // var rows = from row in bakeryOrderSet.Product where (row.ProductID == productID) select row; var rows = from row in damaiDataSet.Product where (row.ProductID == productID) select row; if (rows.Count() > 0) { // BakeryOrderSet.ProductRow row = rows.First(); DamaiDataSet.ProductRow row = rows.First(); if (!row.IsTitleCodeNull()) { dgRow.Cells["dgvColumnTitleCode"].Value = row.TitleCode; } } } catch { } } else if (cellName == "dgvColumnVolume") { try { DataGridViewRow dgRow = view.Rows[e.RowIndex]; DataGridViewCell costCell = dgRow.Cells["dgvCostColumn"]; if (costCell.ValueType != typeof(decimal)) { return; // Cost不是decimal,資料庫定義必然被改過了,程式碼失效 } if (costCell.Value == null) { return; } //if (costCell.Value != DBNull.Value) return; // Cost有資料時就不改 DataRowView rowView = dgRow.DataBoundItem as DataRowView; //SQLVEDataSet.ShipmentDetailRow shipmentDetailRow = rowView.Row as SQLVEDataSet.ShipmentDetailRow; DamaiDataSet.ShipmentDetailRow shipmentDetailRow = rowView.Row as DamaiDataSet.ShipmentDetailRow; // 查出食材表中相對應記錄 //var rows = from ro in bakeryOrderSet.Product // where (ro.ProductID == shipmentDetailRow.ProductID) // select ro; var rows = from ro in damaiDataSet.Product where (ro.ProductID == shipmentDetailRow.ProductID) select ro; if (rows.Count() <= 0) { return; } //BakeryOrderSet.ProductRow row = rows.First(); DamaiDataSet.ProductRow row = rows.First(); if (row.IsPriceNull()) { return; } if (row.Price <= 0) { return; // 參考價不合理 } costCell.Value = shipmentDetailRow.Volume * (decimal)row.Price; } catch { } } }