private void gConvenioClifor_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (gConvenioClifor.Columns[e.ColumnIndex].SortMode == DataGridViewColumnSortMode.NotSortable) { return; } if (bsConvenioClifor.Count < 1) { return; } PropertyDescriptorCollection lP = TypeDescriptor.GetProperties(new TRegistro_Convenio_Clifor()); TList_Convenio_Clifor lComparer; SortOrder direcao = SortOrder.None; if ((gConvenioClifor.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == SortOrder.None) || (gConvenioClifor.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == SortOrder.Descending)) { lComparer = new TList_Convenio_Clifor(lP.Find(gConvenioClifor.Columns[e.ColumnIndex].DataPropertyName, true), SortOrder.Ascending); foreach (DataGridViewColumn c in gConvenioClifor.Columns) { c.HeaderCell.SortGlyphDirection = SortOrder.None; } direcao = SortOrder.Ascending; } else { lComparer = new TList_Convenio_Clifor(lP.Find(gConvenioClifor.Columns[e.ColumnIndex].DataPropertyName, true), SortOrder.Descending); foreach (DataGridViewColumn c in gConvenioClifor.Columns) { c.HeaderCell.SortGlyphDirection = SortOrder.None; } direcao = SortOrder.Descending; } (bsConvenioClifor.List as TList_Convenio_Clifor).Sort(lComparer); bsConvenioClifor.ResetBindings(false); gConvenioClifor.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = direcao; }
private void InserirClifor() { if (bsConvenio.Current != null) { using (TFCliforConvenio fClifor = new TFCliforConvenio()) { fClifor.pCd_empresa = (bsConvenio.Current as TRegistro_Convenio).Cd_empresa; fClifor.tipo_insercaounica = false; if (fClifor.ShowDialog() == DialogResult.OK) #region Inserção unica { if ((fClifor.rClifor != null) && (fClifor.lCombustivel != null) && !string.IsNullOrEmpty(fClifor.rClifor.Cd_clifor)) { TList_Convenio_Clifor lConv = new TList_Convenio_Clifor(); fClifor.lCombustivel.ForEach(p => { lConv.Add( new TRegistro_Convenio_Clifor() { Cd_clifor = fClifor.rClifor.Cd_clifor, Cd_endereco = fClifor.rClifor.Cd_endereco, Cd_empresa = (bsConvenio.Current as TRegistro_Convenio).Cd_empresa, Cd_produto = p.CD_Produto, Id_convenio = (bsConvenio.Current as TRegistro_Convenio).Id_convenio, lMotorista = fClifor.rClifor.lMotorista, lPlaca = fClifor.rClifor.lPlaca, St_faturardireto = fClifor.rClifor.St_faturardireto, St_motconveniado = fClifor.rClifor.St_motconveniado, St_placaconveniada = fClifor.rClifor.St_placaconveniada, St_registro = fClifor.rClifor.St_registro, Vl_unitario = fClifor.rClifor.Vl_unitario, CD_vendedor = fClifor.rClifor.CD_vendedor, Id_config = fClifor.rClifor.Id_config, Qtd_convenio = fClifor.rClifor.Qtd_convenio, Tp_preco = fClifor.rClifor.Tp_preco, Tp_faturamento = fClifor.rClifor.Tp_faturamento, St_exigirrequisicao = fClifor.rClifor.St_exigirrequisicao, St_exigirnomemot = fClifor.rClifor.St_exigirnomemot, Tp_qt_vl = fClifor.rClifor.Tp_qt_vl, Base_calc_fid = fClifor.rClifor.Base_calc_fid, Qt_pontos_fid = fClifor.rClifor.Qt_pontos_fid, Nr_diasvalidade_fid = fClifor.rClifor.Nr_diasvalidade_fid, Tp_pontos_fid = fClifor.rClifor.Tp_pontos_fid, Ds_msgVale = fClifor.rClifor.Ds_msgVale }); }); try { TCN_Convenio_Clifor.Gravar(lConv, null); MessageBox.Show("Cliente gravado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); LimparFiltros(); id_convenio.Text = (bsConvenio.Current as TRegistro_Convenio).Id_conveniostr; cd_empresa.Text = (bsConvenio.Current as TRegistro_Convenio).Cd_empresa; afterBusca(); } catch (Exception ex) { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } #endregion #region Inserção composta else if (fClifor.lClifor != null && fClifor.lCombustivel != null && fClifor.lClifor.Count > 0 && fClifor.lCombustivel.Count > 0) { TList_Convenio_Clifor lConv = new TList_Convenio_Clifor(); fClifor.lClifor.ForEach(c => { fClifor.lCombustivel.ForEach(p => { lConv.Add( new TRegistro_Convenio_Clifor() { Cd_clifor = c.Cd_clifor.ToString().Trim(), Cd_endereco = new CamadaDados.Financeiro.Cadastros.TCD_CadEndereco().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + c.Cd_clifor.ToString().Trim() + "'" } }, "a.cd_endereco").ToString(), Cd_empresa = (bsConvenio.Current as TRegistro_Convenio).Cd_empresa, Cd_produto = p.CD_Produto, Id_convenio = (bsConvenio.Current as TRegistro_Convenio).Id_convenio, St_faturardireto = fClifor.rClifor.St_faturardireto, St_motconveniado = fClifor.rClifor.St_motconveniado, St_placaconveniada = fClifor.rClifor.St_placaconveniada, St_registro = fClifor.rClifor.St_registro, Vl_unitario = fClifor.rClifor.Vl_unitario, CD_vendedor = fClifor.rClifor.CD_vendedor, Id_config = fClifor.rClifor.Id_config, Qtd_convenio = fClifor.rClifor.Qtd_convenio, Tp_preco = fClifor.rClifor.Tp_preco, Tp_faturamento = fClifor.rClifor.Tp_faturamento, St_exigirrequisicao = fClifor.rClifor.St_exigirrequisicao, St_exigirnomemot = fClifor.rClifor.St_exigirnomemot, Tp_qt_vl = fClifor.rClifor.Tp_qt_vl, Base_calc_fid = fClifor.rClifor.Base_calc_fid, Qt_pontos_fid = fClifor.rClifor.Qt_pontos_fid, Nr_diasvalidade_fid = fClifor.rClifor.Nr_diasvalidade_fid, Tp_pontos_fid = fClifor.rClifor.Tp_pontos_fid, Ds_msgVale = fClifor.rClifor.Ds_msgVale }); }); }); try { TCN_Convenio_Clifor.Gravar(lConv, null); MessageBox.Show("Clientes gravados com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); LimparFiltros(); id_convenio.Text = (bsConvenio.Current as TRegistro_Convenio).Id_conveniostr; cd_empresa.Text = (bsConvenio.Current as TRegistro_Convenio).Cd_empresa; afterBusca(); } catch (Exception ex) { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion } } }