How to Record the Date, Time, Minute, and Second in C # WINFORMS and SQL SERVER?

-1

I created a sales system, and I need you to record the date, time, minutes, and seconds. The way I did, just record the date, and the rest comes 00:00:00. Here is the code I did:

//evento load do formulário vendas.
private void Vendafrm1_Load(object sender, EventArgs e)
    {
        tmVenda.Start();//inicia o Timer
        PovoaGridVenda();//Povoa a grid das vendas
        PovoaCobCli();//Povoa a combobox dos clientes
        PovoaCobProd();//povoa a combobox dos produtos
    }

The result looks like this:

Here'stheform:

Themethodthatwrites:

//paragravaravendapublicvoidGravaVenda(){tmVenda.Start();decimalentr=0;VendaModelobjVenda=newVendaModel();//objVenda.Data=Convert.ToDateTime(dtpData.Value);objVenda.Data=Convert.ToDateTime(dtpData.Value);objVenda.Desconto=Convert.ToDecimal(txtDesconto.Text);objVenda.Entreg=Convert.ToDecimal(txtEntreg.Text);objVenda.Falta=Convert.ToDecimal(txtFalta.Text);objVenda.IdCl=Convert.ToInt32(txtIdcl.Text);objVenda.IdPd=Convert.ToInt32(txtIdprod.Text);objVenda.Pago=Convert.ToDecimal(txtPago.Text);objVenda.Qtd=Convert.ToInt32(nudQuantd.Value);objVenda.Total=Convert.ToDecimal(txtTotal.Text);objVenda.Troco=Convert.ToDecimal(txtTroco.Text);try{if(cobCliente.Text=="")
            { MessageBox.Show("O nome do cliente é obrigatório!"); }
            else if (cobProduto.Text == "")
            { MessageBox.Show("O nome do produto é obrigatório!"); }
            else if (txtPreco.Text == "")
            { MessageBox.Show("O preço do produto é obrigatório!"); }
            else if (txtEntreg.Text == entr.ToString())
            { MessageBox.Show("O valor entregue não pode ser zero '0', nem menor que o total!"); } 
            else
            {
                vendaBll = new VendaBLL();
                int cod = Convert.ToInt32(vendaBll.GravaVenD(objVenda));
                txtId2.Text = cod.ToString();                    
                PovoaGridVenda();
                LimpaVenda();
                MessageBox.Show("Dados gravados com sucesso!");

                crFacturaVenda factura = new crFacturaVenda();
                factura.rad2.IsChecked = true;
                factura.txtImp.Text = txtId2.Text;
                factura.Show();
            }
        }
        catch (Exception erro)
        {
            MessageBox.Show("Ocorreu o seguinte erro ao gravar a venda: " + erro.ToString());
        }
    }

The table looks like this:

    
asked by anonymous 02.03.2017 / 12:30

2 answers

0

To receive the current date / time you can do:

DateTime d1 = DateTime.Now;

And to remove a day simply put -1 in the AddDays

d1 = d1.AddDays(-1);
    
02.03.2017 / 12:45
0

You should use DateTimePicker in its properties you define the Format will be Custom and property CustomFormat you put dd/MM/yyyy HH:mm:ss .

If you look in the file Form1.Designer.cs you will see that the declaration of DateTimePicker was as follows.

this.dateTimePicker1.CustomFormat = "dd/MM/yyyy HH:mm:ss";
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dateTimePicker1.Location = new System.Drawing.Point(72, 53);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(200, 20);
this.dateTimePicker1.TabIndex = 0;

To get the value typed in the field, you only need to use the Value :

DateTime data = dateTimePicker1.Value;
    
02.03.2017 / 14:30