public Kardex() { InitializeComponent(); SiaWin = Application.Current.MainWindow; //idemp = SiaWin._BusinessId; TextBoxRef.Focus(); }
private void Button_Click(object sender, RoutedEventArgs e) { try { ResetValue(); if (FecIni.Text.Length <= 0) { MessageBox.Show("debe de ingresar la fecha de corte"); FecIni.Focus(); return; } if (string.IsNullOrEmpty(TextBoxRef.Text.Trim())) { MessageBox.Show("debe de ingresar una referencia"); TextBoxRef.Focus(); return; } if (string.IsNullOrEmpty(TextBoxbod.Text.Trim())) { MessageBox.Show("debe de ingresar una bodega"); TextBoxbod.Focus(); return; } SqlConnection con = new SqlConnection(SiaWin._cn); SqlCommand cmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataSet ds = new DataSet(); cmd = new SqlCommand("_EmpInventarioKardes", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Fecha", FecIni.Text); cmd.Parameters.AddWithValue("@Ref", TextBoxRef.Text); cmd.Parameters.AddWithValue("@Bods", TextBoxbod.Text); cmd.Parameters.AddWithValue("@codemp", codemp); da = new SqlDataAdapter(cmd); da.Fill(ds); con.Close(); GridKardex.ItemsSource = ds.Tables[0]; if (ds.Tables[0].Rows.Count > 0) { GridKardex.Focus(); GridKardex.SelectedIndex = 0; decimal CantEnt = Convert.ToDecimal(ds.Tables[0].Compute("Sum(ent_uni)", "").ToString()); decimal TotEnt = Convert.ToDecimal(ds.Tables[0].Compute("Sum(ent_ctotal)", "").ToString()); TxtTotalUnEnt.Text = CantEnt.ToString("N2"); TxtTotalUncostEnt.Text = TotEnt.ToString("N2"); int promedioEntrada = 0; if (TotEnt > 0 & CantEnt > 0) { TxtTotalUncosEnt.Text = (TotEnt / CantEnt).ToString("N2"); promedioEntrada = Convert.ToInt32(TotEnt / CantEnt); } else { TxtTotalUncosEnt.Text = "0"; } ProEnt.Text = promedioEntrada.ToString(); decimal CantSal = Convert.ToDecimal(ds.Tables[0].Compute("Sum(sal_uni)", "").ToString()); decimal TotSal = Convert.ToDecimal(ds.Tables[0].Compute("Sum(sal_ctotal)", "").ToString()); TxtTotalUnSal.Text = CantSal.ToString("N2"); TxtTotalUncostSal.Text = TotSal.ToString("N2"); int promedioSalida = 0; if (TotSal > 0 & CantSal > 0) { TxtTotalUncosSal.Text = (TotSal / CantSal).ToString("N2"); promedioSalida = Convert.ToInt32(TotSal / CantSal); } else { TxtTotalUncosSal.Text = "0"; } ProSal.Text = promedioSalida.ToString(); decimal CantSaldo = Convert.ToDecimal(ds.Tables[0].Compute("Sum(saldo_uni)", "").ToString()); decimal TotSaldo = Convert.ToDecimal(ds.Tables[0].Compute("Sum(saldo_ctotal)", "").ToString()); TxtTotalUnSaldo.Text = CantSaldo.ToString("N2"); TxtTotalUncostSaldo.Text = TotSaldo.ToString("N2"); int promedioSaldo = 0; if (TotSaldo > 0 & CantSaldo > 0) { promedioSaldo = Convert.ToInt32(TotSaldo / CantSaldo); TxtTotalUncosSaldo.Text = (TotSaldo / CantSaldo).ToString("N2"); } else { TxtTotalUncosSaldo.Text = "0"; } ProSaldo.Text = promedioSaldo.ToString(); } Total.Text = ds.Tables[0].Rows.Count.ToString(); } catch (Exception w) { MessageBox.Show("error al cargar la consulta programada:" + w.ToString()); } }