示例#1
0
 public void updCommittee(Committee com, int cnumOld)
 {
    this.Database.ExecuteSqlCommand("EXEC uspLW1190_CRUDCommittee @action, @tkinit, @cnum, @cchair, @cnumOld",
                   new SqlParameter("@action", "U"),
                   new SqlParameter("@tkinit", com.tkinit),
                   new SqlParameter("@cnum", com.cnum),
                   new SqlParameter("@cchair", com.cchair),
                   new SqlParameter("@cnumOld", cnumOld));
 }
示例#2
0
      protected void grdCommittee_ItemCommand(object sender, GridCommandEventArgs e)
      {
         string id;

         #region Iff all fields are bound by GridBoundColumn
         /*
         if (e.Item.IsInEditMode && e.Item is GridEditableItem)
         {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            //Prepare new dictionary object
            Hashtable newValues = new Hashtable();
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

            int newNum = int.Parse(newValues["cnum"].ToString());
            string newChair = newValues["cchair"].ToString();

            switch (e.CommandName)
            {
               case RadGrid.PerformInsertCommandName:
                  RadTab tab = tabAtty.FindTabByText("Personal");
                  RadPageView pgVw = tab.PageView;

                  id = ((RadTextBox)pgVw.FindControl("txtAttyID")).Text;

                  using (var ctx = new DBContext())
                  {
                     var com = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                     ctx.Committees.Add(com);
                     ctx.SaveChanges();
                  }
                  break;
               case RadGrid.UpdateCommandName:
                  //editedItem.SavedOldValues: dictionary holds the old values
                  id = editedItem.SavedOldValues["tkinit"].ToString();
                  int oldNum = int.Parse(editedItem.SavedOldValues["cnum"].ToString());

                  var comm = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                  using (var ctx = new DBContext())
                  {
                     ////*** Notes:  You cannot update the primary key through EF. ***
                     //// A referential integrity constraint violation occurred: A primary key property that is a part of 
                     //// referential integrity constraint cannot be changed when the dependent object is Unchanged 
                     //// unless it is being set to the association's principal object. 
                     //// The principal object must be tracked and not marked for deletion.
                     //var com = ctx.Committees.Find(id, oldNum);
                     //var comMas = ctx.CommitteeMasters.Find(newNum);
                     ////com.cnum = newNum;
                     ////com.cnum = comMas.cnum;
                     //com.CommitteeMaster = comMas;
                     //com.cchair = newChair;
                     //ctx.SaveChanges();

                     ctx.updateCom(comm, oldNum);
                  }
                  break;
               //case RadGrid.DeleteCommandName:        //AllowAutomaticDeletes="true"             
               //   break;
            }
         }
         */
         #endregion

         if (e.Item.IsInEditMode && e.Item is GridEditableItem)
         {
            RadComboBox cbChair = (RadComboBox)e.Item.FindControl("rcbChairEdit");
            RadComboBox cbCode = (RadComboBox)e.Item.FindControl("rcbComCodeEdit");

            int newNum = int.Parse(cbCode.SelectedValue);
            string newChair = cbChair.SelectedValue;

            switch (e.CommandName)
            {
               case RadGrid.PerformInsertCommandName:
                  //e.Item as GridDataInsertItem
                  RadTab tab = tabAtty.FindTabByText("Personal");
                  RadPageView pgVw = tab.PageView;

                  id = ((RadTextBox)pgVw.FindControl("txtAttyID")).Text;

                  using (var ctx = new DBContext())
                  {
                     var com = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                     ctx.Committees.Add(com);
                     ctx.SaveChanges();
                  }

                  break;
               case RadGrid.UpdateCommandName:
                  GridEditableItem editedItem = e.Item as GridEditableItem;

                  //editedItem.SavedOldValues: dictionary holds the old values
                  id = editedItem.SavedOldValues["tkinit"].ToString();
                  int oldNum = int.Parse(editedItem.SavedOldValues["cnum"].ToString());

                  var comm = new Committee { tkinit = id, cnum = newNum, cchair = newChair };
                  using (var ctx = new DBContext())
                     ctx.updCommittee(comm, oldNum);
                  break;
               //case RadGrid.DeleteCommandName:        //AllowAutomaticDeletes="true"             
               //   break;
            }

         }
      }