void insertHang() { for (int i = 0; i < grvData.RowCount; i++) { string groupCode = grvData.GetRowCellValue(i, "F1").ToString().Trim(); if (groupCode == "") { continue; } MaterialGroupModel group = (MaterialGroupModel)MaterialGroupBO.Instance.FindByAttribute("Code", groupCode)[0]; for (int j = 2; j < grvData.Columns.Count; j++) { try { string columnName = "F" + (j + 1); if (grvData.GetRowCellValue(i, columnName) == null) { continue; } if (grvData.GetRowCellValue(i, columnName).ToString() == "") { continue; } string customerCode = grvData.GetRowCellValue(i, columnName).ToString(); CustomerModel customer = (CustomerModel)CustomerBO.Instance.FindByAttribute("Code", customerCode)[0]; DataTable dtLink = TextUtils.Select(string.Format("Select * from MaterialGroupCustomerLink with(nolock) where CustomerID={0} and MaterialGroupID ={1}", customer.ID, group.ID)); if (dtLink.Rows.Count == 0) { MaterialGroupCustomerLinkModel link = new MaterialGroupCustomerLinkModel(); link.MaterialGroupID = group.ID; link.CustomerID = customer.ID; MaterialGroupCustomerLinkBO.Instance.Insert(link); } } catch (Exception ex) { TextUtils.ShowError(ex); } } } MessageBox.Show("OK"); }
void save(bool close) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } if (Model == null) { Model = new MaterialGroupModel(); } Model.Name = txtName.Text.Trim().ToUpper(); Model.Code = txtCode.Text.Trim().ToUpper(); Model.Description = txtDescription.Text.Trim(); Model.ParentID = TextUtils.ToInt(leParentCat.EditValue); if (Model.ID == 0) { Model.ID = (int)pt.Insert(Model); } else { pt.Update(Model); } if (grvData.RowCount > 0) { for (int i = 0; i < grvData.RowCount; i++) { MaterialGroupCustomerLinkModel link = new MaterialGroupCustomerLinkModel(); int id = TextUtils.ToInt(grvData.GetRowCellValue(i, colID)); if (id > 0) { link = (MaterialGroupCustomerLinkModel)MaterialGroupCustomerLinkBO.Instance.FindByPK(id); } link.CustomerID = TextUtils.ToInt(grvData.GetRowCellValue(i, colCustomerID)); link.MaterialGroupID = Model.ID; if (id > 0) { pt.Update(link); } else { pt.Insert(link); } } } pt.CommitTransaction(); _isSaved = true; if (close) { CurentNode = Model.ID; this.DialogResult = DialogResult.OK; } else { loadGridCustomer(); MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
protected MaterialGroupCustomerLinkFacade(MaterialGroupCustomerLinkModel model) : base(model) { }