using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;

public partial class POS_Comment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label2.Text = Request.QueryString["action"];
            Label4.Text = Request.QueryString["clID"];
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtCardNo.Text.Length == 0)
            lblError.Text = "This field can't be blank";
        else
        {
            string error = "";
            bool saved = addComment( ref error);
            if (saved)
            {
                lblError.Text = "Comment saved";
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.close();", true);
            }
            else
            {
                lblError.Text = error;
            }
        }
    }

    private bool addComment(ref string error)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "MERCHANT_REG_NOTE_EDITOR.Add_Reg_Note";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_client_no", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_act_name", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_note", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_client_no"].Value = Request.QueryString["clID"];
        oracom.Parameters["p_act_name"].Value = Request.QueryString["action"];
        oracom.Parameters["p_note"].Value = txtCardNo.Text;

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }
}
