コード例 #1
0
        private void Insert_Click(object sender, EventArgs e)
        {
            try
            {
                DataLinqToSqlDataContext dbinstall = new DataLinqToSqlDataContext();

                PRODUCT prod = new PRODUCT();

                prod.NAME         = Name.Text;
                prod.CATEGORY     = Category.Text;
                prod.MADED_BY     = Maded_by.Text;
                prod.PRODUCT_DATE = dateTimePicker1.Value;
                prod.PRICE        = numericUpDown1.Value;

                dbinstall.PRODUCTs.InsertOnSubmit(prod);

                dbinstall.SubmitChanges();

                DataView.DataSource = dbinstall.PRODUCTs;
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                DataLinqToSqlDataContext dbdelete = new DataLinqToSqlDataContext();

                int prodID = Convert.ToInt32(DataView.CurrentRow.Cells["ID"].Value);

                PRODUCT prod = dbdelete.PRODUCTs.SingleOrDefault(o => o.ID == prodID);
                dbdelete.PRODUCTs.DeleteOnSubmit(prod);
                dbdelete.SubmitChanges();
                DataView.DataSource = dbdelete.PRODUCTs;
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong! Retry please ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #3
0
        private void Show_Click(object sender, EventArgs e)
        {
            DataLinqToSqlDataContext linq = new DataLinqToSqlDataContext();

            DataView.DataSource = linq.PRODUCTs;

            Insert.Visible          = true;
            Delete.Visible          = true;
            Update.Visible          = true;
            DataView.Visible        = true;
            Maded_by.Visible        = true;
            Name.Visible            = true;
            Category.Visible        = true;
            dateTimePicker1.Visible = true;
            numericUpDown1.Visible  = true;
            label2.Visible          = true;
            label3.Visible          = true;
            Date.Visible            = true;
            Price.Visible           = true;
            label1.Visible          = true;
        }
コード例 #4
0
        private void Update_Click(object sender, EventArgs e)
        {
            try
            {
                DataLinqToSqlDataContext dbupcon = new DataLinqToSqlDataContext();
                int prodId = Convert.ToInt32(Name.Tag);

                PRODUCT prod = dbupcon.PRODUCTs.SingleOrDefault(product => product.ID == prodId);

                prod.NAME         = Name.Text;
                prod.CATEGORY     = Category.Text;
                prod.MADED_BY     = Maded_by.Text;
                prod.PRODUCT_DATE = Convert.ToDateTime(dateTimePicker1.Text);
                prod.PRICE        = numericUpDown1.Value;

                dbupcon.SubmitChanges();

                DataView.DataSource = dbupcon.PRODUCTs;
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong :( , please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }