Ejemplo n.º 1
0
        private bool saveData()
        {
            bool   blnResult = false;
            int    intcount_id;
            string strcount_name = string.Empty,
                   strUserName   = string.Empty,
                   strScript     = string.Empty;
            c3dCount obj3dCount  = new c3dCount();

            try
            {
                #region set Data
                intcount_id   = Helper.CInt(txtcount_id.Text);
                strcount_name = txtcount_name.Text;
                strUserName   = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    blnResult = obj3dCount.SP_COUNT_UPD(intcount_id, strcount_name, strUserName);
                }
                else
                {
                    #region insert
                    if (obj3dCount.SP_COUNT_INS(ref intcount_id, strcount_name, strUserName))
                    {
                        ViewState["count_id"] = intcount_id;
                        blnResult             = true;
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate") && ex.Message.Contains("IX_count_name"))
                {
                    strScript = "alert(\"ไม่สามารถแก้ไขข้อมูล เนื่องจากข้อมูล " + strcount_name.Trim() + "  ซ้ำ\");\n";
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                obj3dCount.Dispose();
            }
            return(blnResult);
        }