예제 #1
0
 public int UpdateGroup(tblGroup group)
 {
     var objOrginGroup = _db.tblGroups.Where(g => g.GroupID.Equals(group.GroupID)).FirstOrDefault();
     _db.Attach(objOrginGroup);
     _db.ApplyPropertyChanges("tblGroups", group);
     return _db.SaveChanges();
 }
예제 #2
0
 public void SaveGroup(tblGroup group)
 {
     _db.Connection.Open();
     _db.AddTotblGroups(group);
     _db.SaveChanges();
     _db.Connection.Close();
 }
예제 #3
0
 public static int Insert(tblGroup group)
 {
     var db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
     group.CreatedDate = CommonFactory.GetCurrentDate();
     group.ModifiedDate = CommonFactory.GetCurrentDate();
     db.AddTotblGroups(group);
     int re = db.SaveChanges();
     db.Connection.Close();
     return re;
 }
예제 #4
0
 public int  UpdateGroup(tblGroup group)
 {
     _db.Connection.Open();
     var objOrginGroup = _db.tblGroups.Where(g => g.GroupID.Equals(group.GroupID)).FirstOrDefault();
     _db.Attach(objOrginGroup);
     _db.ApplyPropertyChanges("tblGroups", group);
     int re = _db.SaveChanges();
     _db.Connection.Close();
     return re;
 }
예제 #5
0
 public frmAddGroup(Mode mode, int groupID,  UserInfo userInfo)
 {
     InitializeComponent();
     _tabAddGroup = tabControlGroup.TabPages[0];
     _tabUser = tabControlGroup.TabPages[1];
     _tabRight = tabControlGroup.TabPages[2];
     _userInfo = userInfo;
     _group = GroupFactory.getGroupByID(groupID);
     _groupID = groupID;
     _mode = mode;
 }
예제 #6
0
 public static int Update(tblGroup group)
 {          
   var db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
   var groupOrgin = db.tblGroups.Where(g => g.GroupID == group.GroupID).FirstOrDefault();
   if (groupOrgin == null) return -1;
   db.Attach(groupOrgin);
   db.ApplyPropertyChanges("tblGroups", group);
   int re = db.SaveChanges();
   db.Connection.Close();
   return re;
 }
예제 #7
0
 public void SaveGroup(tblGroup group)
 {
     _db.AddTotblGroups(group);
     _db.SaveChanges();
 }
예제 #8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                // Validate
                if (!Validate()) return;

                if (_mode.Equals(Mode.Create)) // New mode
                {
                    // Only insert the new group if the group name is not exsiting
                    if(!GroupFactory.IsExistingName(txtName.Text.Trim()))
                    {
                        var group = new tblGroup();
                        group.GroupName = txtName.Text.Trim();
                        group.CreatedBy = _userInfo.UserID;
                        group.ModifedBy = _userInfo.UserID;
                        var result = GroupFactory.Insert(group);
                        if(result < 1)
                        {
                            MessageBox.Show(ConstantInfo.MESSAGE_INSERT_FAIL);
                            return;
                        }

                        //getGroup after save
                        tblGroup groupResuilt = new tblGroup();
                        groupResuilt = GroupFactory.getGroupByName(txtName.Text.Trim());
                        _groupID = groupResuilt.GroupID;

                        // Bind the lastest to the parrent
                        Form[] listForm = this.Owner.OwnedForms;
                        foreach (Form form in listForm)
                        {
                          if (form.Name == "FrmListGroup")
                          {
                            ((FrmListGroup) form).InitData();
                          }
                        }
                        MessageBox.Show(ConstantInfo.MESSAGE_INSERT_SUCESSFULLY);
                        //this.Close();
                        btnSave.Enabled = false;
                        tabControlGroup.TabPages.Add(_tabUser);
                        tabControlGroup.TabPages.Add(_tabRight);
                        //EnableTab(tabControlGroup.TabPages[0],false);

                    } else
                    {
                        MessageBox.Show(ConstantInfo.MESSAGE_GROUP_NAME_EXISTING);
                    }
                }
                else // Edit mode
                {
                  // Update Group
                  tblGroup group = GroupFactory.getGroupByID(_groupID);
                  if (group == null)
                  {
                    MessageBox.Show(ConstantInfo.MESSAGE_GROUP_NOT_EXIST);
                    return;
                  }

                  tblGroup groupCheck = GroupFactory.getGroupByName(txtName.Text.Trim());
                  if (groupCheck != null && (groupCheck.GroupID != _groupID && groupCheck.GroupName == txtName.Text.Trim()))
                  {
                    MessageBox.Show(ConstantInfo.MESSAGE_GROUP_NAME_EXISTING);
                    return;
                  }

                  //update group
                  group.GroupName = txtName.Text.Trim();
                  GroupFactory.Update(group);
                  // Bind the lastest to the parrent
                  Form[] listForm = this.Owner.OwnedForms;
                  foreach (Form form in listForm)
                  {
                    if (form.Name == "FrmListGroup")
                    {
                      ((FrmListGroup)form).InitData();
                    }
                  }
                  MessageBox.Show(ConstantInfo.MESSAGE_UPDATE_SUCESSFULLY);

                }

            } catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString());
            }
        }