Exemple #1
0
        private void btnDeleteMotorOil_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            try
            {
                using (var context = new kitchenEntities())
                {
                    int x = Convert.ToInt16(dgShow.CurrentRow.Cells[4].Value.ToString());

                    ServicesPrice del = context.ServicesPrice.Where(current => current.Id == x).FirstOrDefault();
                    context.ServicesPrice.Remove(del);
                    context.SaveChanges();
                    lblError.ForeColor = Color.Green;
                    lblError.Text      = "خدمت با موفقیت حذف شد";
                    context.Dispose();



                    Refresh_Price();
                    comGroup.Text       = "";
                    txtServiceName.Text = "";
                    txtKindKala.Text    = "";
                    txtServisPrice.Text = "";
                }
            }
            catch (Exception)
            {
                lblError.ForeColor = Color.Red;
                lblError.Text      = "عملیات حذف با مشکل مواجه شد";
            }
        }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            try
            {
                using (var context = new kitchenEntities())
                {
                    var name = context.ServicesPrice.Where(current => current.ServisKind == comGroup.Text && current.ServiceKala == txtKindKala.Text && current.ServiseName == txtServiceName.Text).ToList();
                    if (name.Count == 0)
                    {
                        ServicesPrice pri = new ServicesPrice();
                        pri.ServisKind  = comGroup.Text;
                        pri.ServiseName = txtServiceName.Text;
                        pri.ServiceKala = txtKindKala.Text;
                        //if (txtServisPrice.Text != "")
                        pri.ServicePrice = Convert.ToInt64(txtServisPrice.Text);
                        // else
                        //pri.ServicePrice1 = 0;
                        context.SaveChanges();

                        context.ServicesPrice.Add(pri);
                        context.SaveChanges();
                        lblError.ForeColor = Color.Green;
                        lblError.Text      = "اطلاعات خدمت ثبت شد";
                        Refresh_Price();
                    }
                    else
                    {
                        lblError.ForeColor = Color.Red;
                        lblError.Text      = " خدمت با این مقادیر وجود دارد";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }