private void ClearEstoque() { if (dataGridVariacao.Rows.Count <= 0) { return; } var generateAlert = AlertOptions.Message("Atenção", "Você está prestes a deletar todo o estoque de combinações, continuar?", AlertBig.AlertType.info, AlertBig.AlertBtn.YesNo); if (!generateAlert) { return; } var checkEstoque = new ItemEstoque().FindAll().WhereFalse("excluir").Where("item", idProduto) .Get <ItemEstoque>(); if (checkEstoque.Any()) { foreach (var data in checkEstoque) { new ItemEstoque().Remove(data.Id); } } dataGridVariacao.Rows.Clear(); }
private void LoadDataGrid() { var checkEstoque = new ItemEstoque().FindAll().WhereFalse("excluir").Where("item", idProduto) .Get <ItemEstoque>(); if (!checkEstoque.Any()) { return; } btnGerar.Visible = false; btnClearCombinacao.Visible = true; txtBuscarVariacao.Text = _mItem.Atributos; var attr1Name = new List <string>(); var attr2Name = new List <string>(); var attr3Name = new List <string>(); var attr1Id = new List <string>(); var attr2Id = new List <string>(); var attr3Id = new List <string>(); var grupos = _mItem.Atributos.Split('+'); var i_attrs = 0; foreach (var word in grupos) { i_attrs++; var grupo = new ItemGrupo().FindAll().WhereFalse("excluir").Where("title", word) .FirstOrDefault <ItemGrupo>(); if (grupo == null) { continue; } var attr = new ItemAtributos().FindAll().WhereFalse("excluir").Where("grupo", grupo.Id) .Get <ItemAtributos>(); foreach (var data in attr) { switch (i_attrs) { case 1: attr1Name.Add($"{data.Atributo}"); attr1Id.Add($"{data.Id}"); break; case 2: attr2Name.Add($" - {data.Atributo}"); attr2Id.Add($", {data.Id}"); break; case 3: attr3Name.Add($" - {data.Atributo}"); attr3Id.Add($", {data.Id}"); break; } } } var lstMaster = new List <List <string> >(); if (attr1Id.Count > 0) { lstMaster.Add(attr1Id); } if (attr2Id.Count > 0) { lstMaster.Add(attr2Id); } if (attr3Id.Count > 0) { lstMaster.Add(attr3Id); } var lstMasterNames = new List <List <string> >(); if (attr1Name.Count > 0) { lstMasterNames.Add(attr1Name); } if (attr2Name.Count > 0) { lstMasterNames.Add(attr2Name); } if (attr3Name.Count > 0) { lstMasterNames.Add(attr3Name); } var ids = GetPermutation(lstMaster.Count, lstMaster); var names = GetPermutation(lstMasterNames.Count, lstMasterNames); if (ids.Count != names.Count) { return; } for (var u = 0; u < ids.Count; u++) { var codeBarras = ""; if (checkCodeBarras.Checked) { codeBarras = CodeBarrasRandom(); } dataGridVariacao.Rows.Add( false, ids[u], names[u], 0, "", codeBarras ); } if (checkEstoque != null && checkEstoque.Any()) { // Verifica se existe algum linha if (dataGridVariacao.Rows.Count > 0) { // Percorre todas as linhas do datagrid foreach (DataGridViewRow row in dataGridVariacao.Rows) { // Percorre todos dados do banco, comparando as linhas do grid foreach (var item in checkEstoque) { if (row.Cells["ID"].Value.ToString() != item.Atributo) { continue; } row.Cells["Referencia"].Value = item.Referencia; row.Cells["Código de Barras"].Value = item.Codebarras; row.Cells["Estoque"].Value = item.Estoque; row.Cells["IDAttr"].Value = item.Id; } } } } dataGridVariacao.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; }