private void dgvDolgi_CellClick(object sender, DataGridViewCellEventArgs e) { var grid = sender as DataGridView; if (grid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { int sums = Convert.ToInt32(grid.Rows[e.RowIndex].Cells["sums"].Value); DataSetTpos.debtRow debRow = DBclass.DS.debt.NewdebtRow(); DataSetTposTableAdapters.infoTableAdapter daInfo = new DataSetTposTableAdapters.infoTableAdapter(); daInfo.Fill(DBclass.DS.info); string dat = DateTime.Now.ToString("dd.mm.yyyy"); DataRow[] drInfo = DBclass.DS.info.Select("Dates='" + Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00") + "'"); debRow.payDate = DateTime.Now; debtPaid dbt = new debtPaid(sums); if (dbt.ShowDialog() == System.Windows.Forms.DialogResult.OK) { int termi = 0; if (dbt.terminal == true) { termi = dbt.paidSumm; drInfo[0]["terminal"] = Convert.ToInt32(drInfo[0]["terminal"]) + termi; } else { drInfo[0]["nal"] = Convert.ToInt32(drInfo[0]["nal"]) + Convert.ToInt32(dbt.paidSumm); } debRow.terminal = termi; drInfo[0]["proceed"] = Convert.ToInt32(drInfo[0]["proceed"]) + Convert.ToInt32(dbt.paidSumm); debRow.summ = Convert.ToInt32(dbt.paidSumm); } //debRow. DataRow[] drs = DBclass.DS.contragent.Select("contragentId = " + grid.Rows[e.RowIndex].Cells["contragentId"].Value.ToString()); if (drs.Length != 0) { drs[0]["sums"] = Convert.ToInt32(drs[0]["sums"]) - debRow.summ; } DBclass.DS.debt.AdddebtRow(debRow); daInfo.Update(drInfo[0]); DataSetTposTableAdapters.debtTableAdapter daDebt = new DataSetTposTableAdapters.debtTableAdapter(); daDebt.Update(debRow); DataSetTposTableAdapters.contragentTableAdapter daContr = new DataSetTposTableAdapters.contragentTableAdapter(); daContr.Update(drs); contragentTableAdapter1.Fill(DBclass.DS.contragent); DataView dv = new DataView(DBclass.DS.contragent); dv.RowFilter = "sums<>0"; dgvDolgi.DataSource = dv; //dgvDolgi.Refresh(); } //else //if (e.RowIndex >= 0) //{ // dgvDolgi.CurrentCell = dgvDolgi.Rows[e.RowIndex].Cells["terminal"]; // dgvDolgi.BeginEdit(true); //} }
private void updateContragent() { DataSetTposTableAdapters.contragentTableAdapter prda = new DataSetTposTableAdapters.contragentTableAdapter(); prda.Update(DBclass.DS.contragent); prda.Fill(DBclass.DS.contragent); }