I have the following code:
private void Timer1Tick(object sender, EventArgs e)
{
timer_ScanTimer.Enabled = false;
var psc = new ParseScannedCheckNumbers();
if (psc.ParseCheck(_checkData))
{
label_Status.Text = #"Scan Next Check";
var ct = checkTrans.IndividualCheck.NewIndividualCheckRow();
ct.Date = DateTime.Now.ToShortDateString();
var bracct = GetBranchAccountNumber(psc.BankAccountNumber);
if (bracct.Trim().Length == 7)
{
ct.Branch = bracct.Substring(0, 2);
ct.AccountNumber = bracct.Substring(2, 5);
ct.NameOnCheck = GetAccountName(ct.Branch + ct.AccountNumber);
ct.AccountBalance = GetAccountBalance(ct.Branch + ct.AccountNumber);
}
else
{
ct.Branch = Configuration.Branch;
ct.AccountNumber = string.Empty;
ct.NameOnCheck = string.Empty;
ct.AccountBalance = 0;
}
ct.CheckAmount = 0;
ct.BankRoutingNumber = psc.BankRoutingNumber;
ct.BankAccountNumber = psc.BankAccountNumber;
ct.CheckNumber = psc.CheckNumber;
ct.Status = "Entered";
checkTrans.IndividualCheck.Rows.Add(ct);
}
else
{
label_Status.Text = Resources.ScanCheck_ScanFailed;
}
_checkData = string.Empty;
var rs = new RegistrySettings();
if (!rs.ScanChecksContinuous)
{
StopScanning();
label_Status.Text = Resources.ScanCheck_Success;
EditLastRowEntered();
}
label_ChecksScanned.Text = (dgv_Checks.RowCount - 1).ToString();
}
When the timer goes off, I verified that I have received all of the data, then I add it to the dataset. It's being added to the dataset without issue, it's just being seen on the datagridview every time. Sometimes it works, most time it doesn't.
How do I get the datagridview to update when changes are done to the dataset? Am I doing something wrong in the above code?
Thanks! (again)
If you created the dataset and attached it to the DataGridView using the Visual Studio Data Source Configuration Wizard, then you probably have a call to
this.somethingTableAdapter.Fill(this.yourDataSet.someDataTable);
somewhere in your code. This is what actually loads the data from the DataSet into your DataGridView. While calling this method again might not be the 'proper' way to refresh your DGV, it did the job for me.
Related
created a few seconds ago
Hi,
I am creating a web page in asp.net based on data from a database. This should result in a number of tab pages with card views on each tab with 5 columns and a maximum of 20 rows. The tab pages are working, the rows are working but the columns will not change from the default 3 columns.
I have tried setting the columnCount property at different stages, post and pre databinding. This getting frustrating.
I am having problems with setting a card views column count programmatically. I am setting it, have tried to set it in different places but it always goes to the default 3 columns :(
I am using C# in Visual studio 2017.
Here is the code I am using:
SqlDataSource sds = new SqlDataSource();
public string fName;
protected void Page_Load(object sender, EventArgs e)
{
string fid = Request.QueryString["FID"];
sds.ConnectionString = ConfigurationManager.ConnectionStrings["DataBaseConnection"].ToString();
sds.SelectCommand = "select name from [flashboard] where flashboardid = " + fid;
DataView fDet = (DataView)sds.Select(DataSourceSelectArguments.Empty);
fName = fDet.Table.Rows[0]["name"].ToString();
TitleLink.InnerHtml = fName;
sds.SelectCommand = "SELECT flashboardtabid, name FROM [FlashboardTab] WHERE flashboardid = " + fid+" order by SeqNo";
DataView fTab = (DataView)sds.Select(DataSourceSelectArguments.Empty);
TabPage tabDet;
ASPxPageControl tpc = ASPxPageControl1;
ASPxCardView cardGrp;
CardViewTextColumn cName;
CardViewHyperLinkColumn cEvidence;
foreach (DataRow tab in fTab.Table.Rows)
{
tabDet = new TabPage();
tabDet.Text = tab["name"].ToString();
tabDet.Name = "Tab"+tab["flashboardtabid"].ToString();
tabDet.ActiveTabStyle.Width = Unit.Percentage( 80);
cardGrp = new ASPxCardView();
cardGrp.ID = "CardGroup" + tab["flashboardtabid"].ToString() ;
tabDet.Controls.Add(cardGrp);
tpc.TabPages.Add(tabDet);
cardGrp.AutoGenerateColumns = false;
ASPxCardViewPagerSettings cvps = new ASPxCardViewPagerSettings(cardGrp);
cardGrp.EnableTheming = true;
cardGrp.Theme = "SoftOrange";
cvps.Visible = false;
cvps.SettingsTableLayout.ColumnCount = 5;
cvps.SettingsTableLayout.RowsPerPage = 20;
cardGrp.DataSource = GetData("SELECT cardid, Description, EvidencePage, SmartViewid FROM [flashboardcard] WHERE flashboardtabid = "+tab["flashboardtabid"] + " order by SeqNo");
cardGrp.Attributes.Add("Width", "80%");
cardGrp.Attributes.Add("style", "margin:auto");
cName = new CardViewTextColumn();
cName.Name = "Description";
cName.FieldName = "Description";
cEvidence = new CardViewHyperLinkColumn();
cEvidence.Name = "EvidencePage";
cEvidence.FieldName = "EvidencePage";
cEvidence.PropertiesHyperLinkEdit.Text = "Evidence";
cardGrp.Columns.Add(cName);
cardGrp.Columns.Add(cEvidence);
var layoutitem1 = new CardViewColumnLayoutItem(); // cardGrp.CardLayoutProperties.FindColumnItem("EvidencePage");
layoutitem1.ColumnName = "EvidencePage";
layoutitem1.ShowCaption = DevExpress.Utils.DefaultBoolean.False;
layoutitem1.HorizontalAlign = FormLayoutHorizontalAlign.Center;
var layoutitem2 = new CardViewColumnLayoutItem();
layoutitem2.ColumnName = "Description";
layoutitem2.ShowCaption = DevExpress.Utils.DefaultBoolean.False;
layoutitem2.HorizontalAlign = FormLayoutHorizontalAlign.Center;
layoutitem2.ParentContainerStyle.Font.Bold = true;
layoutitem2.ParentContainerStyle.Font.Size = FontUnit.Medium;
cardGrp.CardLayoutProperties.Items.Add(layoutitem2);
cardGrp.CardLayoutProperties.Items.Add(layoutitem1);
cardGrp.DataBind();
}
}
DataView GetData(String queryString)
{
DataView ds = new DataView();
sds.SelectCommand = queryString;
ds = (DataView)sds.Select(DataSourceSelectArguments.Empty);
return ds;
}
To resolve this issue with ColumnCount, I recommend you define it directly in the control's SettingsPager.SettingsTableLayout.ColumnCount property instead of specifying it in a new ASPxCardViewPagerSettings instance:
cardGrp.SettingsPager.SettingsTableLayout.ColumnCount = 5;
cardGrp.SettingsPager.SettingsTableLayout.RowsPerPage = 20;
Do you know if there is any validation to know the end of a datagridview? I'm making an update to the database but my code throws an error at this line (if (BANDASMAGNETICAS.Exists(x => x.Equals(item.cheques_banda_magnetica)))), because there are more records in the db than the datagrid.
foreach (var item in objCheques)
{
if (BANDASMAGNETICAS.Exists(x => x.Equals(item.cheques_banda_magnetica)))
{
string sBanda = BANDASMAGNETICAS[iBandaMagnetica].ToString();
Ext_Cheques.ActualizarBandaMagnetica(sBanda, false);
item.cheques_suc = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["# SUC"].Value.ToString();
item.cheques_cod_aut = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["COD_AUT"].Value.ToString();
item.cheques_dig_pre = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["DIG_PRE"].Value.ToString();
item.cheques_cve_ope = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["CVE_OPE"].Value.ToString();
item.cheques_plaza = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["PLAZA"].Value.ToString();
item.cheques_banco = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["BANCO"].Value.ToString();
item.cheques_dig_int = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["DIG_INT"].Value.ToString();
item.cheques_cuenta = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["CUENTA"].Value.ToString();
item.cheques_cheque = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["# CHEQUE"].Value.ToString();
item.cheques_banda_magnetica = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["BANDA MAGNETICA"].Value.ToString();
item.cheques_fecha_deposito = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["FECHA_DEPOSITO"].Value.ToString();
item.cheques_fecha_liberacion = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["FECHA_LIBERACION"].Value.ToString();
item.cheques_importe_cheque = dgvBaseArchivo.Rows[iBandaMagnetica].Cells["IMPORTE_CHEQUE"].Value.ToString();
item.cheques_activo = true;
//item.Insert();
}
}
Regards!!!
Thanks for your help, but I have to change the whole code because the variable iBandaMagnetica throws the error when the datagrid has no more records and the objCheques collection has more.
1.- I have to assign to a datatable the datagrid(dgvBaseArchivo) source like: DataTable dtRegistrosTXT = (DataTable)(dgvBaseArchivo.DataSource);
2.-Made a method named ActualizarBandaMagnetica():
private void ActualizarInsertarBandaMagnetica()
{
if (dgvBaseArchivo.Rows.Count <= 0)
{
MessageBox.Show("Primero carga el archivo", "Banco Azteca Cheques");
return;
}
else
{
Ext_ChequesCollection objCheques = Ext_Cheques.GetAll();
foreach(DataRow row in dtRegistrosTXT.Rows)
{
Thread myThread = new Thread(() => this.BuscarCheque(row, objCheques));
myThread.Start();
Procesando++;
}
timerProcesar.Stop();
FinProc = DateTime.Now;
Invoke(new MethodInvoker(delegate
{
cmdGuardar.Enabled = true;
cmdUploadFile.Enabled = true;
}));
MessageBox.Show("Proceso Finalizado", "Banco Azteca Cheques");
}
}
With this method, I avoid the use of iBandaMagnetica over the datagrid.
I'm trying to build several gridpanels with the result of a search in the DB.
But they never appears...
Here is my code, what's wrong with it ?
http://pastebin.com/WuTZwZrP
EDIT
Ok, got it. For those who have the same problem, I solved it by adding this to the GridPanel :
RenderTo = this.ExtPanel.ClientID
And this after the build :
ext.GridPanel grid = this.BuildGridPanel(forwarder.Key, forwarder.Value);
grid.Render();
//this.ExtPanel.Controls.Add(grid);
public void AddGridPanel()
{
Ext.Net.GridPanel g=new Ext.Net.GridPanel();
Ext.Net.Store store1=new Ext.Net.Store();
Model model = new Model();
for (int i = 1; i < tas.getTaskDE().Count / 2; i++)
{
fields = fields + "," + tas.getTaskDE()[i].FieldName;
ModelField modelField = new ModelField();
modelField.Name = tas.getTaskDE()[i].FieldName;
model.Fields.Add(modelField);
if (tas.getTaskDE()[i].Visibility == "true")
{
g.ColumnModel.Columns.Add(new ColumnBase[] {
new Column
{
Text = tas.getTaskDE()[i].FieldADName,
DataIndex = tas.getTaskDE()[i].FieldName,
Flex = 1
},
});
}
}
SqlDataSource s = new SqlDataSource();
s.ConnectionString =ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
s.SelectCommand = query;
store1.Model.Add(model);
store1.DataSource = s;
store1.DataBind();
g.Store.Add(store1);
g.Render(this.Form);
}
this an example of dynamic gridpanel hope it helps
I am Sending my DataGridview data to SQL database. I have created and initiate the connection. All working fine but when I have more than one raw in my Datagridview, I am getting more messages that means each and every raw getting me a successfully added I need to get only one message.
private void buttonsave_Click(object sender, EventArgs e)
{
InvoiceNew myobj = new InvoiceNew();
myobj.Invoicedate = dateTimePicker1.Value;
myobj.Invoiceno = textBoxInvoiceNo.Text;
myobj.Invoicetotal = Convert.ToDouble(textboxtotal.Text);
myobj.Balance = 0.00;
myobj.Paidammount = Convert.ToDouble(textboxtotal.Text);
myobj.AddInvoiceHeader(myobj);
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
InvoiceDetailNew myobjd = new InvoiceDetailNew();
myobjd.Invoiceno = textBoxInvoiceNo.Text;
myobjd.Itemcode = dataGridView1.Rows[i].Cells[0].Value.ToString();
myobjd.Itemname = dataGridView1.Rows[i].Cells[2].Value.ToString();
myobjd.Qty =
Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value.ToString());
myobjd.Unitprice =
Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value.ToString());
myobjd.Subtotal =
Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value.ToString());
myobjd.AddInvoiceDetail(myobjd);
main_menu myobj1 = new main_menu();
myobj1.Show();
this.Hide();
}
}
I wrote a very simple method. It saves data from class DayWeather to the database. Method checks if line with that day exist in table and update her or create a new line.
I am doing it by adding new class for LINQ and move table from Server Inspector to the constructor. It generate new class WeatherTBL.
Method itself looks like this:
public static void SaveDayWeather(DayWeather day)
{
using (DataClassesDataContext db = new DataClassesDataContext())
{
var existingDay =
(from d in db.WeatherTBL
where d.DateTime.ToString() == day.Date.ToString()
select d).SingleOrDefault<WeatherTBL>();
if (existingDay != null)
{
existingDay.Temp = day.Temp;
existingDay.WindSpeed = day.WindSpeed;
existingDay.Pressure = day.Pressure;
existingDay.Humidity = day.Humidity;
existingDay.Cloudiness = day.Cloudiness;
existingDay.TypeRecip = day.TypeRecip;
db.SubmitChanges();
}
else
{
WeatherTBL newDay = new WeatherTBL();
newDay.DateTime = day.Date;
newDay.Temp = day.Temp;
newDay.WindSpeed = day.WindSpeed;
newDay.Pressure = day.Pressure;
newDay.Humidity = day.Humidity;
newDay.Cloudiness = day.Cloudiness;
newDay.TypeRecip = day.TypeRecip;
db.WeatherTBL.InsertOnSubmit(newDay);
db.SubmitChanges();
}
}
}
When I tried to call him from UnitTest project:
[TestMethod]
public void TestDataAccess()
{
DayWeather day = new DayWeather(DateTime.Now);
DataAccessClass.SaveDayWeather(day);
}
It write, that test has passed successfully. But if look into table, it has`t chanched.
No error messages shows. Does anyone know whats the problem?
P.S. Sorry for my bad English.
UDP
Problem was in that:
"...db maybe copied to the debug or release folder at every build, overwriting your modified one". Thanks #Silvermind
I wrote simple method to save employee details into Database.
private void AddNewEmployee()
{
using (DataContext objDataContext = new DataContext())
{
Employee objEmp = new Employee();
// fields to be insert
objEmp.EmployeeName = "John";
objEmp.EmployeeAge = 21;
objEmp.EmployeeDesc = "Designer";
objEmp.EmployeeAddress = "Northampton";
objDataContext.Employees.InsertOnSubmit(objEmp);
// executes the commands to implement the changes to the database
objDataContext.SubmitChanges();
}
}
Please try with lambda expression. In your code, var existingDay is of type IQueryable
In order to insert or update, you need a variable var existingDay of WeatherTBL type.
Hence try using below..
var existingDay =
db.WeatherTBL.SingleOrDefault(d => d.DateTime.Equals(day.Date.ToString()));
if(existingDay != null)
{
//so on...
}
Hope it should work..
Linq to SQL
Detail tc = new Detail();
tc.Name = txtName.Text;
tc.Contact = "92"+txtMobile.Text;
tc.Segment = txtSegment.Text;
var datetime = DateTime.Now;
tc.Datetime = datetime;
tc.RaisedBy = Global.Username;
dc.Details.InsertOnSubmit(tc);
try
{
dc.SubmitChanges();
MessageBox.Show("Record inserted successfully!");
txtName.Text = "";
txtSegment.Text = "";
txtMobile.Text = "";
}
catch (Exception ex)
{
MessageBox.Show("Record inserted Failed!");
}