/// <summary> /// 读取产品详细信息 /// </summary> /// <param name="ProductNumber">产品编号</param> /// <returns></returns> internal Model_WarehouseProductBatchIn ReadProductInfo(string ProductNumber) { Model_WarehouseProductBatchIn m = new Model_WarehouseProductBatchIn(); string sql = " SELECT a.GUID,a.Name,a.Material,a.PackageNumber,Total(b.Quantity) as TotalParts " + " FROM T_ProductInfo_Product a" + " Left join T_Warehouse_Product b ON a.Guid=b.ProductID " + " WHERE a.NUMBER='" + ProductNumber + "' " + " AND a.DELETEMARK ISNULL" + " AND b.DeleteMark ISNULL" ; DataSet ds = new DataSet(); bool flag = new Helper.SQLite.DBHelper().QueryData(sql, out ds); if (flag) { foreach (DataRow dr in ds.Tables[0].Rows) { if (dr["GUID"].ToString().Length < 5) { return(m); } m.Guid = (Guid)dr["GUID"]; m.Number = ProductNumber; m.Name = dr["Name"].ToString(); m.Material = dr["Material"].ToString(); int PerQuantity = 0; int.TryParse(dr["PackageNumber"].ToString(), out PerQuantity); m.PerQuantity = PerQuantity; int TotalParts = 0; int.TryParse(dr["TotalParts"].ToString(), out TotalParts); m.TotalParts = TotalParts; } } return(m); }
private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { object SelectItem = DataGrid.SelectedCells[0].Item; Model_WarehouseProductBatchIn model = this.DataGrid.SelectedCells[0].Item as Model_WarehouseProductBatchIn; string newValue = (e.EditingElement as TextBox).Text.Trim(); string Header = e.Column.Header.ToString(); if (Header == "编号")//产品信息 { Model_WarehouseProductBatchIn m = new ProductBatchInConsole().ReadProductInfo(newValue); if (m.Guid == new Guid()) { DataGrid.CurrentCell = new DataGridCellInfo(SelectItem, DataGrid.Columns[0]); data[data.IndexOf(model)].Guid = new Guid(); data[data.IndexOf(model)].Name = ""; data[data.IndexOf(model)].Material = ""; data[data.IndexOf(model)].PerQuantity = 0; data[data.IndexOf(model)].TotalParts = 0; } else { data[data.IndexOf(model)].Guid = m.Guid; data[data.IndexOf(model)].Name = m.Name; data[data.IndexOf(model)].Material = m.Material; data[data.IndexOf(model)].PerQuantity = m.PerQuantity; data[data.IndexOf(model)].TotalParts = m.TotalParts; } } else if (Header == "件数") { int PackQuantity = 0; if (!int.TryParse(newValue, out PackQuantity)) { MessageBox.Show("请输入数字", "警告"); (e.EditingElement as TextBox).Text = "0"; DataGrid.CurrentCell = new DataGridCellInfo(SelectItem, DataGrid.Columns[3]); return; } data[data.IndexOf(model)].PackQuantity = PackQuantity; data[data.IndexOf(model)].AllQuantity = data[data.IndexOf(model)].PackQuantity * data[data.IndexOf(model)].PerQuantity; if (data[data.IndexOf(model)].AllQuantity > data[data.IndexOf(model)].TotalParts) { MessageBox.Show("包装总数不能大于散件总数", "警告"); (e.EditingElement as TextBox).Text = "0"; DataGrid.CurrentCell = new DataGridCellInfo(SelectItem, DataGrid.Columns[3]); } } }
/// <summary> /// 读取要修改的单的详细内容 /// </summary> /// <returns></returns> internal ObservableCollection <Model_WarehouseProductBatchIn> ReadDatas(Guid OrderGuid, string OrderType) { string TableName = ""; int IsOut = 1; switch (OrderType) { case "0": //入库:包装产品 TableName = "T_Warehouse_ProductPacking"; break; case "1": //入库:散件产品 TableName = "T_Warehouse_Product"; break; case "2": //出库:包装产品 TableName = "T_Warehouse_ProductPacking"; IsOut = -1; break; case "3": //出库:散件产品 TableName = "T_Warehouse_Product"; IsOut = -1; break; } ObservableCollection <Model_WarehouseProductBatchIn> data = new ObservableCollection <Model_WarehouseProductBatchIn>(); Model_WarehouseProductBatchIn m; DataSet ds = new DataSet(); string sql = "Select a.*,p.Number,p.Name,p.Material,p.PackageNumber " + " from " + TableName + " a" + " left join T_ProductInfo_Product p ON a.ProductID=p.Guid" + " Where a.Obligate1='" + OrderGuid + "' " + " AND a.DeleteMark ISNULL"; if (new Helper.SQLite.DBHelper().QueryData(sql, out ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { m = new Model_WarehouseProductBatchIn(); m.Guid = (Guid)dr["ProductID"]; m.Number = dr["Number"].ToString(); m.Name = dr["Name"].ToString(); m.Material = dr["Material"].ToString(); if (OrderType == "0" || OrderType == "2") //包装产品 { m.PerQuantity = int.Parse(dr["PackageNumber"].ToString()); //单件量 m.PackQuantity = IsOut * int.Parse(dr["Quantity"].ToString()); //包装数 m.AllQuantity = m.PerQuantity * m.PackQuantity; //总数量 } else//散件产品 { m.AllQuantity = IsOut * int.Parse(dr["Quantity"].ToString()); } data.Add(m); } } //补全20行 if (data.Count < 20) { int COUNT = data.Count; for (int i = 0; i < 20 - COUNT; i++) { data.Add(new Model_WarehouseProductBatchIn { Id = i + 1 }); } } return(data); }