bindingNavigator控件为什么新增不好用

泥泥 2013-06-29 03:18:22
///windiw load
this.bindingNavigatorAddNewItem.Enabled = true;
this.toolStripButton1.Enabled = true;
this.toolStripButton2.Enabled = false;
this.toolStripButton3.Enabled = false;
this.toolStripButton4.Enabled = true;
this.toolStripButton5.Enabled = true;
this.bindingNavigatorMoveFirstItem.Enabled = true;
this.bindingNavigatorMoveLastItem.Enabled = true;
this.bindingNavigatorMoveNextItem.Enabled = true;
this.bindingNavigatorMovePreviousItem.Enabled = true;
this.bindingNavigatorPositionItem.Enabled = true;
this.dataGridView1.Enabled = true;
this.DisEnableControl();

cmdSelect = new SqlCommand();
cmdSelect.CommandText = "select * from paymentByCheque ";
cmdSelect.Connection = sqlConnection1;



chequeDS = this.LoadDataToDs();
if (chequeDS != null)
{
this.bindingSource1.DataSource = this.chequeDS;
this.bindingSource1.DataMember = "ChequeT";
this.bindingNavigator1.BindingSource = this.bindingSource1;
CustomizeMyDataGridViewStyle();

this.txtChequeNum.DataBindings.Add("Text", this.bindingSource1, "chequeNum");
this.txtBankName.DataBindings.Add("Text", this.bindingSource1, "BankName");
this.txtChequAmount.DataBindings.Add("Text", this.bindingSource1, "Amount");
this.txtCreateBy.DataBindings.Add("Text", this.bindingSource1, "PayBy");
this.txtCreateDate.DataBindings.Add("Text", this.bindingSource1, "PayDate", true);
this.tbId.DataBindings.Add("Text",this.bindingSource1,"ID");

}

cmdUpdate = new SqlCommand();
cmdUpdate.CommandText = "update paymentByCheque set ChequeNum=@ChequeNum ,BankName=@BankName,Amount=@Amount where ID=@ID";
cmdUpdate.Connection = sqlConnection1;
sda.UpdateCommand = cmdUpdate;
SqlParameter id = sda.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID");
id.SourceVersion = DataRowVersion.Original;

cmdUpdate.Parameters.Add("@ChequeNum", SqlDbType.NVarChar, 50, "ChequeNum");
cmdUpdate.Parameters.Add("@BankName", SqlDbType.NVarChar, 100, "BankName");
cmdUpdate.Parameters.Add("@Amount", SqlDbType.Decimal, 9, "Amount");

cmdInsert = new SqlCommand();
cmdInsert.CommandText = "insert into paymentByCheque (chequenum,bankname,amount,paydate,id)values(@ChequeNum,@BankName,@Amount,@PayDate,@PayBy,@ID)";
cmdInsert.Connection = sqlConnection1;
sda.InsertCommand = cmdInsert;



cmdInsert.Parameters.Add("@ChequeNum", SqlDbType.NVarChar, 50, "ChequeNum");
cmdInsert.Parameters.Add("@BankName", SqlDbType.NVarChar, 100, "BankName");
cmdInsert.Parameters.Add("@Amount", SqlDbType.Decimal, 9, "Amount");
cmdInsert.Parameters.Add("@PayDate", SqlDbType.DateTime, 8, "PayDate");
cmdInsert.Parameters.Add("@PayBy", SqlDbType.NVarChar, 50, "PayBy");
cmdInsert.Parameters.Add("@ID", SqlDbType.Int, 4, "ID");




cmdDelete = new SqlCommand();
cmdDelete.CommandText = "delete from paymentByCheque where ID=@ID";
cmdDelete.Connection = sqlConnection1;
sda.DeleteCommand = cmdDelete;
SqlParameter SeqID = sda.DeleteCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID");
SeqID.SourceVersion = DataRowVersion.Original;
//新增
dsStatus = "dsInsert";
this.bindingNavigatorAddNewItem.Enabled = false;
this.toolStripButton1.Enabled = false;
this.toolStripButton2.Enabled = true;
this.toolStripButton3.Enabled = true;
this.toolStripButton4.Enabled = false;
this.toolStripButton5.Enabled = false;
this.bindingNavigatorMoveFirstItem.Enabled = false;
this.bindingNavigatorMoveLastItem.Enabled = false;
this.bindingNavigatorMoveNextItem.Enabled = false;
this.bindingNavigatorMovePreviousItem.Enabled = false;
this.bindingNavigatorPositionItem.Enabled = false;
this.dataGridView1.Enabled = false;
this.EnableControl();

this.txtCreateBy.Text = BussinessLevel.ShareClass.userID;
this.txtCreateDate.Text = System.DateTime.Now.ToString("dd/MM/yyyy");
tbId.Text = GetMaxID().ToString();
//保存
if (this.txtChequeNum.Text.Trim() == string.Empty)
{
MessageBox.Show("Please input cheque# first !","Harbour Hotel",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
if (this.txtChequAmount.Text.Trim() == string.Empty)
{
MessageBox.Show("Please input amount first !", "Harbour Hotel", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (this.txtBankName.Text.Trim() == string.Empty)
{
MessageBox.Show("Please input bank name first !", "Harbour Hotel", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}

try
{
if (sqlConnection1.State == ConnectionState.Closed) sqlConnection1.Open();


this.bindingSource1.EndEdit();
if (chequeDS.HasChanges() == true)
{

sda.Update(chequeDS.Tables[0]);
chequeDS.Tables[0].AcceptChanges();
chequeDS.Clear(); //******
sda.Fill(chequeDS, "ChequeT");//*******


}



this.bindingSource1.ResetBindings(true);
dsStatus = "dsBrowse";
this.bindingNavigatorAddNewItem.Enabled = true;
this.toolStripButton1.Enabled = true;
this.toolStripButton2.Enabled = false;
this.toolStripButton3.Enabled = false;
this.toolStripButton4.Enabled = true;
this.toolStripButton5.Enabled = true;
this.bindingNavigatorMoveFirstItem.Enabled = true;
this.bindingNavigatorMoveLastItem.Enabled = true;
this.bindingNavigatorMoveNextItem.Enabled = true;
this.bindingNavigatorMovePreviousItem.Enabled = true;
this.bindingNavigatorPositionItem.Enabled = true;
this.dataGridView1.Enabled = true;
this.DisEnableControl();

...全文
72 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧