Exemplo n.º 1
0
        public void m_lngSave()
        {
            if (m_objViewer.m_txtID.Text.Trim() == "")
            {
                m_ephHandler.m_mthAddControl(m_objViewer.m_txtID);
                m_ephHandler.m_mthShowControlsErrorProvider();
                m_ephHandler.m_mthClearControl();
                m_objViewer.m_txtID.Focus();
                return;
            }

            if (m_objViewer.m_txtName.Text.Trim() == "")
            {
                m_ephHandler.m_mthAddControl(m_objViewer.m_txtName);
                m_ephHandler.m_mthShowControlsErrorProvider();
                m_ephHandler.m_mthClearControl();
                m_objViewer.m_txtName.Focus();
                return;
            }

            long lngRes = 0;
            clsCharegeItemCat_VO objResult = new clsCharegeItemCat_VO();

            objResult.m_strItemCatID   = this.m_objViewer.m_txtID.Text.Trim();
            objResult.m_strItemCatName = this.m_objViewer.m_txtName.Text.Trim();


            if (m_objViewer.m_txtName.Tag == null)          //新增
            {
                for (int i = 0; i < m_objViewer.m_lvw.Items.Count; i++)
                {
                    if (m_objViewer.m_lvw.Items[i].SubItems[1].Text.Trim() == m_objViewer.m_txtID.Text.Trim())
                    {
                        MessageBox.Show("ID已经存在,请选择另一个ID!", "提示");
                        m_ephHandler.m_mthAddControl(m_objViewer.m_txtID);
                        m_ephHandler.m_mthShowControlsErrorProvider();
                        m_ephHandler.m_mthClearControl();
                        m_objViewer.m_txtID.Focus();
                        m_objViewer.m_txtID.SelectAll();

                        return;
                    }

                    if (m_objViewer.m_lvw.Items[i].SubItems[2].Text.Trim() == m_objViewer.m_txtName.Text.Trim())
                    {
                        MessageBox.Show("分类名称已经存在,请选择另一个名称!", "提示");
                        m_ephHandler.m_mthAddControl(m_objViewer.m_txtName);
                        m_ephHandler.m_mthShowControlsErrorProvider();
                        m_ephHandler.m_mthClearControl();
                        m_objViewer.m_txtName.Focus();
                        m_objViewer.m_txtName.SelectAll();

                        return;
                    }
                }
                lngRes = clsDomain.m_lngAddCat(objResult);
                int index = m_objViewer.m_lvw.Items.Count;
                if (lngRes > 0)
                {
                    ListViewItem lvw = new ListViewItem();
                    lvw.SubItems.Add(objResult.m_strItemCatID);
                    lvw.SubItems.Add(objResult.m_strItemCatName);
                    lvw.Tag = objResult.m_strItemCatID;
                    m_objViewer.m_lvw.Items.Add(lvw);
                    m_objViewer.m_lvw.Items[index].Selected = true;
                }
                else
                {
                    MessageBox.Show("保存失败!", "提示");
                }
            }
            else
            {
                if (m_objViewer.m_lvw.SelectedItems.Count <= 0)
                {
                    return;
                }
                for (int i = 0; i < m_objViewer.m_lvw.Items.Count; i++)
                {
                    if (i == m_objViewer.m_lvw.SelectedItems[0].Index)
                    {
                        continue;
                    }
                    if (m_objViewer.m_lvw.Items[i].SubItems[1].Text.Trim() == m_objViewer.m_txtID.Text.Trim())
                    {
                        MessageBox.Show("ID已经存在,请选择另一个ID!", "提示");
                        m_ephHandler.m_mthAddControl(m_objViewer.m_txtID);
                        m_ephHandler.m_mthShowControlsErrorProvider();
                        m_ephHandler.m_mthClearControl();

                        m_objViewer.m_txtID.Focus();
                        m_objViewer.m_txtID.SelectAll();

                        return;
                    }
                    if (m_objViewer.m_lvw.Items[i].SubItems[2].Text.Trim() == m_objViewer.m_txtName.Text.Trim())
                    {
                        MessageBox.Show("分类名称已经存在,请选择另一个名称!", "提示");
                        m_ephHandler.m_mthAddControl(m_objViewer.m_txtName);
                        m_ephHandler.m_mthShowControlsErrorProvider();
                        m_ephHandler.m_mthClearControl();

                        m_objViewer.m_txtName.Focus();
                        m_objViewer.m_txtName.SelectAll();

                        return;
                    }
                }

                lngRes = clsDomain.m_lngDoUpdCatByID(objResult, this.m_objViewer.m_txtName.Tag.ToString());
                if (lngRes > 0)
                {
                    MessageBox.Show("修改成功!", "提示");
                    m_objViewer.m_lvw.SelectedItems[0].SubItems[1].Text = objResult.m_strItemCatID;
                    m_objViewer.m_lvw.SelectedItems[0].SubItems[2].Text = objResult.m_strItemCatName;
                    m_objViewer.m_lvw.SelectedItems[0].Tag = objResult.m_strItemCatID;
                }
                else
                {
                    MessageBox.Show("修改失败!", "提示");
                }
            }
            m_objViewer.m_txtID.Text   = "";
            m_objViewer.m_txtName.Text = "";

            m_objViewer.m_txtName.Tag = null;
            m_objViewer.m_txtID.Focus();
        }