public static string SP_GetPermohonanStockByProcessIdTemp(out Data.PermohonanStok ps, string pid)
        {
            ps = null;
            SqlConnection sqlConn = new SqlConnection();  //defines database connection
            SqlCommand sqlCmd = new SqlCommand();  //defines what to do
            SqlDataAdapter sqlAdap = new SqlDataAdapter();

            try
            {
                sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["AMS_StockConnectionString"].ToString();
                sqlConn.Open();

                sqlCmd.CommandText = "SP_GetPermohonanStockByProcessIdTemp";
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Connection = sqlConn;

                SqlParameter parm1 = new SqlParameter("@ProcessIdTemp", SqlDbType.VarChar);
                parm1.Value = pid;
                parm1.Direction = ParameterDirection.Input;
                sqlCmd.Parameters.Add(parm1);

                sqlAdap.SelectCommand = sqlCmd;
                DataSet ds = new DataSet();
                sqlAdap.Fill(ds);

                DataRow dr = ds.Tables[0].Rows[0];
                ps = new Data.PermohonanStok
                {
                    ProcessId = (int)dr["ProcessId"],
                    ProcessIdTemp = dr["ProcessIdTemp"].ToString(),

                    PemohonJabatan = dr["PemohonJabatan"].ToString(),
                    PemohonJawatan = dr["PemohonJawatan"].ToString(),
                    PemohonNama = dr["PemohonNama"].ToString(),
                    PemohonNoKakitangan = dr["PemohonNoKakitangan"].ToString(),
                    PemohonEmpSysId = (int)dr["PemohonEmpSysId"],

                    PermohonanTarikhDiKehendaki = dr["RequiredDate"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["RequiredDate"].ToString()),
                    PtjId = (int)dr["PtjId"],
                    PermohonanTujuan = dr["Purpose"] == DBNull.Value ? "" : dr["Purpose"].ToString(),
                    CreationDate = dr["CreationDate"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["CreationDate"].ToString()),
                    Status = (int)dr["Status"],
                };

                return string.Empty;
            }
            catch (Exception err)
            {
                return err.Message;
            }
            finally
            { sqlConn.Close(); sqlConn.Dispose(); sqlCmd.Dispose(); }
        }
        public static string SP_FindPermohonanStokByProcessId(out Data.PermohonanStok ps, string pId)
        {
            ps = null;
            SqlConnection sqlConn = new SqlConnection();  //defines database connection
            SqlCommand sqlCmd = new SqlCommand();  //defines what to do
            SqlDataAdapter sqlAdap = new SqlDataAdapter();

            try
            {
                sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["AMS_StockConnectionString"].ToString();
                sqlConn.Open();

                sqlCmd.CommandText = "SP_GetPermohonanStockByProcessId";
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Connection = sqlConn;

                SqlParameter parm1 = new SqlParameter("@ProcessId", SqlDbType.Int);
                parm1.Value = int.Parse(pId);
                parm1.Direction = ParameterDirection.Input;
                sqlCmd.Parameters.Add(parm1);

                sqlAdap.SelectCommand = sqlCmd;
                DataSet ds = new DataSet();
                sqlAdap.Fill(ds);

                DataRow dr = ds.Tables[0].Rows[0];
                ps = new Data.PermohonanStok();
                ps.ProcessId = (int)dr["ProcessId"];
                ps.ProcessIdTemp = dr["ProcessIdTemp"].ToString();
                //Pemohon
                ps.PemohonEmpSysId = (int)dr["PemohonEmpSysId"];
                ps.PemohonNama = dr["PemohonNama"].ToString();
                ps.PemohonNoKakitangan = dr["PemohonNoKakitangan"].ToString();
                ps.PemohonJawatan = dr["PemohonJawatan"].ToString();
                ps.PemohonJabatan = dr["PemohonJabatan"].ToString();

                ps.PtjId = (int)dr["PtjId"];
                ps.CreationDate = dr["CreationDate"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["CreationDate"].ToString());
                ps.Status = (int)dr["Status"];
                ps.PtjDiPohon = (int)dr["PtjDiPohon"];
                ps.PermohonanKuantitiDiPohon = (int)dr["KuantitDiPohon"];
                ps.StokDiPohon = (int)dr["StokDiPohon"];
                ps.StorDiPohon = (int)dr["StorDiPohon"];
                ps.PermohonanPtjDipohonNama = dr["PermohonanPtjDipohonNama"].ToString();
                ps.PermohonanStokDiPohonNama = dr["PermohonanStokDiPohonNama"].ToString();
                ps.PermohonanStorDiPohonNama = dr["PermohonanStorDiPohonNama"].ToString();
                ps.PermohonanTujuan = dr["Purpose"] == DBNull.Value ? "" : dr["Purpose"].ToString();
                ps.PermohonanTarikhDiKehendaki = dr["RequiredDate"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["RequiredDate"].ToString());
                ps.PermohonanToJenis = (int)dr["PermohonanToJenis"];
                ps.PermohonanToNama = dr["PermohonanToNama"] == DBNull.Value ? 0 : (int)dr["PermohonanToNama"];
                ps.PermohonanToPtj = dr["PermohonanToPtj"] == DBNull.Value ? 0 : (int)dr["PermohonanToPtj"];
                ps.PermohonanToStor = dr["PermohonanToStor"] == DBNull.Value ? 0 : (int)dr["PermohonanToStor"];

                ps.PegawaiKelulusanEmpSysId = dr["PegawaiKelulusanEmpSysId"] == DBNull.Value ? 0 : (int)dr["PegawaiKelulusanEmpSysId"];
                ps.TarikhDiluluskan = dr["TarikhDiluluskan"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["TarikhDiluluskan"].ToString());
                ps.KuantitiDiluluskan = dr["KuantitiDiluluskan"] == DBNull.Value ? 0 : (int)dr["KuantitiDiluluskan"];

                ps.PengeluaranEmpSysId = dr["PengeluaranEmpSysId"] == DBNull.Value ? 0 : (int)dr["PengeluaranEmpSysId"];
                ps.PengeluaranTarikh = dr["PengeluaranTarikh"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(dr["PengeluaranTarikh"].ToString());
                ps.PengeluaranKuantiti = dr["PengeluaranKuantiti"] == DBNull.Value ? 0 : (int)dr["PengeluaranKuantiti"];
                ps.PengeluaranCatatan = dr["PengeluaranCatatan"].ToString();

                return string.Empty;
            }
            catch (Exception err)
            {
                return err.Message;
            }
            finally
            { sqlConn.Close(); sqlConn.Dispose(); sqlCmd.Dispose(); }
        }