private bool saveData()
        {
            bool   blnResult  = false;
            string strMessage = string.Empty;
            //Head
            string stritem_acc_doc     = string.Empty;
            string stritem_acc_year    = string.Empty;
            string strpay_month        = string.Empty;
            string strpay_year         = string.Empty;
            string stritem_acc_comment = string.Empty;
            //Detail
            string stritem_acc_detail_id = "0";
            string stritem_acc_deka;
            string stritem_acc_group;
            string stritem_acc_amount;
            string stritem_acc_tax;
            string stritem_acc_total;
            string stritem_acc_code;
            string stritem_project_code;
            string stritem_code;
            string strproduce_code;

            string strc_user = Session["username"].ToString();

            string    strScript = string.Empty;
            bool      blnDup    = false;
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds        = new DataSet();

            try
            {
                #region set Data
                stritem_acc_doc     = txtitem_acc_doc.Text;
                stritem_acc_year    = cboYear.SelectedValue;
                strpay_month        = cboPay_Month.SelectedValue;
                strpay_year         = cboPay_Year.SelectedValue;
                stritem_acc_comment = txtcomments.Text;
                #endregion

                if (ViewState["mode"].ToString().ToLower().Equals("add"))
                {
                    #region insert
                    string strCheckDup = string.Empty;
                    strCheckDup = " and pay_year = '" + strpay_year + "' " +
                                  " and pay_month = '" + strpay_month + "'" +
                                  " and budget_type = '" + this.BudgetType + "'" +
                                  " and c_created_by = '" + UserLoginName + "' ";
                    if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            blnDup    = true;
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" +
                                "\\n รอบเดือน : " + cboPay_Month.SelectedItem.Text + "   ปี : " + strpay_year +
                                "\\nซ้ำ\");\n";
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript, true);
                        }
                        else
                        {
                            if (!oItem_acc.SP_ITEM_ACC_HEAD_INS(stritem_acc_year, strpay_month,
                                                                strpay_year, stritem_acc_comment, strc_user, "B", ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            else
                            {
                                DataSet dsCHK = new DataSet();
                                strCheckDup = " and pay_year = '" + strpay_year + "' " +
                                              " and pay_month = '" + strpay_month + "' " +
                                              " and budget_type = '" + this.BudgetType + "'" +
                                              " and c_created_by = '" + UserLoginName + "' ";
                                if (!oItem_acc.SP_ITEM_ACC_HEAD_SEL(strCheckDup, ref dsCHK, ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                                else
                                {
                                    stritem_acc_doc           = dsCHK.Tables[0].Rows[0]["item_acc_doc"].ToString();
                                    ViewState["item_acc_doc"] = stritem_acc_doc;
                                    blnResult = true;
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region update
                    if (!oItem_acc.SP_ITEM_ACC_HEAD_UPD(stritem_acc_doc, stritem_acc_year, strpay_month, strpay_year,
                                                        stritem_acc_comment, strc_user, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        #region insert detail
                        GridViewRow gviewRow;
                        int         i;
                        for (i = 0; i <= GridView1.Rows.Count - 1; i++)
                        {
                            gviewRow = GridView1.Rows[i];
                            Label lblitem_acc_code = (Label)gviewRow.FindControl("lblitem_acc_code");
                            //if (lblitem_acc_code.Text != "")
                            //{
                            HiddenField hdditem_acc_detail_id = (HiddenField)gviewRow.FindControl("hdditem_acc_detail_id");
                            TextBox     txtitem_acc_deka      = (TextBox)gviewRow.FindControl("txtitem_acc_deka");
                            TextBox     txtitem_acc_group     = (TextBox)gviewRow.FindControl("txtitem_acc_group");
                            TextBox     txtitem_project_code  = (TextBox)gviewRow.FindControl("txtitem_project_code");
                            AwNumeric   txtitem_acc_amount    = (AwNumeric)gviewRow.FindControl("txtitem_acc_amount");
                            AwNumeric   txtitem_acc_tax       = (AwNumeric)gviewRow.FindControl("txtitem_acc_tax");
                            AwNumeric   txtitem_acc_total     = (AwNumeric)gviewRow.FindControl("txtitem_acc_total");
                            //Label lblitem_acc_code = (Label)gviewRow.FindControl("txtitem_code");
                            Label lblitem_code             = (Label)gviewRow.FindControl("lblitem_code");
                            Label lblproduce_code          = (Label)gviewRow.FindControl("lblproduce_code");
                            Label lblperson_group_code_acc = (Label)gviewRow.FindControl("lblperson_group_code_acc");
                            Label lblpayment_back_type     = (Label)gviewRow.FindControl("lblpayment_back_type");

                            stritem_acc_detail_id = hdditem_acc_detail_id.Value.ToString();
                            stritem_acc_deka      = txtitem_acc_deka.Text.Trim();
                            stritem_acc_group     = txtitem_acc_group.Text.Trim();
                            stritem_acc_amount    = txtitem_acc_amount.Value.ToString();
                            stritem_acc_tax       = txtitem_acc_tax.Value.ToString();
                            stritem_acc_total     = txtitem_acc_total.Value.ToString();
                            stritem_acc_code      = lblitem_acc_code.Text;
                            stritem_project_code  = txtitem_project_code.Text.Trim();
                            strproduce_code       = lblproduce_code.Text;
                            stritem_code          = lblitem_code.Text;

                            if (stritem_acc_detail_id != "0")
                            {
                                if (!oItem_acc.SP_ITEM_ACC_DETAIL_UPD(stritem_acc_detail_id, txtitem_acc_doc.Text.Trim(),
                                                                      stritem_acc_deka, stritem_acc_group, stritem_acc_amount,
                                                                      stritem_acc_tax, stritem_acc_total, stritem_acc_code,
                                                                      stritem_project_code, stritem_code, strproduce_code,
                                                                      ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                            }
                            else
                            {
                                if (!oItem_acc.SP_ITEM_ACC_DETAIL_INS(txtitem_acc_doc.Text.Trim(), stritem_acc_deka, stritem_acc_group,
                                                                      stritem_acc_amount, stritem_acc_tax, stritem_acc_total, stritem_acc_code,
                                                                      stritem_project_code, stritem_code, strproduce_code, lblperson_group_code_acc.Text.Trim(),
                                                                      lblpayment_back_type.Text, ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                            }
                            //}
                        }
                        #endregion
                        blnResult = true;
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oItem_acc.Dispose();
            }
            return(blnResult);
        }