public void SelectRow(DataRow row, string condition = "") { frmSelect frm = new frmSelect(); frm.dgv.AddColumn("选择", "选择", "", 40, 2, "{0:,1:√}"); frm.dgv.AddColumn("item_subno", "货号", "", 110, 1, ""); frm.dgv.AddColumn("barcode", "条码", "", 110, 1, ""); frm.dgv.AddColumn("item_name", "商品名称", "", 160, 1, ""); frm.dgv.AddColumn("item_subname", "拼音码", "", 90, 1, ""); frm.dgv.AddColumn("unit_no", "单位", "", 60, 1, ""); frm.dgv.AddColumn("item_size", "规格", "", 60, 1, ""); frm.dgv.AddColumn("price", "价格", "", 100, 3, "0.00"); frm.dgv.AddColumn("product_area", "产地", "", 150, 1, ""); frm.Text = "选择商品"; frm.condition = condition; IBLL.IPriceBLL pricebll = new BLL.PriceBLL(); var sup_id = this.txt_cust.Text.Trim().Split('/')[0]; List <DataRow> lis = frm.SelectDataRow("货号:", "item_subno"); int index = 0; for (int i = 0; i < this.editGrid1.DataSource.Rows.Count; i++) { if (this.editGrid1.DataSource.Rows[i] == row) { index = i; } } if (lis.Count > 1) { for (int i = 0; i < lis.Count - 1; i++) { this.editGrid1.DataSource.Rows.InsertAt(this.editGrid1.DataSource.NewRow(), index); } } foreach (DataRow dr in lis) { var dgv_tb = this.editGrid1.DataSource.Copy(); dgv_tb.ImportRow(dr); var dgv_dr = dgv_tb.Rows[dgv_tb.Rows.Count - 1]; dgv_dr["valid_price"] = pricebll.GetCustItemPrice(sup_id, dr["item_no"].ToString(), "0"); dgv_dr["sub_amount"] = Helper.Conv.ToDecimal(dgv_dr["in_qty"]) * Helper.Conv.ToDecimal(dgv_dr["valid_price"]); Conv.CopyDataRow(this.editGrid1.DataSource, index, dgv_dr); index++; } if (!string.IsNullOrEmpty(this.editGrid1.DataSource.Rows[this.editGrid1.DataSource.Rows.Count - 1]["item_subno"].ToString())) { this.editGrid1.DataSource.Rows.Add(); } this.editGrid1.Editing = false; this.editGrid1.Refresh(); }
private void editGrid1_CellEndEdit(object sender, string column_name, DataRow row) { if (isSelect) { return; } if (column_name == "item_subno") { if (string.IsNullOrEmpty(row[column_name].ToString())) { return; } IBLL.IPriceBLL pricebll = new BLL.PriceBLL(); IBLL.IItem itembll = new BLL.ItemBLL(); var sup_id = this.txt_cust.Text.Trim().Split('/')[0]; DataTable tb = itembll.GetLikeItem(sup_id, 0, row["item_subno"].ToString(), "0"); if (tb.Rows.Count > 1) { SelectRow(row, row["item_subno"].ToString()); } else { foreach (DataRow dr in tb.Rows) { int index = 0; for (int i = 0; i < this.editGrid1.DataSource.Rows.Count; i++) { if (this.editGrid1.DataSource.Rows[i] == row) { index = i; } } var dgv_tb = this.editGrid1.DataSource.Copy(); dgv_tb.ImportRow(dr); var dgv_dr = dgv_tb.Rows[dgv_tb.Rows.Count - 1]; dgv_dr["valid_price"] = pricebll.GetCustItemPrice(sup_id, row["item_no"].ToString(), "0"); dgv_dr["sub_amount"] = Helper.Conv.ToDecimal(row["in_qty"]) * Helper.Conv.ToDecimal(row["valid_price"]); Conv.CopyDataRow(this.editGrid1.DataSource, index, dgv_dr); break; } if (tb.Rows.Count < 1) { row[column_name] = ""; } } if (!string.IsNullOrEmpty(this.editGrid1.DataSource.Rows[this.editGrid1.DataSource.Rows.Count - 1]["item_subno"].ToString())) { this.editGrid1.DataSource.Rows.Add(); } } else if (column_name == "in_qty" || column_name == "valid_price") { row["sub_amount"] = Helper.Conv.ToDecimal(row["in_qty"]) * Helper.Conv.ToDecimal(row["valid_price"]); editGrid1.Refresh(); } }