public TypeContEdit(VisitaJayaPerkasa.Entities.TypeCont typeCont)
        {
            InitializeComponent();
            this.typeCont = typeCont;

            if (typeCont == null)
                wantToCreateVessel = true;
            else {
                wantToCreateVessel = false;
                etTypeCode.Text = typeCont.TypeCode;
                etTypeName.Text = typeCont.TypeName;
            }
        }
        public List<VisitaJayaPerkasa.Entities.TypeCont> GetTypeCont()
        {
            List<VisitaJayaPerkasa.Entities.TypeCont> listTypeCont = null;

            try
            {
                using (SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString))
                {
                    Constant.VisitaJayaPerkasaApplication.anyConnection = false;
                    con.Open();
                    Constant.VisitaJayaPerkasaApplication.anyConnection = true;

                    using (SqlCommand command = new SqlCommand(
                        "SELECT type_id, type_code, type_name FROM [Type_Cont] WHERE (deleted is null OR deleted = '0') " +
                        "ORDER BY type_code ASC, type_name ASC"
                        , con))
                    {
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            VisitaJayaPerkasa.Entities.TypeCont typeCont= new VisitaJayaPerkasa.Entities.TypeCont();
                            typeCont.ID = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString());
                            typeCont.TypeCode = reader.GetString(1);
                            typeCont.TypeName = reader.GetString(2);

                            if (listTypeCont == null)
                                listTypeCont = new List<VisitaJayaPerkasa.Entities.TypeCont>();

                            listTypeCont.Add(typeCont);
                            typeCont = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error("SqlTypeContRepository.cs - GetTypeCont() " + e.Message);
            }

            return listTypeCont;
        }
        private void radButtonElement1_Click(object sender, EventArgs e)
        {
            if (etTypeCode.Text.Trim().Length == 0)
                MessageBox.Show(this, "Please fill type code", "Information");
            else if (etTypeName.Text.Trim().Length == 0)
                MessageBox.Show(this, "Please fill type name", "Information");
            else
            {
                SqlTypeContRepository sqlTypeContRepository = new SqlTypeContRepository();

                SqlParameter[] param = SqlUtility.SetSqlParameter(new string[] { "type_code", "type_name" }, new object[] { etTypeCode.Text.Trim(), etTypeName.Text.Trim() });


                if (wantToCreateVessel)
                {
                    VisitaJayaPerkasa.Entities.TypeCont typeCont = new VisitaJayaPerkasa.Entities.TypeCont();
                    typeCont.ID = Guid.NewGuid();
                    typeCont.TypeCode = etTypeCode.Text.Trim();
                    typeCont.TypeName = etTypeName.Text.Trim();
                    typeCont.Deleted = 0;

                    if (sqlTypeContRepository.CheckTypeCont(param, Guid.Empty, true))
                    {
                        DialogResult dResult = MessageBox.Show(this, "Type cont has already deleted. Do you want to activate ?", "Confirmation", MessageBoxButtons.YesNo);
                        if (dResult == DialogResult.Yes)
                        {
                            SqlParameter[] parameters = SqlUtility.SetSqlParameter(new string[] { "type_id", "type_code", "type_name", "deleted" }
                            , new object[] { typeCont.ID, typeCont.TypeCode, typeCont.TypeName, typeCont.Deleted });

                            if (sqlTypeContRepository.ActivateTypeCont(parameters))
                            {
                                MessageBox.Show(this, "Success Activate Type Cont", "Information");
                                radButtonElement2.PerformClick();
                            }
                            else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                                MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            else
                                MessageBox.Show(this, "Cannot Activate Type Cont", "Information");

                            parameters = null;
                        }
                        return;
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    {
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (sqlTypeContRepository.CheckTypeCont(param, Guid.Empty))
                    {
                        MessageBox.Show(this, "Type cont has already exists", "Information");
                        return;
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    {
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(new string[] { "type_id", "type_code", "type_name", "deleted" }
                        , new object[] { typeCont.ID, typeCont.TypeCode, typeCont.TypeName, typeCont.Deleted });
                    if (sqlTypeContRepository.CreateTypeCont(sqlParam))
                    {
                        MessageBox.Show(this, "Success create type cont", "Information");
                        radButtonElement2.PerformClick();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                    {
                        MessageBox.Show(this, "Cannot Create type cont", "Information");
                    }
                }
                else
                {
                    typeCont.ID = this.typeCont.ID;
                    typeCont.TypeCode = etTypeCode.Text.Trim();
                    typeCont.TypeName = etTypeName.Text.Trim();
                    typeCont.Deleted = 0;

                    if (sqlTypeContRepository.CheckTypeCont(param, typeCont.ID))
                    {
                        MessageBox.Show(this, "Type cont has already exist. if it has already deleted. you must activate it with create new data", "Information");
                        return;
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                    {
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    SqlParameter[] sqlParam = SqlUtility.SetSqlParameter(new string[] { "type_id", "type_code", "type_name", "deleted" }
                    , new object[] { typeCont.ID, typeCont.TypeCode, typeCont.TypeName, typeCont.Deleted });

                    if (sqlTypeContRepository.EditTypeCont(sqlParam))
                    {
                        MessageBox.Show(this, "Success edit type cont", "Information");
                        radButtonElement2.PerformClick();
                    }
                    else if (!Constant.VisitaJayaPerkasaApplication.anyConnection)
                        MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                    {
                        MessageBox.Show(this, "Cannot edit type cont", "Information");
                    }
                }


            //    SqlParameter[] param;

            //    if (wantToCreateVessel)
            //    {
            //        //Check vessel code has already exists ?
            //        param = SqlUtility.SetSqlParameter(new string[] { "type_code" }, new object[] { etTypeCode.Text.Trim() });
            //        if (sqlTypeContRepository.CheckTypeCont(param))
            //        {
            //            MessageBox.Show(this, "Type Cont has already exists !", "Information");
            //            return;
            //        }

            //        param = null;
            //        param = SqlUtility.SetSqlParameter(new string[] { "type_id", "type_code", "type_name", "deleted" }, new object[] { Guid.NewGuid(), etTypeCode.Text.Trim(), etTypeName.Text.Trim(), 0 });

            //        if (sqlTypeContRepository.CreateTypeCont(param))
            //        {
            //            MessageBox.Show(this, "Success create type cont", "Information");
            //            radButtonElement2.PerformClick();
            //        }
            //        else
            //        {
            //            MessageBox.Show(this, "Cannot Create type cont", "Information");
            //        }
            //    }
            //    else
            //    {
            //        param = SqlUtility.SetSqlParameter(new string[] { "type_code", "type_name", "type_id" }, new object[] { etTypeCode.Text.Trim(), etTypeName.Text.Trim(), typeCont.ID });

            //        if (sqlTypeContRepository.EditTypeCont(param))
            //        {
            //            MessageBox.Show(this, "Success Edit type cont", "Information");
            //            radButtonElement2.PerformClick();
            //        }
            //        else
            //        {
            //            MessageBox.Show(this, "Cannot Edit type cont", "Information");
            //        }
            //    }

            //    param = null;
            //    sqlTypeContRepository = null;
            }
        }