private void RetornaModel() { DataGridViewCell dvC = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgUsuario.DataSource; if (this.dgUsuario.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this._alteracao == false) { if (this.dgUsuario.CurrentRow != null) { //Atribui a coluna e a linha que esta selecionada a um objeto do tipo DataGridViewCell //------------------------------------------------------------------------------------ dvC = this.dgUsuario["id_usu", this.dgUsuario.CurrentRow.Index]; _model.IdUsuario = Convert.ToInt32(dvC.Value); dvC = this.dgUsuario["Usuário", this.dgUsuario.CurrentRow.Index]; _model.Login = dvC.Value.ToString(); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } } else { MessageBox.Show("É necessário Cadastrar um Usuário", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Buscar e Selecionar um Usuário", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvC != null) { dvC.Dispose(); dvC = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void RetornaModel() { DataGridViewCell dvC = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgTipoMotor.DataSource; if (this.dgTipoMotor.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgTipoMotor.CurrentRow != null) { //AtribUI a coluna e a linha que esta selecionada a um objeto do tipo DataGridViewCell //------------------------------------------------------------------------------------ dvC = this.dgTipoMotor["hIdTipoMotor", this.dgTipoMotor.CurrentRow.Index]; _model.IdTipoMotor = Convert.ToInt32(dvC.Value.ToString()); dvC = this.dgTipoMotor["hCodigo", this.dgTipoMotor.CurrentRow.Index]; _model.IdTipoMotorReal = dvC.Value.ToString(); dvC = this.dgTipoMotor["hDescTipoMotor", this.dgTipoMotor.CurrentRow.Index]; _model.DscTipoMotor = dvC.Value.ToString(); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Cadastrar um Tipo de Motor", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Buscar e Selecionar um Tipo de Motor", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvC != null) { dvC.Dispose(); dvC = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
bool setFieldRowValue(DataGridViewRow row, bool setEmpty) { Template.Field f = (Template.Field)row.Tag; if (f == null) { return(false); } if (!f.IsSet()) { setRowStatus(statuses.WARNING, row, "Not set"); return(false); } DataGridViewCell c = row.Cells["Value"]; if (c is DataGridViewImageCell && c.Value != null) { ((Bitmap)c.Value).Dispose(); } if (setEmpty) { c.Value = null; setRowStatus(statuses.NEUTRAL, row, ""); return(false); } clearImageFromBoxes(); object v = extractFieldAndDrawSelectionBox(f); if (f.Type == Template.Field.Types.ImageData) { if (!(c is DataGridViewImageCell)) { c.Dispose(); c = new DataGridViewImageCell(); row.Cells["Value"] = c; } } else { if (c is DataGridViewImageCell) { c.Dispose(); c = new DataGridViewTextBoxCell(); row.Cells["Value"] = c; } } c.Value = v; if (c.Value != null) { setRowStatus(statuses.SUCCESS, row, "Found"); } else { setRowStatus(statuses.ERROR, row, "Error"); } return(v != null); }
private void RetornaModel() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgKit.DataSource; if (this.dgKit.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgKit.CurrentRow != null) { dvc = this.dgKit["hIdKit", this.dgKit.CurrentRow.Index]; this._model.IdKit = Convert.ToInt32(dvc.Value); dvc = this.dgKit["hIdKitReal", this.dgKit.CurrentRow.Index]; this._model.IdKitReal = Convert.ToString(dvc.Value); dvc = this.dgKit["hNome", this.dgKit.CurrentRow.Index]; this._model.Nom_grupo = dvc.Value.ToString(); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário cadastrar um Kit Grupo Peça", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário buscar e selecionar um Kit Grupo Peça", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void RetornaModel() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgCompra.DataSource; if (this.dgCompra.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgCompra.CurrentRow != null) { dvc = this.dgCompra["id_compra", this.dgCompra.CurrentRow.Index]; this._model.IdCompra = Convert.ToInt32(dvc.Value); dvc = this.dgCompra["obs", this.dgCompra.CurrentRow.Index]; this._model.Obs = dvc.Value.ToString(); dvc = this.dgCompra["dat", this.dgCompra.CurrentRow.Index]; this._model.Dat = Convert.ToDateTime(dvc.Value); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário cadastrar um Cliente", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário buscar e selecionar um Cliente!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void RetornaModel() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgNumMotor.DataSource; if (this.dgNumMotor.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgNumMotor.CurrentRow != null) { dvc = this.dgNumMotor["hid", this.dgNumMotor.CurrentRow.Index]; this._model.Id_num_motor = Convert.ToInt32(dvc.Value); dvc = this.dgNumMotor["hCodigo", this.dgNumMotor.CurrentRow.Index]; this._model.IdNumMotorReal = dvc.Value.ToString(); dvc = this.dgNumMotor["hDescNumMotor", this.dgNumMotor.CurrentRow.Index]; this._model.Dsc_num_motor = dvc.Value.ToString(); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário cadastrar um Numero de motor", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário buscar e selecionar um Numero de motor!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void retornaModel() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgOrdemServico.DataSource; if (this.dgOrdemServico.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgOrdemServico.CurrentRow != null) { dvc = this.dgOrdemServico["hCodigoOrdemServ", this.dgOrdemServico.CurrentRow.Index]; this._modelOrdemServico.IdOrdemServ = Convert.ToInt32(dvc.Value); //Outros campos, se houver this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar uma linha!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário cadastrar uma Ordem de Serviço!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário buscar e selecionar uma Ordem de Serviço!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void RetornaModel() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgUsinagem.DataSource; if (this.dgUsinagem.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgUsinagem.CurrentRow != null) { dvc = this.dgUsinagem["id_usinagem", this.dgUsinagem.CurrentRow.Index]; this._model.IdUsinagem = Convert.ToInt32(dvc.Value); dvc = this.dgUsinagem["id_peca", this.dgUsinagem.CurrentRow.Index]; this._model.IdPeca = Convert.ToInt32(dvc.Value.ToString()); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("É necessário Selecionar um item de Usinagem", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário cadastrar um item de Usinagem", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário buscar e selecionar um item de Usinagem!", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
/// <summary> /// Popula o model com os dados que estão no DataSource do Grid /// </summary> private void PopulaModelDadosGrid() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgCliente.DataSource; if (this.dgCliente.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgCliente.CurrentRow != null) { dvc = this.dgCliente["hId", this.dgCliente.CurrentRow.Index]; this._model.IdCliente = Convert.ToInt32(dvc.Value); dvc = this.dgCliente["hNome", this.dgCliente.CurrentRow.Index]; this._model.NomeCliente = dvc.Value.ToString(); dvc = this.dgCliente["hEmail", this.dgCliente.CurrentRow.Index]; this._model.Email = dvc.Value.ToString(); } else { throw new BUSINESS.Exceptions.Busca.LinhaSemSelecionarException(); } } else { throw new BUSINESS.Exceptions.Busca.CadastrarDadoException(this._model.getNomeTabela()); } } else { throw new BUSINESS.Exceptions.Busca.SemBuscaESelecionarException(this._model.getNomeTabela()); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
/// <summary> /// Popula o model com os dados que estão no DataSource do Grid /// </summary> private void PopulaModelDadosGrid() { DataGridViewCell dvc = null; DataTable dtSource = new DataTable(); try { dtSource = (DataTable)this.dgColaborador.DataSource; if (this.dgColaborador.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgColaborador.CurrentRow != null) { dvc = this.dgColaborador["hid_colab", this.dgColaborador.CurrentRow.Index]; this._model.IdColab = Convert.ToInt32(dvc.Value); dvc = this.dgColaborador["hColaborador", this.dgColaborador.CurrentRow.Index]; this._model.NomeColab = dvc.Value.ToString(); } else { throw new TCC.Regra.Exceptions.Busca.LinhaSemSelecionarException(); } } else { throw new TCC.Regra.Exceptions.Busca.CadastrarDadoException(this._model.getNomeTabela()); } } else { throw new TCC.Regra.Exceptions.Busca.SemBuscaESelecionarException(this._model.getNomeTabela()); } } catch (Exception ex) { throw ex; } finally { if (dvc != null) { dvc.Dispose(); dvc = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void PopulaListaModel() { DataGridViewCell dvC = null; DataTable dtSource = new DataTable(); mPecaEstoque modelPecaEstoque; try { dtSource = (DataTable)this.dgEstoques.DataSource; if (this.dgEstoques.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgEstoques.CurrentRow != null) { //Varre o DataGrid linha por linha //-------------------------------- foreach (DataGridViewRow linha in this.dgEstoques.Rows) { //Verifica se a quantidade é maior que Zero //----------------------------------------- if (Convert.ToInt32(linha.Cells["hQuantidade"].Value) >= 0) { modelPecaEstoque = new mPecaEstoque(); //Atribui a coluna e a linha que esta selecionada a um objeto do tipo DataGridViewCell //------------------------------------------------------------------------------------ //Pega id Estoque dvC = linha.Cells["hIdEstoque"]; modelPecaEstoque.Id_estoq = Convert.ToInt32(dvC.Value); //Pega resto model dvC = linha.Cells["hQuantidade"]; // Qtde modelPecaEstoque.Qtd_peca = Convert.ToInt32(dvC.Value); if (this._telaPeca == true) { modelPecaEstoque.Id_peca = null; } else { modelPecaEstoque.Id_peca = this._modelPeca.IdPeca; } modelPecaEstoque.Dat_alt = DateTime.Now; modelPecaEstoque.Flg_ativo = true; //Atribui o model à lista de models if (this._listaModelPecaEstoque == null) { this._listaModelPecaEstoque = new List <mPecaEstoque>(); this._listaModelPecaEstoque.Add(modelPecaEstoque); } else { this._listaModelPecaEstoque.Add(modelPecaEstoque); } } } } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Cadastrar um Departamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Buscar e Selecionar um Departamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvC != null) { dvC.Dispose(); dvC = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void PopulaListaModel() { DataGridViewCell dvC = null; DataTable dtSource = new DataTable(); mPerfilMenu modelPerfilMenu; try { dtSource = (DataTable)this.dgMenu.DataSource; if (this.dgMenu.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgMenu.CurrentRow != null) { //Varre o DataGrid linha por linha //-------------------------------- foreach (DataGridViewRow linha in this.dgMenu.Rows) { //Verifica se a linha é nula //-------------------------- if (linha.Cells[0].Value != null) { //Converte o valor para Boolean e verifica se está checado //-------------------------------------------------------- if (Convert.ToBoolean(linha.Cells[0].Value) != false) { modelPerfilMenu = new mPerfilMenu(); //Atribui a coluna e a linha que esta selecionada a um objeto do tipo DataGridViewCell //------------------------------------------------------------------------------------ //Pega id Menu dvC = linha.Cells[1]; modelPerfilMenu.IdMenu = Convert.ToInt32(dvC.Value); //Pega id Perfil modelPerfilMenu.IdPerfil = this._modelPerfil.IdPerfil; modelPerfilMenu.DatTrans = DateTime.Now; modelPerfilMenu.FlgAtivo = true; //Atribui o model à lista de models if (this._listaModelPerfilMenu == null) { this._listaModelPerfilMenu = new List <mPerfilMenu>(); this._listaModelPerfilMenu.Add(modelPerfilMenu); } else { this._listaModelPerfilMenu.Add(modelPerfilMenu); } } } } } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Cadastrar um Menu", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Buscar e Selecionar um Perfil", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvC != null) { dvC.Dispose(); dvC = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
private void PopulaListaModel() { DataGridViewCell dvC = null; DataTable dtSource = new DataTable(); mMotorFornecedor modelMotorFornecedor; try { dtSource = (DataTable)this.dgFornecedores.DataSource; if (this.dgFornecedores.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgFornecedores.CurrentRow != null) { //Varre o DataGrid linha por linha //-------------------------------- foreach (DataGridViewRow linha in this.dgFornecedores.Rows) { //Verifica se a linha é nula //-------------------------- if (linha.Cells[0].Value != null) { //Converte o valor para Boolean e verifica se está checado //-------------------------------------------------------- if (Convert.ToBoolean(linha.Cells[0].Value) != false) { modelMotorFornecedor = new mMotorFornecedor(); //Atribui a coluna e a linha que esta selecionada a um objeto do tipo DataGridViewCell //------------------------------------------------------------------------------------ //Pega id Fornecedor dvC = linha.Cells["hIdForn"]; modelMotorFornecedor.Id_forn = Convert.ToInt32(dvC.Value); //Completa Model FornecedorDepto if (this._telaMotor == false) { modelMotorFornecedor.Id_motor = this._modelMotor.IdMotor; } else { modelMotorFornecedor.Id_motor = null; } modelMotorFornecedor.Dat_alt = DateTime.Now; modelMotorFornecedor.Flg_ativo = true; //Atribui o model à lista de models if (this._listaModelMotorFornecedor == null) { this._listaModelMotorFornecedor = new List <mMotorFornecedor>(); this._listaModelMotorFornecedor.Add(modelMotorFornecedor); } else { this._listaModelMotorFornecedor.Add(modelMotorFornecedor); } } } } } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Cadastrar um Departamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Buscar e Selecionar um Departamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvC != null) { dvC.Dispose(); dvC = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
object setFieldRowValue(DataGridViewRow row, bool setEmpty) { Template.Field f = (Template.Field)row.Tag; if (f == null) { return(null); } if (!f.IsSet()) { setRowStatus(statuses.WARNING, row, "Not set"); return(null); } DataGridViewCell valueCell = row.Cells["Value"]; if (valueCell.Value != null && valueCell.Value is IDisposable) { ((IDisposable)valueCell.Value).Dispose(); } if (f is Template.Field.Image || f is Template.Field.OcrTextLineImages) { if (!(valueCell is DataGridViewImageCell)) { valueCell.Dispose(); valueCell = new DataGridViewImageCell(); row.Cells["Value"] = valueCell; } } else { if (valueCell is DataGridViewImageCell) { valueCell.Dispose(); valueCell = new DataGridViewTextBoxCell(); row.Cells["Value"] = valueCell; } } if (setEmpty) { valueCell.Value = null; setRowStatus(statuses.NEUTRAL, row, ""); return(null); } clearImageFromBoxes(); object v = extractFieldAndDrawSelectionBox(f); if (v != null) { switch (f.Type) { case Template.Field.Types.PdfText: valueCell.Value = Page.NormalizeText((string)v); break; case Template.Field.Types.PdfTextLines: valueCell.Value = Page.NormalizeText(string.Join("\r\n", (List <string>)v)); break; case Template.Field.Types.PdfCharBoxs: valueCell.Value = Page.NormalizeText(Serialization.Json.Serialize(v)); break; case Template.Field.Types.OcrText: valueCell.Value = Page.NormalizeText((string)v); break; case Template.Field.Types.OcrTextLines: valueCell.Value = Page.NormalizeText(string.Join("\r\n", (List <string>)v)); break; case Template.Field.Types.OcrCharBoxs: valueCell.Value = Page.NormalizeText(Serialization.Json.Serialize(v)); break; case Template.Field.Types.Image: { Bitmap b = (Bitmap)v; Size s = valueCell.Size; if (s.Height < b.Height * pictureScale.Value) { s.Width = int.MaxValue; b = Win.ImageRoutines.GetScaled(b, s); } else if (pictureScale.Value != 1) { b = Win.ImageRoutines.GetScaled(b, (float)pictureScale.Value); } valueCell.Value = b; break; } case Template.Field.Types.OcrTextLineImages: { List <Bitmap> bs = (List <Bitmap>)v; if (bs.Count < 1) { break; } Bitmap b = bs[0]; Size s = valueCell.Size; if (s.Height < b.Height * pictureScale.Value) { s.Width = int.MaxValue; b = Win.ImageRoutines.GetScaled(b, s); } else if (pictureScale.Value != 1) { b = Win.ImageRoutines.GetScaled(b, (float)pictureScale.Value); } valueCell.Value = b; break; } default: throw new Exception("Unknown option: " + f.Type); } } else { valueCell.Value = v; } if (valueCell.Value != null) { setRowStatus(statuses.SUCCESS, row, "Found"); } else { setRowStatus(statuses.ERROR, row, "Not found"); } return(v); }
void setAnchorRow(DataGridViewRow row, Template.Anchor a) { row.Tag = a; row.Cells["Id3"].Value = a.Id; row.Cells["Type3"].Value = a.Type; row.Cells["ParentAnchorId3"].Value = a.ParentAnchorId; row.Cells["SearchRectangleMargin"].Value = a.SearchRectangleMargin < 0 ? "-" : a.SearchRectangleMargin.ToString(); DataGridViewCell patternCell = row.Cells["Pattern"]; if (patternCell.Value != null && patternCell.Value is IDisposable) { ((IDisposable)patternCell.Value).Dispose(); } if (a is Template.Anchor.CvImage || a is Template.Anchor.ImageData) { if (!(patternCell is DataGridViewImageCell)) { patternCell.Dispose(); patternCell = new DataGridViewImageCell { ImageLayout = DataGridViewImageCellLayout.NotSet }; row.Cells["Pattern"] = patternCell; } } else { if (patternCell is DataGridViewImageCell) { patternCell.Dispose(); patternCell = new DataGridViewTextBoxCell { }; row.Cells["Pattern"] = patternCell; } } row.Cells["Pattern"].ReadOnly = true; switch (a.Type) { case Template.Anchor.Types.PdfText: { Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a; if (pt.CharBoxs == null) { patternCell.Value = null; break; } StringBuilder sb = new StringBuilder(); foreach (var l in Page.GetLines(pt.CharBoxs.Select(x => new Pdf.CharBox { Char = x.Char, R = x.Rectangle.GetSystemRectangleF() }), new TextAutoInsertSpace { IgnoreSourceSpaces = textAutoInsertSpace_IgnoreSourceSpaces.Checked, Threshold = (float)textAutoInsertSpace_Threshold.Value /*, Representative*/ }, null)) { foreach (var cb in l.CharBoxs) { sb.Append(cb.Char); } sb.Append("\r\n"); } patternCell.Value = sb.ToString(); } break; case Template.Anchor.Types.OcrText: { Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a; if (ot.CharBoxs == null) { patternCell.Value = null; break; } StringBuilder sb = new StringBuilder(); foreach (var l in Page.GetLines(ot.CharBoxs.Select(x => new Ocr.CharBox { Char = x.Char, R = x.Rectangle.GetSystemRectangleF() }), new TextAutoInsertSpace { IgnoreSourceSpaces = textAutoInsertSpace_IgnoreSourceSpaces.Checked, Threshold = (float)textAutoInsertSpace_Threshold.Value /*, Representative*/ }, null)) { foreach (var cb in l.CharBoxs) { sb.Append(cb.Char); } sb.Append("\r\n"); } patternCell.Value = sb.ToString(); } break; case Template.Anchor.Types.ImageData: { Template.Anchor.ImageData id = (Template.Anchor.ImageData)a; Bitmap b = null; if (id.Image != null) { b = id.Image.GetBitmap(); Size s = patternCell.Size; if (s.Height < b.Height * pictureScale.Value) { s.Width = int.MaxValue; Win.ImageRoutines.Scale(ref b, s); } else if (pictureScale.Value != 1) { Win.ImageRoutines.Scale(ref b, (float)pictureScale.Value); } } patternCell.Value = b; } break; case Template.Anchor.Types.CvImage: { Template.Anchor.CvImage ci = (Template.Anchor.CvImage)a; Bitmap b = null; if (ci.Image != null) { b = ci.Image.GetBitmap(); Size s = patternCell.Size; if (s.Height < b.Height * pictureScale.Value) { s.Width = int.MaxValue; Win.ImageRoutines.Scale(ref b, s); } else if (pictureScale.Value != 1) { Win.ImageRoutines.Scale(ref b, (float)pictureScale.Value); } } patternCell.Value = b; } break; default: throw new Exception("Unknown option: " + a.Type); } Template.PointF p = a.Position; if (p != null) { row.Cells["Position3"].Value = Serialization.Json.Serialize(p); } if (loadingTemplate) { return; } if (currentAnchorControl != null && row == currentAnchorControl.Row) { setCurrentAnchorRow(a.Id, false); } setConditionsStatus(); }