public ActionResult Create(LeaveRequest Createleave)
        {
            string reason;
            if (ModelState.IsValid)
            {
                if (cek_data("*", "KMIHRMS_DETAIL_LEAVE", "EMPID='" + Createleave.Empid + "' and leave_type='" + Createleave.SelectedItem + "' and to_char(FROMLEAVE,'dd/mm/yyyy')='" + Createleave.fromleave + "'and to_char(TOLEAVE,'dd/mm/yyyy')='" + Createleave.toleave + "'") == false)
                {
                    string connectionString = "Data Source=HRMSDEV;user id=PERSON;password=PERSON;Unicode=True;";
                    string empid, empname, bagian, namabagian, namaapproved, emailapproved;
                    using (OracleConnection connection = new OracleConnection(connectionString))
                    {
                        if (Createleave.SelectedItem == "CT")
                        {
                                OracleCommand cmd1 = new OracleCommand();
                                cmd1.CommandText = "INSERT INTO KMIHRMS_DETAIL_LEAVE (EMPID,LEAVE_TYPE,FROMLEAVE,TOLEAVE,REASON,ADDRESS,STATUS,DAYS) VALUES ('" + Createleave.Empid + "','" + Createleave.SelectedItem + "',to_date('" + Createleave.fromleave + "','DD/MM/YYYY'),to_date('" + Createleave.toleave + "','DD/MM/YYYY'),'" + Createleave.reasonpost1 + "','" + Createleave.Alamat + "','Release','" + Createleave.hari + "')";
                                cmd1.CommandType = CommandType.Text;
                                cmd1.Connection = connection;
                                connection.Open();
                                cmd1.ExecuteNonQuery();
                                OracleCommand cmd2 = new OracleCommand();
                                cmd2.CommandText = "select t.EMP_ID,t.EMP_NAME,T.COST_CENTER,t.CC_DESC from person.personal_master t where t.emp_id='" + Createleave.Empid + "'";
                                cmd2.CommandType = CommandType.Text;
                                cmd2.Connection = connection;
                                using (OracleDataReader rdr1 = cmd2.ExecuteReader())
                                {
                                    rdr1.Read();
                                    empid = rdr1.GetString(0);
                                    empname = rdr1.GetString(1);
                                    bagian = rdr1.GetString(2);
                                    namabagian = rdr1.GetString(3);
                                }
                                OracleCommand cmd3 = new OracleCommand();
                                cmd3.CommandText = "select KLAT.app1_id app_id,CEMT.EMP_NAME,cemt.email,KLAT.app1_as app_as from person.KMIHRMS_LEAVE_APP_TAB KLAT " +
                                    "INNER JOIN PERSON.CTM_EMPLOYEE_MASTER_TAB CEMT ON CEMT.EMP_ID=KLAT.APP1_ID " +
                                    "where requsioner_id='" + bagian + "' and app_type='HR'";
                                cmd3.CommandType = CommandType.Text;
                                cmd3.Connection = connection;
                                using (OracleDataReader rdr2 = cmd3.ExecuteReader())
                                {
                                    rdr2.Read();
                                    namaapproved = rdr2.GetString(1);
                                    emailapproved = rdr2.GetString(2);
                                }
                                sendmail(namaapproved, emailapproved, empid, empname, bagian, namabagian, DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null), DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null), Createleave.reasonpost1, Createleave.SelectedItem, Createleave.Alamat, Createleave.hpl, Createleave.tglkej, Createleave.times);
                                connection.Close();
                            /*}*/

                        }
                        else if (Createleave.SelectedItem == "CH")
                        {
                            TimeSpan date = (DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null) - DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null));
                            if (Math.Round(date.TotalDays + 1) > 2)
                            {
                                return Content("<script language='javascript' type='text/javascript'>alert('Your Request More Then 2 Days !');location.href = 'Create'; ;</script>", "WARNING");
                            }
                            else
                            {
                                OracleCommand cmd1 = new OracleCommand();
                                cmd1.CommandText = "INSERT INTO KMIHRMS_DETAIL_LEAVE (EMPID,LEAVE_TYPE,FROMLEAVE,TOLEAVE,ADDRESS,STATUS,DAYS) VALUES ('" + Createleave.Empid + "','" + Createleave.SelectedItem + "',to_date('" + Createleave.fromleave + "','DD/MM/YYYY'),to_date('" + Createleave.toleave + "','DD/MM/YYYY'),'" + Createleave.Alamat + "','Release','" + Createleave.hari + "')";
                                cmd1.CommandType = CommandType.Text;
                                cmd1.Connection = connection;
                                connection.Open();
                                cmd1.ExecuteNonQuery();
                                OracleCommand cmd2 = new OracleCommand();
                                cmd2.CommandText = "select t.EMP_ID,t.EMP_NAME,T.COST_CENTER,t.CC_DESC from person.personal_master t where t.emp_id='" + Createleave.Empid + "'";
                                cmd2.CommandType = CommandType.Text;
                                cmd2.Connection = connection;
                                using (OracleDataReader rdr1 = cmd2.ExecuteReader())
                                {
                                    rdr1.Read();
                                    empid = rdr1.GetString(0);
                                    empname = rdr1.GetString(1);
                                    bagian = rdr1.GetString(2);
                                    namabagian = rdr1.GetString(3);
                                }
                                OracleCommand cmd3 = new OracleCommand();
                                cmd3.CommandText = "select KLAT.app1_id app_id,CEMT.EMP_NAME,cemt.email,KLAT.app1_as app_as from person.KMIHRMS_LEAVE_APP_TAB KLAT " +
                                    "INNER JOIN PERSON.CTM_EMPLOYEE_MASTER_TAB CEMT ON CEMT.EMP_ID=KLAT.APP1_ID " +
                                    "where requsioner_id='" + bagian + "' and app_type='HR'";
                                cmd3.CommandType = CommandType.Text;
                                cmd3.Connection = connection;
                                using (OracleDataReader rdr2 = cmd3.ExecuteReader())
                                {
                                    rdr2.Read();
                                    namaapproved = rdr2.GetString(1);
                                    emailapproved = rdr2.GetString(2);
                                }
                                sendmail(namaapproved, emailapproved, empid, empname, bagian, namabagian, DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null), DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null), Createleave.reasonpost, Createleave.SelectedItem, Createleave.Alamat, Createleave.hpl, Createleave.tglkej, Createleave.times);
                                connection.Close();
                            }
                        }
                        else if (Createleave.SelectedItem == "DI")
                        {

                            if (Createleave.reasonpost== "Perkawinan")
                            {
                                reason = Createleave.reasonpost + " " + Createleave.detail;
                            }
                            else if (Createleave.reasonpost == "Meninggal Dunia")
                            {
                                reason = Createleave.reasonpost + " " + Createleave.detail1;
                            }
                            else
                            {
                                reason = Createleave.reasonpost;
                            }

                            OracleCommand cmd1 = new OracleCommand();
                            cmd1.CommandText = "INSERT INTO KMIHRMS_DETAIL_LEAVE (EMPID,LEAVE_TYPE,FROMLEAVE,TOLEAVE,ADDRESS,STATUS,REASON,DAYS,REALDATE,TIMESREAL) VALUES ('" + Createleave.Empid + "','" + Createleave.SelectedItem + "',to_date('" + Createleave.fromleave + "','DD/MM/YYYY'),to_date('" + Createleave.toleave + "','DD/MM/YYYY'),'" + Createleave.Alamat + "','Release','" + reason + "','" + Createleave.hari + "',to_date('" + Createleave.tglkej + "','DD/MM/YYYY'),to_date('" + Createleave.times + "','HH24:MI'))";
                            cmd1.CommandType = CommandType.Text;
                            cmd1.Connection = connection;
                            connection.Open();
                            cmd1.ExecuteNonQuery();
                            OracleCommand cmd2 = new OracleCommand();
                            cmd2.CommandText = "select t.EMP_ID,t.EMP_NAME,T.COST_CENTER,t.CC_DESC from person.personal_master t where t.emp_id='" + Createleave.Empid + "'";
                            cmd2.CommandType = CommandType.Text;
                            cmd2.Connection = connection;
                            using (OracleDataReader rdr1 = cmd2.ExecuteReader())
                            {
                                rdr1.Read();
                                empid = rdr1.GetString(0);
                                empname = rdr1.GetString(1);
                                bagian = rdr1.GetString(2);
                                namabagian = rdr1.GetString(3);
                            }
                            OracleCommand cmd3 = new OracleCommand();
                            cmd3.CommandText = "select KLAT.app1_id app_id,CEMT.EMP_NAME,cemt.email,KLAT.app1_as app_as from person.KMIHRMS_LEAVE_APP_TAB KLAT " +
                                "INNER JOIN PERSON.CTM_EMPLOYEE_MASTER_TAB CEMT ON CEMT.EMP_ID=KLAT.APP1_ID " +
                                "where requsioner_id='" + bagian + "' and app_type='HR'";
                            cmd3.CommandType = CommandType.Text;
                            cmd3.Connection = connection;
                            using (OracleDataReader rdr2 = cmd3.ExecuteReader())
                            {
                                rdr2.Read();
                                namaapproved = rdr2.GetString(1);
                                emailapproved = rdr2.GetString(2);
                            }
                            sendmail(namaapproved, emailapproved, empid, empname, bagian, namabagian, DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null), DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null), reason, Createleave.SelectedItem, Createleave.Alamat, Createleave.hpl, Createleave.tglkej, Createleave.times);
                            connection.Close();
                        }
                        else if (Createleave.SelectedItem == "I")
                        {
                            OracleCommand cmd1 = new OracleCommand();
                            cmd1.CommandText = "INSERT INTO KMIHRMS_DETAIL_LEAVE (EMPID,LEAVE_TYPE,FROMLEAVE,TOLEAVE,REASON,ADDRESS,STATUS,DAYS) VALUES ('" + Createleave.Empid + "','" + Createleave.SelectedItem + "',to_date('" + Createleave.fromleave + "','DD/MM/YYYY'),to_date('" + Createleave.toleave + "','DD/MM/YYYY'),'" + Createleave.reasonpost1 + "','" + Createleave.Alamat + "','Release','" + Createleave.hari + "')";
                            cmd1.CommandType = CommandType.Text;
                            cmd1.Connection = connection;
                            connection.Open();
                            cmd1.ExecuteNonQuery();
                            OracleCommand cmd2 = new OracleCommand();
                            cmd2.CommandText = "select t.EMP_ID,t.EMP_NAME,T.COST_CENTER,t.CC_DESC from person.personal_master t where t.emp_id='" + Createleave.Empid + "'";
                            cmd2.CommandType = CommandType.Text;
                            cmd2.Connection = connection;
                            using (OracleDataReader rdr1 = cmd2.ExecuteReader())
                            {
                                rdr1.Read();
                                empid = rdr1.GetString(0);
                                empname = rdr1.GetString(1);
                                bagian = rdr1.GetString(2);
                                namabagian = rdr1.GetString(3);
                            }
                            OracleCommand cmd3 = new OracleCommand();
                            cmd3.CommandText = "select KLAT.app1_id app_id,CEMT.EMP_NAME,cemt.email,KLAT.app1_as app_as from person.KMIHRMS_LEAVE_APP_TAB KLAT " +
                                "INNER JOIN PERSON.CTM_EMPLOYEE_MASTER_TAB CEMT ON CEMT.EMP_ID=KLAT.APP1_ID " +
                                "where requsioner_id='" + bagian + "' and app_type='HR'";
                            cmd3.CommandType = CommandType.Text;
                            cmd3.Connection = connection;
                            using (OracleDataReader rdr2 = cmd3.ExecuteReader())
                            {
                                rdr2.Read();
                                namaapproved = rdr2.GetString(1);
                                emailapproved = rdr2.GetString(2);
                            }
                            sendmail(namaapproved, emailapproved, empid, empname, bagian, namabagian, DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null), DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null), Createleave.reasonpost1, Createleave.SelectedItem, Createleave.Alamat, Createleave.hpl, Createleave.tglkej, Createleave.times);
                            connection.Close();
                        }
                        else if (Createleave.SelectedItem == "CI")
                        {
                            OracleCommand cmd1 = new OracleCommand();
                            cmd1.CommandText = "INSERT INTO KMIHRMS_DETAIL_LEAVE (EMPID,LEAVE_TYPE,FROMLEAVE,TOLEAVE,REASON,ADDRESS,STATUS,DAYS) VALUES ('" + Createleave.Empid + "','" + Createleave.SelectedItem + "',to_date('" + Createleave.fromleave + "','DD/MM/YYYY'),to_date('" + Createleave.toleave + "','DD/MM/YYYY'),'" + Createleave.reasonpost1 + "','" + Createleave.Alamat + "','Release','" + Createleave.hari + "')";
                            cmd1.CommandType = CommandType.Text;
                            cmd1.Connection = connection;
                            connection.Open();
                            cmd1.ExecuteNonQuery();
                            OracleCommand cmd2 = new OracleCommand();
                            cmd2.CommandText = "select t.EMP_ID,t.EMP_NAME,T.COST_CENTER,t.CC_DESC from person.personal_master t where t.emp_id='" + Createleave.Empid + "'";
                            cmd2.CommandType = CommandType.Text;
                            cmd2.Connection = connection;
                            using (OracleDataReader rdr1 = cmd2.ExecuteReader())
                            {
                                rdr1.Read();
                                empid = rdr1.GetString(0);
                                empname = rdr1.GetString(1);
                                bagian = rdr1.GetString(2);
                                namabagian = rdr1.GetString(3);
                            }
                            OracleCommand cmd3 = new OracleCommand();
                            cmd3.CommandText = "select KLAT.app1_id app_id,CEMT.EMP_NAME,cemt.email,KLAT.app1_as app_as from person.KMIHRMS_LEAVE_APP_TAB KLAT " +
                                "INNER JOIN PERSON.CTM_EMPLOYEE_MASTER_TAB CEMT ON CEMT.EMP_ID=KLAT.APP1_ID " +
                                "where requsioner_id='" + bagian + "' and app_type='HR'";
                            cmd3.CommandType = CommandType.Text;
                            cmd3.Connection = connection;
                            using (OracleDataReader rdr2 = cmd3.ExecuteReader())
                            {
                                rdr2.Read();
                                namaapproved = rdr2.GetString(1);
                                emailapproved = rdr2.GetString(2);
                            }
                            sendmail(namaapproved, emailapproved, empid, empname, bagian, namabagian, DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null), DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null), Createleave.reasonpost1, Createleave.SelectedItem, Createleave.Alamat, Createleave.hpl, Createleave.tglkej, Createleave.times);
                            connection.Close();
                        }
                        else if (Createleave.SelectedItem == "CM")
                        {
                            OracleCommand cmd1 = new OracleCommand();
                            cmd1.CommandText = "INSERT INTO KMIHRMS_DETAIL_LEAVE (EMPID,LEAVE_TYPE,FROMLEAVE,TOLEAVE,REASON,ADDRESS,STATUS,DAYS,REALDATE) VALUES ('" + Createleave.Empid + "','" + Createleave.SelectedItem + "',to_date('" + Createleave.fromleave + "','DD/MM/YYYY'),to_date('" + Createleave.toleave + "','DD/MM/YYYY'),'Melahirkan','" + Createleave.Alamat + "','Release','" + Createleave.hari + "',to_date('" + Createleave.hpl + "','DD/MM/YYYY'))";
                            cmd1.CommandType = CommandType.Text;
                            cmd1.Connection = connection;
                            connection.Open();
                            cmd1.ExecuteNonQuery();
                            OracleCommand cmd2 = new OracleCommand();
                            cmd2.CommandText = "select t.EMP_ID,t.EMP_NAME,T.COST_CENTER,t.CC_DESC from person.personal_master t where t.emp_id='" + Createleave.Empid + "'";
                            cmd2.CommandType = CommandType.Text;
                            cmd2.Connection = connection;
                            using (OracleDataReader rdr1 = cmd2.ExecuteReader())
                            {
                                rdr1.Read();
                                empid = rdr1.GetString(0);
                                empname = rdr1.GetString(1);
                                bagian = rdr1.GetString(2);
                                namabagian = rdr1.GetString(3);
                            }
                            OracleCommand cmd3 = new OracleCommand();
                            cmd3.CommandText = "select KLAT.app1_id app_id,CEMT.EMP_NAME,cemt.email,KLAT.app1_as app_as from person.KMIHRMS_LEAVE_APP_TAB KLAT " +
                                "INNER JOIN PERSON.CTM_EMPLOYEE_MASTER_TAB CEMT ON CEMT.EMP_ID=KLAT.APP1_ID " +
                                "where requsioner_id='" + bagian + "' and app_type='HR'";
                            cmd3.CommandType = CommandType.Text;
                            cmd3.Connection = connection;
                            using (OracleDataReader rdr2 = cmd3.ExecuteReader())
                            {
                                rdr2.Read();
                                namaapproved = rdr2.GetString(1);
                                emailapproved = rdr2.GetString(2);
                            }
                            sendmail(namaapproved, emailapproved, empid, empname, bagian, namabagian, DateTime.ParseExact(Createleave.fromleave, "dd/MM/yyyy", null), DateTime.ParseExact(Createleave.toleave, "dd/MM/yyyy", null), "Melahirkan", Createleave.SelectedItem, Createleave.Alamat, Createleave.hpl, Createleave.tglkej, Createleave.times);
                            connection.Close();
                        }
                        return RedirectToAction("Index");
                    }

                }
                else
                {
                    return Content("<script language='javascript' type='text/javascript'>alert('Your Request Already Exist!');location.href = 'Index'; ;</script>", "WARNING");

                }
            }
            return View(Createleave);
        }
 public ViewResult Index(LeaveRequest model)
 {
     return View(model);
 }
 public ActionResult Create()
 {
     LeaveRequest model = new LeaveRequest();
     return View(model);
 }