Beispiel #1
0
        private void btn_Click(object sender, ItemClickEventArgs e)
        {
            try
            {
                TreeListNode nodeSel = TreeListMain.FocusedNode;

                DataRow dr = null;
                if (nodeSel != null)
                {
                    var dataRowView = TreeListMain.GetDataRecordByNode(TreeListMain.FocusedNode) as DataRowView;
                    if (dataRowView != null)
                    {
                        dr = dataRowView.Row;
                    }
                }
                Cursor = Cursors.WaitCursor;
                DtTreeList.Columns["Organize_Id"].ReadOnly = false;
                switch (e.Item.Name)
                {
                case "btnAddSameLevel":
                    SetMode("Add");
                    string  strCtrlAddSameLevel = CtrlNextArray[0];
                    Control ctrlAddSameLevel    = layoutControl1.Controls.Find(strCtrlAddSameLevel, true)[0];
                    DoFocus(ctrlAddSameLevel);
                    DataRow drNew = DtTreeList.NewRow();
                    drNew["Organize_Id"] = -1;
                    if (dr == null)
                    {
                        drNew["Layer"]    = 1;
                        drNew["ParentId"] = 0;
                    }
                    else
                    {
                        drNew["Layer"]    = dr["Layer"];
                        drNew["ParentId"] = dr["ParentId"];
                    }

                    blInitBound = true;
                    TreeListNode nodeA;
                    if (dr == null)
                    {
                        nodeA = TreeListMain.AppendNode(drNew, 0);
                    }
                    else
                    {
                        nodeA = TreeListMain.AppendNode(drNew, nodeSel.ParentNode);
                    }
                    TreeListMain.SetFocusedNode(nodeA);
                    blInitBound = false;
                    TreeListMain_FocusedNodeChanged(TreeListMain, new DevExpress.XtraTreeList.FocusedNodeChangedEventArgs(null, TreeListMain.FocusedNode));
                    txtCreateTime.Text   = DateTime.Now.ToString();
                    txtCreateUserId.Text = UserInfoHelper.CreateName;
                    break;

                case "btnAddNextLevel":
                    if (dr == null)
                    {
                        return;
                    }
                    SetMode("Add");
                    string  strCtrlAddNextLevel = CtrlNextArray[0];
                    Control ctrlAddNextLevel    = layoutControl1.Controls.Find(strCtrlAddNextLevel, true)[0];
                    DoFocus(ctrlAddNextLevel);
                    DataRow drNewS = DtTreeList.NewRow();
                    drNewS["Organize_Id"] = -1;
                    drNewS["Layer"]       = int.Parse(dr["Layer"].ToString()) + 1;
                    drNewS["ParentId"]    = dr["Organize_Id"];

                    blInitBound = true;
                    TreeListNode nodeAs = TreeListMain.AppendNode(drNewS, nodeSel);
                    nodeSel.ExpandAll();
                    TreeListMain.SetFocusedNode(nodeAs);
                    blInitBound = false;
                    TreeListMain_FocusedNodeChanged(TreeListMain, new DevExpress.XtraTreeList.FocusedNodeChangedEventArgs(null, TreeListMain.FocusedNode));
                    txtCreateTime.Text   = DateTime.Now.ToString();
                    txtCreateUserId.Text = UserInfoHelper.CreateName;
                    break;

                case "btnEdit":
                    if (dr == null)
                    {
                        return;
                    }
                    Mode = "Edit";
                    SetMode("Edit");
                    string  StrCtrlEdit = CtrlNextArray[0];
                    Control CtrlEdit    = layoutControl1.Controls.Find(StrCtrlEdit, true)[0];
                    DoFocus(CtrlEdit);
                    break;

                case "btnCancel":
                    if (dr == null)
                    {
                        return;
                    }
                    blInitBound = true;
                    DtTreeList.RejectChanges();    //引发gridView1_FocusedRowChanged
                    DtTreeList.AcceptChanges();
                    blInitBound = false;
                    SetMode("View");
                    TreeListMain_FocusedNodeChanged(TreeListMain, new DevExpress.XtraTreeList.FocusedNodeChangedEventArgs(null, TreeListMain.FocusedNode));
                    break;

                case "btnSave":
                    if (dr == null)
                    {
                        return;
                    }
                    DoSave();
                    break;

                case "btnDelete":
                    if (dr == null)
                    {
                        return;
                    }
                    List <Bse_Organize> roleModel = ModelHandler <Bse_Organize> .FillModel(organizeDal.GetList("Organize_Id=" + _organizeId + "").Tables[0]);

                    Bse_Organize model = roleModel[0];
                    model.State = 0;
                    bool flag = organizeDal.Update(roleModel[0]);
                    if (flag)
                    {
                        MessageBox.Show(@"作废成功");
                        TreeListMain.DeleteSelectedNodes();
                    }
                    else
                    {
                        MessageBox.Show(@"作废失败");
                    }
                    SetMode("View");
                    break;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(@"错误:" + err.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Beispiel #2
0
        private void DoSave()
        {
            var dataRowView = TreeListMain.GetDataRecordByNode(TreeListMain.FocusedNode) as DataRowView;

            if (dataRowView != null)
            {
                DataRow dr = dataRowView.Row;
                if (dr == null)
                {
                    return;
                }

                if (CheckSave(this.layoutControl1, CtrlSaveArray, CtrlSaveArrayTxt) == false)
                {
                    return;
                }

                btnSave.Enabled = false;
                bool blChgState = false;

                try
                {
                    if (dr["Organize_Id"].ToString() == string.Empty || _organizeId == "-1")
                    {
                        if (organizeDal.GetList("  Number='" + txtNumber.Text + "'  and SystemId=" + _systemId + " ").Tables[0].Rows.Count > 0)
                        {
                            MessageBox.Show(@"输入的编码已经存在");
                            btnSave.Enabled = true;
                            return;
                        }
                        Bse_Organize organize = new Bse_Organize();
                        organize.Name         = txtName.Text.Trim();
                        organize.Number       = txtNumber.Text.Trim();
                        organize.Sort         = int.Parse(txtSort.Text.Trim());
                        organize.Category     = lueCategory.EditValue.ToString();
                        organize.OuterPhone   = txtOuterPhone.Text.Trim();
                        organize.InnerPhone   = txtInnerPhone.Text.Trim();
                        organize.Address      = txtAddress.Text.Trim();
                        organize.Remark       = txtRemark.Text.Trim();
                        organize.CreateName   = txtCreateUserId.Text.Trim();
                        organize.CreateUserId = int.Parse(UserInfoHelper.CreateUserId);
                        organize.Dept_Id      = int.Parse(UserInfoHelper.Dept_Id);
                        organize.SystemId     = int.Parse(UserInfoHelper.SystemId);
                        organize.Bloc_Id      = int.Parse(UserInfoHelper.Bloc_Id);
                        organize.Company_Id   = int.Parse(UserInfoHelper.Company_Id);
                        organize.Layer        = int.Parse(dr["Layer"].ToString());
                        organize.ParentId     = int.Parse(dr["ParentId"].ToString());
                        organize.State        = 1;
                        int flag = organizeDal.Add(organize);
                        if (flag > 0)
                        {
                            MessageDxUtilHelper.ShowWarning("操作成功");
                            //DataRow drNew = ds.Tables[0].Rows[0];
                            dr["Organize_Id"] = flag;
                        }
                        btnSave.Enabled = true;
                    }
                    else
                    {
                        if (organizeDal.GetList("Organize_Id!=" + _organizeId + " and Number='" + txtNumber.Text + "' ").Tables[0].Rows.Count > 0)
                        {
                            MessageBox.Show(@"输入的编码已经存在");
                            btnSave.Enabled = true;
                            return;
                        }

                        List <Bse_Organize> roleModel = ModelHandler <Bse_Organize> .FillModel(organizeDal.GetList("Organize_Id=" + _organizeId + "").Tables[0]);

                        Bse_Organize organize = roleModel[0];
                        organize.Organize_Id  = int.Parse(_organizeId);
                        organize.Name         = txtName.Text.Trim();
                        organize.Number       = txtNumber.Text.Trim();
                        organize.Sort         = int.Parse(txtSort.Text.Trim());
                        organize.Category     = lueCategory.EditValue.ToString();
                        organize.OuterPhone   = txtOuterPhone.Text.Trim();
                        organize.InnerPhone   = txtInnerPhone.Text.Trim();
                        organize.Address      = txtAddress.Text.Trim();
                        organize.Remark       = txtRemark.Text.Trim();
                        organize.CreateName   = txtCreateUserId.Text.Trim();
                        organize.CreateUserId = int.Parse(UserInfoHelper.CreateUserId);
                        organize.Dept_Id      = int.Parse(UserInfoHelper.Dept_Id);
                        organize.SystemId     = int.Parse(UserInfoHelper.SystemId);
                        organize.Bloc_Id      = int.Parse(UserInfoHelper.Bloc_Id);
                        organize.Company_Id   = int.Parse(UserInfoHelper.Company_Id);
                        organize.Layer        = int.Parse(dr["Layer"].ToString());
                        organize.ParentId     = int.Parse(dr["ParentId"].ToString());
                        bool flag = organizeDal.Update(organize);
                        EntityCovert.SetDataRowByEntity <Bse_Organize>(dr, organize);
                        //dr["Number"] = organize.Number;
                        if (flag)
                        {
                            MessageDxUtilHelper.ShowWarning("操作成功");
                            if (dr.Table.Columns.Contains("State") && dr["State"].ToString() != dr["State", DataRowVersion.Original].ToString())
                            {
                                blChgState = true;
                            }
                        }
                        btnSave.Enabled = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                dr.AcceptChanges();
                SetMode("VIEW");
                if (blChgState)
                {
                    SetFocRowstyleFormat(dr);
                }
            }
        }