Beispiel #1
0
 private void toolStripButtonAdd_Click(object sender, EventArgs e)
 {
     enforceLawGridViewAreaCodes.AllowUserToAddRows = true;
     DataGridViewRow row = enforceLawGridViewAreaCodes.Rows[enforceLawGridViewAreaCodes.NewRowIndex];
     AreaCode areaCode = new AreaCode();
     areaCode.IsExists = false;
     areaCode.ParentID = 0;
     areaCode.LevelID = 0;
     areaCode.OrderID = 0;
     if (enforceLawGridViewAreaCodes.SelectedRows.Count != 0)
     {
         foreach (DataGridViewRow Prow in enforceLawGridViewAreaCodes.SelectedRows)
         {
             if (Prow.Tag == null)
                 continue;
             AreaCode aCode = Prow.Tag as AreaCode;
             areaCode.ParentID = aCode.ID;
             areaCode.LevelID = aCode.LevelID + 1;
             areaCode.LevelName = GetLevel(areaCode.LevelID);
             areaCode.OrderID = InvokeUtil.SystemService.AreaCodeMaxOrderId(areaCode.ParentID) + 1;
         }
     }
     InvokeUtil.SystemService.EntityUpdate(areaCode);
     row.Tag = areaCode;
     Reload();
     enforceLawGridViewAreaCodes.AllowUserToAddRows = false;
 }
Beispiel #2
0
        /// <summary>
        /// 栏目上移下移
        /// </summary>
        /// <param name="Id">移动栏目编号</param>
        /// <param name="IfUp">是否上移</param>
        /// <param name="Value">移动数量</param>
        internal void MoveAction(int Id, bool IfUp, int Value)
        {
            using (CreateTranscation())
            {
                if (IfUp)//上移
                {
                    for (int i = 0; i < Value; i++)
                    {
                        //AreaCode areaCode = (AreaCode)SystemService.EntityInit(new AreaCode { ID == Id });

                        SelectSqlSection section = DB.Select(DataBases.AreaCode);
                        section.Where(DataBases.AreaCode.ID == Id);
                        AreaCode areaCode = new AreaCode();
                        using (IDataReader reader = section.ToDataReader())
                        {
                            while (reader.Read())
                            {
                                areaCode = ReadRow(reader);
                                break;
                            }
                        }
                        if (areaCode == null)
                            break;

                        SelectSqlSection section1 = DB.Select(DataBases.AreaCode);
                        section1.Where(DataBases.AreaCode.ParentID == areaCode.ParentID &&
                            DataBases.AreaCode.OrderID < areaCode.OrderID);
                        section1.OrderBy(DataBases.AreaCode.OrderID.Desc);
                        AreaCode areaCode1 = new AreaCode();
                        using (IDataReader reader = section1.ToDataReader())
                        {
                            while (reader.Read())
                            {
                                areaCode1 = ReadRow(reader);
                                break;
                            }
                        }
                        if (areaCode1 == null)
                            break;

                        //AreaCode ac= DB.Select(DataBases.AreaCode).Where(DataBases.AreaCode.ParentID == areaCode.ParentID &&
                        //    DataBases.AreaCode.OrderID < areaCode.OrderID).OrderBy(DataBases.AreaCode.OrderID.Desc)
                        //    .;

                        DB.Update(DataBases.AreaCode).AddColumn(DataBases.AreaCode.OrderID, areaCode.OrderID)
                            .Where(DataBases.AreaCode.OrderID == areaCode1.ParentID &&
                            DataBases.AreaCode.ParentID == areaCode.ParentID).Execute();

                        areaCode.OrderID = areaCode1.OrderID;
                        areaCode.Update();
                    }
                }
                else//下移
                {
                    for (int i = 0; i < Value; i++)
                    {
                        SelectSqlSection section = DB.Select(DataBases.AreaCode);
                        section.Where(DataBases.AreaCode.ID == Id);
                        AreaCode areaCode = new AreaCode();
                        using (IDataReader reader = section.ToDataReader())
                        {
                            while (reader.Read())
                            {
                                areaCode = ReadRow(reader);
                                break;
                            }
                        }
                        if (areaCode == null)
                            break;
                        SelectSqlSection section1 = DB.Select(DataBases.AreaCode);
                        section1.Where(DataBases.AreaCode.ParentID == areaCode.ParentID &&
                            DataBases.AreaCode.OrderID > areaCode.OrderID);
                        section1.OrderBy(DataBases.AreaCode.OrderID.Desc);
                        AreaCode areaCode1 = new AreaCode();
                        using (IDataReader reader = section1.ToDataReader())
                        {
                            while (reader.Read())
                            {
                                areaCode1 = ReadRow(reader);
                                break;
                            }
                        }
                        if (areaCode1 == null)
                            break;
                        SelectSqlSection updtion1 = DB.Select(DataBases.AreaCode);
                        updtion1.Where(DataBases.AreaCode.OrderID == areaCode1.ParentID &&
                            DataBases.AreaCode.ParentID == areaCode.ParentID);
                        AreaCode areaCodeUp1 = new AreaCode();
                        using (IDataReader reader = updtion1.ToDataReader())
                        {
                            while (reader.Read())
                            {
                                areaCodeUp1 = ReadRow(reader);
                                break;
                            }
                        }
                        areaCodeUp1.OrderID = areaCode.OrderID;
                        areaCodeUp1.Update();

                        areaCode.OrderID = areaCode1.OrderID;
                        areaCode.Update();
                    }
                }
                SQLtransaction.Complete();
            }
        }