I have made a system, when use select Model,then the F.Grade dropdownlist will show the F.Grade belong to user select Model. So I put display F.Grade code into Model dropdownlist. But it is very slow when user use down arrow button to find model. This is because when down to next model, it will load the F.Grade for this Model. Any expert a good suggestion for this problem??? (Attach picture and code).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
namespace WindowsFormsApplication1.PDC
{
public partial class PDC : Form
{
OleDbCommand sCommand;
OleDbDataAdapter sAdapter;
OleDbCommandBuilder sBuilder;
DataSet sDs;
DataTable sTable;
public PDC()
{
InitializeComponent();
}
private void AddPDC_Load(object sender, EventArgs e)
{
dtpDeliveryDate.Value = System.DateTime.Today;
timerLoad.Enabled = true;
timer1.Enabled = true;
timer2.Enabled = true;
timerModel.Enabled = true;
}
private void txtStockIn_ValueChanged(object sender, EventArgs e)
{
if (txtQty.Value < txtStockIn.Value)
{
MessageBox.Show("Cannot exceed Quantity");
txtStockIn.Value = 0;
}
int a = Convert.ToInt32(txtQty.Value);
int b = Convert.ToInt32(txtStockIn.Value);
int c = Convert.ToInt32(txtItemPerPackage.Value);
txtShortage.Value = a - b;
}
private void txtItemPerPackage_ValueChanged(object sender, EventArgs e)
{
if (txtQty.Value < txtItemPerPackage.Value)
{
MessageBox.Show("Cannot exceed Quantity");
txtItemPerPackage.Value = 0;
}
int a = Convert.ToInt32(txtQty.Value);
int b = Convert.ToInt32(txtStockIn.Value);
int c = Convert.ToInt32(txtItemPerPackage.Value);
txtShortage.Value = a - b;
if (txtItemPerPackage.Value == 0)
{
//MessageBox.Show("Please enter number to Item per Pack field");
lblMessage.Text = ("Please enter number to Item per Pack field");
}
else
{
txtPackage.Value = a / c;
txtRemain.Value = a % c;
}
}
private void btnCalculate_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(txtQty.Value);
int b = Convert.ToInt32(txtStockIn.Value);
int c = Convert.ToInt32(txtItemPerPackage.Value);
txtShortage.Value = a - b;
if (txtItemPerPackage.Value == 0)
{
//MessageBox.Show("Please enter number to Item per Pack field");
lblMessage.Text = ("Please enter number to Item per Pack field");
}
else
{
txtPackage.Value = a / c;
txtRemain.Value = a % c;
}
}
private void cboModel_SelectedIndexChanged(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
OleDbConnection connection = new OleDbConnection(ConnectionString);
string sql = "SELECT DISTINCT FGrade FROM Product Where Model='" + cboModel.Text + "' Order By FGrade ";
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "Product");
sTable = sDs.Tables["Product"];
connection.Close();
cboFGrade.DataSource = sDs.Tables["Product"];
cboFGrade.DisplayMember = "FGrade";
cboFGrade.SelectedIndex = -1;
}
private void cboFGrade_SelectedIndexChanged(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
OleDbConnection connection = new OleDbConnection(ConnectionString);
string sql = "SELECT DISTINCT Thk FROM Product Where Model='" + cboModel.Text + "' and FGrade='" + cboFGrade.Text + "'Order By Thk";
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "Product");
sTable = sDs.Tables["Product"];
connection.Close();
cboThk.DataSource = sDs.Tables["Product"];
cboThk.DisplayMember = "Thk";
cboThk.SelectedIndex = -1;
}
private void cboThk_SelectedIndexChanged(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
OleDbConnection connection = new OleDbConnection(ConnectionString);
string sql = "SELECT DISTINCT FSize FROM Product Where Model='" + cboModel.Text + "' and FGrade='" + cboFGrade.Text + "' and Thk='" + cboThk.Text + "'Order By FSize";
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "Product");
sTable = sDs.Tables["Product"];
connection.Close();
cboSize.DataSource = sDs.Tables["Product"];
cboSize.DisplayMember = "FSize";
cboSize.SelectedIndex = -1;
}
private void cboSize_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void btnAdd_Click(object sender, EventArgs e)
{
OleDbConnection conAuthor;
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
//string conString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA Source= \\\\Wdsharespace\\Wansern_System\\Wansern_Foam\\Instyle Sofa\\Instyle_Sofa.mdb";
conAuthor = new OleDbConnection(ConnectionString);
OleDbCommand cmdInsert, cmdCheckID;
OleDbDataReader dtrCheckID;
conAuthor.Open();
string strChechID = "select * from PDC where PONO='" + txtPONO.Text + "' and Model='" + cboModel.Text + "'and FGrade='" + cboFGrade.Text + "' and Thk='" + cboThk.Text + "'and FSize='" + cboSize.Text + "'";
ConnectionString = "Insert Into PDC(PONO, DeliveryDate,Customer,Name,Item,Model,FGrade,Thk,FSize,Qty,StockIn,Shortage,Package,ItemPerPackage,Remain,io,l)Values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
cmdCheckID = new OleDbCommand(strChechID, conAuthor);
cmdInsert = new OleDbCommand(ConnectionString, conAuthor);
dtrCheckID = cmdCheckID.ExecuteReader();
if (String.IsNullOrEmpty(txtPONO.Text))
{
MessageBox.Show("PO NO field is empty");
conAuthor.Close();
dtrCheckID.Close();
}
try
{
if (dtrCheckID.HasRows)
{
MessageBox.Show("Duplicate Data!!!!!!");
dtrCheckID.Close();
}
else
{
dtrCheckID.Close();
cmdInsert.Parameters.AddWithValue("@PONO", txtPONO.Text);
cmdInsert.Parameters.AddWithValue("@DeliveryDate", dtpDeliveryDate.Value);
cmdInsert.Parameters.AddWithValue("@Customer", cboCustomer.Text);
cmdInsert.Parameters.AddWithValue("@Name", cboName.Text);
cmdInsert.Parameters.AddWithValue("@Item", txtItem.Text);
cmdInsert.Parameters.AddWithValue("@Model", cboModel.Text);
cmdInsert.Parameters.AddWithValue("@FGrade", cboFGrade.Text);
cmdInsert.Parameters.AddWithValue("@Thk", cboThk.Text);
cmdInsert.Parameters.AddWithValue("@FSize", cboSize.Text);
cmdInsert.Parameters.AddWithValue("@Qty", txtQty.Value);
cmdInsert.Parameters.AddWithValue("@StockIn", txtStockIn.Value);
cmdInsert.Parameters.AddWithValue("@Shortage", txtShortage.Value);
cmdInsert.Parameters.AddWithValue("@Package", txtPackage.Value);
cmdInsert.Parameters.AddWithValue("@ItemPerPackage", txtItemPerPackage.Value);
cmdInsert.Parameters.AddWithValue("@Remain", txtRemain.Value);
cmdInsert.Parameters.AddWithValue("@io", chkio.Checked);
cmdInsert.Parameters.AddWithValue("@l", chkl.Checked);
cmdInsert.ExecuteNonQuery();
conAuthor.Close();
timerLoad.Enabled = true;
lblMessage.Text=("Successful Update!!!");
}
}
catch (Exception)
{
//MessageBox.Show(ex.ToString());
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
string sql = "SELECT DISTINCT CName FROM Customer Order By CName";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "Customer");
sTable = sDs.Tables["Customer"];
connection.Close();
cboCustomer.DataSource = sDs.Tables["Customer"];
cboCustomer.DisplayMember = "CName";
connection.Close();
timer1.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
string sql = "SELECT DISTINCT Name FROM Staff Order By Name";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "Staff");
sTable = sDs.Tables["Staff"];
connection.Close();
cboName.DataSource = sDs.Tables["Staff"];
cboName.DisplayMember = "Name";
cboName.SelectedIndex = -1;
connection.Close();
timer2.Enabled = false;
}
private void timerLoad_Tick(object sender, EventArgs e)
{
dtpDeliveryDate.Value = System.DateTime.Today;
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
DateTime a = System.DateTime.Today;
DateTime b = a.AddDays(-90);
//string format = ("dd/MMM/yy");
//string c = b.ToString(format);
//string sql = "SELECT * FROM PDC where DeliveryDate >=@odate Order by DeliveryDate";
string sql = "SELECT * FROM PDC where Customer NOT LIKE '%Zhia Yi%' Order by DeliveryDate,PONO,Item";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
//sCommand.Parameters.AddWithValue("@odate", b);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "PDC");
sTable = sDs.Tables["PDC"];
connection.Close();
dataGridView1.DataSource = sDs.Tables["PDC"];
dataGridView1.ReadOnly = true;
save_btn.Enabled = false;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
//lblMessage.Text = "List of Production Daily Control from '" + b.ToShortDateString() + "' (Last 90 days)";
dtpDeliveryDate.Value = System.DateTime.Today;
cboCustomer.Text = "";
cboName.Text = "";
txtPONO.Text = "";
txtItem.Text = "";
cboModel.Text = "";
cboFGrade.Text = "";
cboThk.Text = "";
cboSize.Text = "";
txtQty.Value = 0;
txtStockIn.Value = 0;
txtShortage.Value = 0;
txtItemPerPackage.Value = 0;
txtPackage.Value = 0;
txtRemain.Value = 0;
//chkio.Checked = false;
//chkl.Checked = false;
timerLoad.Enabled = false;
}
private void btnRefresh_Click(object sender, EventArgs e)
{
timerLoad.Enabled = true;
}
private void delete_btn_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Do you want to delete this row ?", "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
sAdapter.Update(sTable);
}
}
private void new_btn_Click(object sender, EventArgs e)
{
dataGridView1.ReadOnly = false;
save_btn.Enabled = true;
new_btn.Enabled = false;
delete_btn.Enabled = false;
btnRefresh.Enabled = false;
btnAdd.Enabled = false;
btnUpdateTable.Enabled = false;
btnAddGoods.Enabled = false;
btnAll.Enabled = false;
btnReport.Enabled = false;
btnSaveTable.Enabled = false;
txtPONO.Enabled = false;
cboCustomer.Enabled = false;
cboModel.Enabled = false;
cboFGrade.Enabled = false;
cboThk.Enabled = false;
cboSize.Enabled = false;
btnReports.Enabled = false;
txtPONO.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
dtpDeliveryDate.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
cboCustomer.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
cboName.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
txtItem.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
cboModel.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
cboFGrade.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
cboThk.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
cboSize.Text = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
txtQty.Text = this.dataGridView1.CurrentRow.Cells[9].Value.ToString();
txtStockIn.Text = this.dataGridView1.CurrentRow.Cells[10].Value.ToString();
txtShortage.Text = this.dataGridView1.CurrentRow.Cells[11].Value.ToString();
txtItemPerPackage.Text = this.dataGridView1.CurrentRow.Cells[12].Value.ToString();
txtPackage.Text = this.dataGridView1.CurrentRow.Cells[13].Value.ToString();
txtRemain.Text = this.dataGridView1.CurrentRow.Cells[14].Value.ToString();
chkio.Checked = Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[15].Value.ToString());
chkl.Checked = Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[16].Value.ToString());
}
private void save_btn_Click(object sender, EventArgs e)
{
dataGridView1.ReadOnly = true;
save_btn.Enabled = false;
new_btn.Enabled = true;
delete_btn.Enabled = true;
btnAdd.Enabled = true;
btnReports.Enabled = true;
btnRefresh.Enabled = true;
txtPONO.Enabled = true;
cboCustomer.Enabled = true;
cboModel.Enabled = true;
cboFGrade.Enabled = true;
cboThk.Enabled = true;
cboSize.Enabled = true;
btnUpdateTable.Enabled = true;
btnSaveTable.Enabled = true;
btnAddGoods.Enabled = true;
btnAll.Enabled = true;
btnReport.Enabled = true;
OleDbConnection conAuthor;
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
conAuthor = new OleDbConnection(ConnectionString);
OleDbCommand cmdUpdate;
conAuthor.Open();
string strUpdate = "Update PDC set DeliveryDate=@DeliveryDate, Customer=@Customer, Name=@Name, Item=@Item, Qty=@Qty, StockIn=@StockIn,Shortage=@Shortage,ItemPerPackage=@ItemPerPackage,Package=@Package,Remain=@Remain,io=@io,l=@l where PONO=@PONO and Model=@Model and FGrade=@FGrade and Thk=@Thk and FSize=@FSize";
cmdUpdate = new OleDbCommand(strUpdate, conAuthor);
cmdUpdate.Parameters.AddWithValue("@DeliveryDate", dtpDeliveryDate.Value);
cmdUpdate.Parameters.AddWithValue("@Customer", cboCustomer.Text);
cmdUpdate.Parameters.AddWithValue("@Name", cboName.Text);
cmdUpdate.Parameters.AddWithValue("@Item", txtItem.Text);
cmdUpdate.Parameters.AddWithValue("@Qty", txtQty.Text);
cmdUpdate.Parameters.AddWithValue("@StockIn", txtStockIn.Value);
cmdUpdate.Parameters.AddWithValue("@Shortage", txtShortage.Value);
cmdUpdate.Parameters.AddWithValue("@ItemPerPackage", txtItemPerPackage.Value);
cmdUpdate.Parameters.AddWithValue("@Package", txtPackage.Value);
cmdUpdate.Parameters.AddWithValue("@Remain", txtRemain.Value);
cmdUpdate.Parameters.AddWithValue("@io", chkio.Checked);
cmdUpdate.Parameters.AddWithValue("@l", chkl.Checked);
cmdUpdate.Parameters.AddWithValue("@PONO", txtPONO.Text);
cmdUpdate.Parameters.AddWithValue("@Model", cboModel.Text);
cmdUpdate.Parameters.AddWithValue("@FGrade", cboFGrade.Text);
cmdUpdate.Parameters.AddWithValue("@Thk", cboThk.Text);
cmdUpdate.Parameters.AddWithValue("@FSize", cboSize.Text);
cmdUpdate.ExecuteNonQuery();
conAuthor.Close();
timerUpdateRefresh.Enabled = true;
}
private void btnAll_Click(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
string sql = "SELECT * FROM PDC Order by DeliveryDate";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "PDC");
sTable = sDs.Tables["PDC"];
connection.Close();
dataGridView1.DataSource = sDs.Tables["PDC"];
dataGridView1.ReadOnly = true;
save_btn.Enabled = false;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
lblMessage.Text="Display All Data";
dtpDeliveryDate.Value = System.DateTime.Today;
}
private void timerModels_Tick(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
string sql = "SELECT DISTINCT Model FROM Product Order By Model";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "Product");
sTable = sDs.Tables["Product"];
connection.Close();
cboModel.DataSource = sDs.Tables["Product"];
cboModel.DisplayMember = "Model";
cboModel.SelectedIndex = -1;
connection.Close();
timerModel.Enabled = false;
}
private void btnAddGoods_Click(object sender, EventArgs e)
{
OleDbCommand cmdCheckID;
OleDbDataReader dtrCheckID;
foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
string PONO = r.Cells[0].Value.ToString();
string DeliveryDate = r.Cells[1].Value.ToString();
string Customer = r.Cells[2].Value.ToString();
string Name = r.Cells[3].Value.ToString();
string Item = r.Cells[4].Value.ToString();
string Model = r.Cells[5].Value.ToString();
string FGrade = r.Cells[6].Value.ToString();
string Thk = r.Cells[7].Value.ToString();
string FSize = r.Cells[8].Value.ToString();
string Qty = r.Cells[9].Value.ToString();
string StockIn = r.Cells[10].Value.ToString();
string Shortage = r.Cells[11].Value.ToString();
string ItemPerPackage = r.Cells[12].Value.ToString();
string Package = r.Cells[13].Value.ToString();
string Remain = r.Cells[14].Value.ToString();
Boolean io = Convert.ToBoolean(r.Cells[15].Value.ToString());
Boolean l = Convert.ToBoolean(r.Cells[16].Value.ToString());
//Connectt to Database
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
//Code Insert Both values into database table
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
string strChechID = "select * from PDC_FG where PONO='" + PONO + "' and Model='" + Model + "' and FGrade='" + FGrade + "'and Thk='" + Thk + "'and FSize='" + FSize + "'";
cmdCheckID = new OleDbCommand(strChechID, con);
dtrCheckID = cmdCheckID.ExecuteReader();
OleDbCommand comm = new OleDbCommand("insert into PDC_FG values(@PONO,@DeliveryDate,@Customer,@Name,@Item,@Model,@FGrade,@Thk,@FSize,@Qty,@StockIn,@Shortage,@ItemPerPackage,@Package,@Remain,@io,@l)", con);
OleDbCommand comm1 = new OleDbCommand("Delete From PDC where PONO=@PONO and Model=@Model and FGrade=@FGrade and Thk=@Thk and FSize=@FSize", con);
try
{
if (dtrCheckID.HasRows)
{
MessageBox.Show("Duplicate Data!!!!!!");
dtrCheckID.Close();
}
else
{
dtrCheckID.Close();
comm.Parameters.AddWithValue("@PONO", PONO);
comm.Parameters.AddWithValue("@DeliveryDate", DeliveryDate);
comm.Parameters.AddWithValue("@Customer", Customer);
comm.Parameters.AddWithValue("@Name", Name);
comm.Parameters.AddWithValue("@Item", Item);
comm.Parameters.AddWithValue("@Model", Model);
comm.Parameters.AddWithValue("@FGrade", FGrade);
comm.Parameters.AddWithValue("@Thk", Thk);
comm.Parameters.AddWithValue("@FSize", FSize);
comm.Parameters.AddWithValue("@Qty", Qty);
comm.Parameters.AddWithValue("@StockIn", StockIn);
comm.Parameters.AddWithValue("@Shortage", Shortage);
comm.Parameters.AddWithValue("@ItemPerPackage", ItemPerPackage);
comm.Parameters.AddWithValue("@Package", Package);
comm.Parameters.AddWithValue("@Remain", Remain);
comm.Parameters.AddWithValue("@io", io);
comm.Parameters.AddWithValue("@l", l);
comm1.Parameters.AddWithValue("@PONO", PONO);
comm1.Parameters.AddWithValue("@Model", Model);
comm1.Parameters.AddWithValue("@FGrade", FGrade);
comm1.Parameters.AddWithValue("@Thk", Thk);
comm1.Parameters.AddWithValue("@FSize", FSize);
comm.ExecuteNonQuery();
comm1.ExecuteNonQuery();
con.Close();
timerLoad.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
private void timerUpdateRefresh_Tick(object sender, EventArgs e)
{
dtpDeliveryDate.Value = System.DateTime.Today;
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
DateTime a = System.DateTime.Today;
DateTime b = a.AddDays(-90);
//string format = ("dd/MMM/yy");
//string c = b.ToString(format);
//string sql = "SELECT * FROM PDC where DeliveryDate >=@odate Order by DeliveryDate";
string sql = "SELECT * FROM PDC where Customer NOT LIKE '%Zhia Yi%' Order by DeliveryDate DESC";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
//sCommand.Parameters.AddWithValue("@odate", b);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "PDC");
sTable = sDs.Tables["PDC"];
connection.Close();
dataGridView1.DataSource = sDs.Tables["PDC"];
dataGridView1.ReadOnly = true;
save_btn.Enabled = false;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
//lblMessage.Text = "List of Production Daily Control from '" + b.ToShortDateString() + "' (Last 90 days)";
dtpDeliveryDate.Value = System.DateTime.Today;
cboCustomer.Text = "";
cboName.Text = "";
txtPONO.Text = "";
txtItem.Text = "";
cboModel.Text = "";
cboFGrade.Text = "";
cboThk.Text = "";
cboSize.Text = "";
txtQty.Value = 0;
txtStockIn.Value = 0;
txtShortage.Value = 0;
txtItemPerPackage.Value = 0;
txtPackage.Value = 0;
txtRemain.Value = 0;
//chkio.Checked = false;
//chkl.Checked = false;
lblMessage.Text = ("Successful Update!!!");
timerUpdateRefresh.Enabled = false;
}
private void btnReport_Click(object sender, EventArgs e)
{
PDC_ReportControl myForm = new PDC_ReportControl();
myForm.Show();
}
private void btnUpdateTable_Click(object sender, EventArgs e)
{
dataGridView1.ReadOnly = false;
save_btn.Enabled = false;
new_btn.Enabled = false;
delete_btn.Enabled = false;
btnRefresh.Enabled = false;
btnAdd.Enabled = false;
btnUpdateTable.Enabled = false;
btnSaveTable.Enabled = true;
btnReports.Enabled = false;
btnAddGoods.Enabled = false;
btnAll.Enabled = false;
btnReport.Enabled = false;
}
private void btnSaveTable_Click(object sender, EventArgs e)
{
sAdapter.Update(sTable);
dataGridView1.ReadOnly = true;
save_btn.Enabled = true;
new_btn.Enabled = true;
delete_btn.Enabled = true;
btnRefresh.Enabled = true;
btnAdd.Enabled = true;
btnUpdateTable.Enabled = true;
btnSaveTable.Enabled = false;
btnAddGoods.Enabled = true;
btnAll.Enabled = true;
btnReport.Enabled = true;
btnReports.Enabled = true;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("calc");
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtPONO.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
dtpDeliveryDate.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
cboCustomer.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
cboName.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
txtItem.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
cboModel.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
cboFGrade.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
cboThk.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
cboSize.Text = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
txtQty.Text = this.dataGridView1.CurrentRow.Cells[9].Value.ToString();
txtStockIn.Text = this.dataGridView1.CurrentRow.Cells[10].Value.ToString();
txtShortage.Text = this.dataGridView1.CurrentRow.Cells[11].Value.ToString();
txtItemPerPackage.Text = this.dataGridView1.CurrentRow.Cells[12].Value.ToString();
txtPackage.Text = this.dataGridView1.CurrentRow.Cells[13].Value.ToString();
txtRemain.Text = this.dataGridView1.CurrentRow.Cells[14].Value.ToString();
chkio.Checked = Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[15].Value.ToString());
chkl.Checked = Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[16].Value.ToString());
}
private void btnReports_Click(object sender, EventArgs e)
{
Report.Report_PDC_Process myForm = new Report.Report_PDC_Process();
myForm.Show();
}
/*private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
txtPONO.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
dtpDeliveryDate.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
cboCustomer.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
cboName.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
txtItem.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
cboModel.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
cboFGrade.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
cboThk.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
cboSize.Text = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
txtQty.Text = this.dataGridView1.CurrentRow.Cells[9].Value.ToString();
txtStockIn.Text = this.dataGridView1.CurrentRow.Cells[10].Value.ToString();
txtShortage.Text = this.dataGridView1.CurrentRow.Cells[11].Value.ToString();
txtItemPerPackage.Text = this.dataGridView1.CurrentRow.Cells[12].Value.ToString();
txtPackage.Text = this.dataGridView1.CurrentRow.Cells[13].Value.ToString();
txtRemain.Text = this.dataGridView1.CurrentRow.Cells[14].Value.ToString();
chkio.Checked = Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[15].Value.ToString());
chkl.Checked = Convert.ToBoolean(this.dataGridView1.CurrentRow.Cells[16].Value.ToString());
}*/
}
}