コード例 #1
0
        public bool Update(MODEL.FlavourModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var editModel = _context.Flavours.FirstOrDefault(a => a.FlavourId == model.FlavourId);

                    if (editModel != null)
                    {
                        editModel.FlavourName = model.FlavourName;
                        editModel.Description = model.Description;
                    }

                    _context.Entry(editModel).State = EntityState.Modified;
                    _context.SaveChanges();

                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
コード例 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtFlavourName.Text))
            {
                ClsCommon.ShowErrorToolTip(txtFlavourName,"Please Enter The Flavour Name");
            }
            else
            {
                var model = new FlavourModel
                {
                    FlavourId = _flavourId,
                    FlavourName = txtFlavourName.Text,
                    Description = txtRemarks.Text
                };

                if (_isNewMode)
                {

                    _flavourId = _flavourService.Save(model);
                    if (_flavourId<=0) return;
                    MessageBox.Show(@"Data Saved Successfully", @"Save", MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                    var frm = (FrmFlavour)_frmForm;
                    frm.grdData.Rows.Add(_flavourId, model.FlavourName, model.Description);
                    frm.grdData.Rows[frm.grdData.Rows.Count - 1].IsSelected = true;
                    txtFlavourName.Focus();
                    txtFlavourName.Text = "";
                    txtRemarks.Text = "";
                    notify();
                }
                else
                {
                    var success = _flavourService.Update(model);
                    if (!success) return;
                    MessageBox.Show(@"Data Updated Successfully", @"Update", MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                    var frm = (FrmFlavour)_frmForm;
                    frm.grdData.CurrentRow.Cells["FlavourName"].Value = model.FlavourName;
                    frm.grdData.CurrentRow.Cells["Description"].Value = model.Description;
                    notify();
                    Close();
                }

            }
        }
コード例 #3
0
 public FrmFlavourEntry(FlavourModel model, Form frmForm)
 {
     InitializeComponent();
     _frmForm = frmForm;
     _flavourService = new FlavourService();
     if (model != null)
     {
         _isNewMode = false;
         _flavourId = model.FlavourId;
         txtFlavourName.Text = model.FlavourName;
         txtRemarks.Text = model.Description;
         btnAdd.Text = @"Update";
     }
     else
     {
         _isNewMode = true;
         btnAdd.Text = @"Save";
     }
 }
コード例 #4
0
        public int Save(MODEL.FlavourModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var addModel = new Flavour()
                    {
                        FlavourName = model.FlavourName,
                        Description = model.Description
                    };
                    _context.Entry(addModel).State = EntityState.Added;
                    _context.SaveChanges();

                    return(addModel.FlavourId);
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                return(0);
            }
        }
コード例 #5
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(lblID.Text) <= 0) return;
            var model = new FlavourModel()
            {
                FlavourId = Convert.ToInt32(lblID.Text),
                FlavourName = lblName.Text,
                Description = lblRemarks.Text
            };

            var frm = new FrmFlavourEntry(model, this);
            frm.ShowDialog(this);
        }