private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                CatagorySetup insGetSet = new CatagorySetup();
                insGetSet.Name = nameTextBox.Text;


                CatagorySetupManager catagorymanager = new CatagorySetupManager();
                bool chk = catagorymanager.Insert(insGetSet);

                if (chk)
                {
                    MessageBox.Show("Data Saved", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Try Again");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            nameTextBox.Text = "";
            loadData();
        }
        private void categorySetupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            CatagorySetup catagory = new CatagorySetup();

            catagory.Show();
        }
        private void nameTextBox_TextChanged(object sender, EventArgs e)
        {
            CatagorySetup exist = new CatagorySetup();

            exist.Name = nameTextBox.Text;

            CatagorySetupRepository cs = new CatagorySetupRepository();

            cs.AlredyExist(exist);
        }
        public bool Insert(CatagorySetup ca)
        {
            string     query = @"INSERT CategorySetup (name) Values (@name)";
            SqlCommand cmd   = new SqlCommand(query, con);

            cmd.Parameters.AddWithValue("@name", ca.Name);
            con.Open();
            int rowAffect = cmd.ExecuteNonQuery();

            con.Close();
            if (rowAffect > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void AlredyExist(CatagorySetup cs)
        {
            try
            {
                SqlConnection con   = new SqlConnection(connection);
                string        query = @"SELECT * FROM CategorySetup WHERE EXISTS (SELECT * FROM CategorySetup WHERE name=@name)";
                SqlCommand    cmd   = new SqlCommand(query, con);
                cmd.Parameters.AddWithValue("@name", cs.Name);
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                if (reader.HasRows)
                {
                    MessageBox.Show("This Name Already Added", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void setupCategoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CatagorySetup catagory = new CatagorySetup();

            catagory.Show();
        }
Exemplo n.º 7
0
        CatagorySetupRepository DalFolder = new CatagorySetupRepository(); // Create a new Instance or Object store data in DalFolder variable for passing value
        public bool Insert(CatagorySetup ca)                               // Calling Insert Method from DAL with passing parameters
        {
            bool chk = DalFolder.Insert(ca);

            return(chk);
        }