protected void gdvAccountType_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int RowIndex = Convert.ToInt32((e.RowIndex).ToString()); Label lblAccountType_ID = (Label)gdvAccountType.Rows[RowIndex].FindControl("lblAccountType_ID"); TextBox txtEditAccountType_Name = (TextBox)gdvAccountType.Rows[RowIndex].FindControl("txtEditAccountType_Name"); DropDownList ddlAccount_ID = (DropDownList)gdvAccountType.Rows[RowIndex].FindControl("ddlAccount_ID"); if (txtEditAccountType_Name.Text.Trim() != string.Empty) { dbo_AccountTypeClass cycle = new dbo_AccountTypeClass() { Account_Type_ID = lblAccountType_ID.Text, Account_Type = txtEditAccountType_Name.Text, Account_ID = ddlAccount_ID.Text }; string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value; bool success = false; success = dbo_AccountTypeDataClass.UpdateAccountType_New(cycle, User_ID); if (success) { gdvAccountType.EditIndex = -1; gdvAccountType.ShowFooter = false; gdvAccountType.DataSource = dbo_AccountTypeDataClass.GetAccountType_New(); gdvAccountType.DataBind(); } System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true); } else { System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true); Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน"); } } catch (Exception ex) { logger.Error(ex); } }
public static Boolean UpdateAccountType_New(dbo_AccountTypeClass clsAccountType, string userName) { /// Account_ID Account_Type_ID Account_Type /// รายรับ 01 ธนาคารกสิกรไทย /// รายรับ 03 ธนาคารทหารไทย /// รายรับ 04 ธนาคารกรุงไทย /// รายรับ 02 ธนาคารไทยพาณิชย์ SqlConnection connection = SAMDataClass.GetConnection(); string insertProcedure = "UpdateAccountType"; SqlCommand insertCommand = new SqlCommand(insertProcedure, connection); insertCommand.CommandType = CommandType.StoredProcedure; insertCommand.Parameters.AddWithValue("@Mode", "UpdAccountType"); insertCommand.Parameters.AddWithValue("@Account_ID", clsAccountType.Account_ID); insertCommand.Parameters.AddWithValue("@Account_Type_ID", clsAccountType.Account_Type_ID); insertCommand.Parameters.AddWithValue("@UpdateBY", userName); insertCommand.Parameters.AddWithValue("@UpdateParam", clsAccountType.Account_Type); try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { logger.Error(ex.Message); return(false); } finally { connection.Close(); } }
protected void gdvAccountType_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "EditAccountCode") { int RowIndex = Convert.ToInt32((e.CommandArgument).ToString()); List <dbo_AccountTypeClass> item1 = dbo_AccountTypeDataClass.GetAccountType_New(); if (item1.Count < gdvAccountType.Rows.Count && RowIndex > int.Parse(ViewState["current_index"].ToString())) { RowIndex--; } current_index = RowIndex; ViewState["current_index"] = current_index; LinkButton currbtn = (LinkButton)gdvAccountType.Rows[RowIndex].FindControl("lnkB_SetAccountCode"); //Label lblAccountType_ID = (Label)gdvAccountType.Rows[RowIndex].FindControl("lblAccountType_ID"); string accountTypeID = item1[RowIndex].Account_Type_ID; if (currbtn.Text == "แก้ไขรหัสบัญชี") { dbo_AccountTypeClass cycle = new dbo_AccountTypeClass() { }; List <dbo_AccountTypeClass> item = dbo_AccountTypeDataClass.GetAccountType_New(); item.Insert(RowIndex + 1, new dbo_AccountTypeClass() { }); gdvAccountType.DataSource = item; gdvAccountType.DataBind(); currbtn = (LinkButton)gdvAccountType.Rows[RowIndex].FindControl("lnkB_SetAccountCode"); currbtn.Text = "ปิด"; //List<dbo_AccountCodeClass> Account_Code = dbo_AccountTypeDataClass.GetAccountCode_New(lblAccountType_ID.Text); List <dbo_AccountCodeClass> Account_Code = dbo_AccountTypeDataClass.GetAccountCode_New(accountTypeID); GridView gv = (GridView)gdvAccountType.Rows[RowIndex + 1].FindControl("gdvAccountCode"); Button newbutton1 = (Button)gdvAccountType.Rows[RowIndex + 1].FindControl("btnCreateAccountCode"); LinkButton Cycle_Name = (LinkButton)gdvAccountType.Rows[RowIndex + 1].FindControl("lnkB_SetAccountCode"); gv.DataSource = Account_Code; gv.DataBind(); gv.Visible = true; newbutton1.Visible = true; Cycle_Name.Visible = false; gdvAccountType.Rows[RowIndex + 1].Cells[3].ColumnSpan = 6; gdvAccountType.Rows[RowIndex + 1].Cells[0].Visible = false; gdvAccountType.Rows[RowIndex + 1].Cells[1].Visible = false; gdvAccountType.Rows[RowIndex + 1].Cells[2].Visible = false; gdvAccountType.Rows[RowIndex + 1].Cells[4].Visible = false; gdvAccountType.Rows[RowIndex + 1].Cells[5].Visible = false; gdvAccountType.Rows[RowIndex + 1].Cells[6].Visible = false; Label currlbl = (Label)gdvAccountType.Rows[RowIndex + 1].FindControl("lblOrder"); currlbl.Visible = false; currbtn.Visible = true; for (int i = RowIndex + 1; i < gdvAccountType.Rows.Count; i++) { Label lbl_Amount = (Label)gdvAccountType.Rows[i].FindControl("lblOrder"); lbl_Amount.Text = i.ToString(); } } else { List <dbo_AccountTypeClass> item = dbo_AccountTypeDataClass.GetAccountType_New(); gdvAccountType.DataSource = item; gdvAccountType.DataBind(); } } else if (e.CommandName == "AddNew") { TextBox txtNewAccountType_Name = (TextBox)gdvAccountType.FooterRow.FindControl("txtNewAccountType_Name"); DropDownList ddlFooterAccount_ID = (DropDownList)gdvAccountType.FooterRow.FindControl("ddlFooterAccount_ID"); if (txtNewAccountType_Name.Text.Trim() != string.Empty) { dbo_AccountTypeClass cycle = new dbo_AccountTypeClass() { Account_Type = txtNewAccountType_Name.Text, Account_ID = ddlFooterAccount_ID.Text }; bool success = false; string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value; success = dbo_AccountTypeDataClass.InsertAccountType_New(cycle, User_ID); if (success) { gdvAccountType.ShowFooter = false; List <dbo_AccountTypeClass> item = dbo_AccountTypeDataClass.GetAccountType_New(); gdvAccountType.DataSource = item; gdvAccountType.DataBind(); } System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true); } else { System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true); Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน"); } } } catch (Exception ex) { logger.Error(ex); } }