关闭

增加 修改,装载状态(父品类)

标签: 绑定数据
112人阅读 评论(0) 收藏 举报
分类:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DrugSaleSystem.DAL;
using DrugSaleSystem.Model;
using DrugSaleSystem.Components.Control;
using DrugSaleSystem.Components;

namespace DrugSaleSystem.ManagementCenter
{
    public partial class frmDrugCategoryEdit : frmBaseForm
    {
        #region 私有参数
        private List<GroupPermissionsInfo> gpInfos;
        #endregion
        #region 公共参数
        public int iDrugCategoryCode = 0;
        #endregion
        private static frmDrugCategoryEdit _Instance = null;


        public frmDrugCategoryEdit()
        {
            InitializeComponent();
            _Instance = this;
        }

        public static frmDrugCategoryEdit Instance
        {
            get
            {
                //第一次使用,如果没有实例,创建一个 
                if (_Instance == null)
                {
                    _Instance = new frmDrugCategoryEdit();
                }
                return _Instance;
            }
        }
        /// <summary>
        /// 初始化

        /// </summary>
        public void InitData()
        {
            frmMain.Instance.StyleType = ConstInfo.const_Stype;
            ParentDrugCategoryInit();
            DrugCategoryInit();

        }
        private void ControlClesrInit()
        {
            txbDrugCategoryCode.Text = "";
            cbParentDrugCategory.Text = ""; 
            txbCategoryName.Text = "";
            txbDescription.Text = "";
            txbOperator.Text = "";
            txbDrugCategoryCode.Enabled = true;
            
        }
        /// <summary>
        /// 装载父类别名称
        /// </summary>
        private void ParentDrugCategoryInit()
        {
            cbParentDrugCategory.Items.Clear();
            List<DrugCategoryInfo> _DrugCategoryInfos = DrugCategory.Get(0, 0, "", 100, 1).DrugCategoryInfo;
            ComboBoxItem pItem = new ComboBoxItem();
            pItem.Text = "请选择父类别";
            pItem.Value = "";
            cbParentDrugCategory.Items.Add(pItem);
            ComboBoxItem TopItem = new ComboBoxItem();
            TopItem.Text = "顶级类别";
            TopItem.Value = "0";
            cbParentDrugCategory.Items.Add(TopItem);
            foreach (DrugCategoryInfo info in _DrugCategoryInfos)
            {
                ComboBoxItem Item = new ComboBoxItem();
                Item.Text = info.CategoryName;
                Item.Value = info.DrugCategoryCode;
                cbParentDrugCategory.Items.Add(Item);
                List<DrugCategoryInfo> _ChildDrugCategoryInfos = DrugCategory.Get(0, info.DrugCategoryCode, "", 100, 1).DrugCategoryInfo;
                foreach (DrugCategoryInfo cinfo in _ChildDrugCategoryInfos)
                {
                    ComboBoxItem cItem = new ComboBoxItem();
                    cItem.Text = string.Format("┗{0}", cinfo.CategoryName);
                    cItem.Value = cinfo.DrugCategoryCode;
                    cbParentDrugCategory.Items.Add(cItem); 
                }
            }
            cbParentDrugCategory.SelectedIndex = 0;
        }

        private void DrugCategoryInit()
        {

            if (iDrugCategoryCode > 0)
            {
                DrugCategoryInfo info = DrugCategory.GetByDrugCategoryCode(iDrugCategoryCode);
                this.lbTitle.Text = string.Format("编辑品类[{0}]", info.CategoryName);
                txbDrugCategoryCode.Text = info.DrugCategoryCode.ToString();
                //cbParentDrugCategory.Text = info.ParentDrugCategory.ToString();
                txbCategoryName.Text = info.CategoryName;
                txbDescription.Text = info.Description;
                for (int i = 0; i < cbParentDrugCategory.Items.Count; i++)
                {
                    if (((ComboBoxItem)cbParentDrugCategory.Items[i]).Value.ToString() == info.ParentDrugCategory.ToString())
                    {
                        cbParentDrugCategory.SelectedIndex = i;
                        break;
                    }
                }
                txbOperator.Text = info.Operator;
                txbDrugCategoryCode.Enabled = false;
            }
            else
            {
                this.lbTitle.Text = "新增品类";
                ControlClesrInit();

            }
        }
        ///// <summary>
        ///// 装载

        ///// </summary>
        //private void DrugCategoryStatusInit()
        //{
        //    cbParentDrugCategory.Items.Clear();
        //    DrugSaleSystem.Components.Control.ComboBoxItem pitem = new DrugSaleSystem.Components.Control.ComboBoxItem();
        //    pitem.Text = "请选择状态";
        //    pitem.Value = "-1";
        //    cbParentDrugCategory.Items.Add(pitem);
        //    Dictionary<string, string> list = CommStatusAttributeType.LoadCommStatusAttribute();
        //    foreach (var pair in list)
        //    {
        //        DrugSaleSystem.Components.Control.ComboBoxItem item = new DrugSaleSystem.Components.Control.ComboBoxItem();
        //        item.Text = pair.Value;
        //        item.Value = pair.Key;
        //        cbParentDrugCategory.Items.Add(item);
        //    }
        //    cbParentDrugCategory.SelectedIndex = 0;
        //}
        /// <summary>
        /// 关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region 验证
            if (string.IsNullOrEmpty(txbCategoryName.Text))
            {
                MessageBox.Show("请输入品类名称!");
                return;
            }
            #endregion
            DrugCategoryInfo editinfo = new DrugCategoryInfo();
            if (iDrugCategoryCode > 0)
            {
                #region 修改
                
                editinfo = DrugCategory.GetByDrugCategoryCode(iDrugCategoryCode);
                editinfo.DrugCategoryCode = Convert.ToInt32(txbDrugCategoryCode.Text);
                editinfo.ParentDrugCategory = int.Parse(((ComboBoxItem)cbParentDrugCategory.SelectedItem).Value.ToString());
                editinfo.CategoryName = txbCategoryName.Text;
                editinfo.Operator = txbOperator.Text;
                editinfo.Description = txbDescription.Text;
                if (DrugCategory.Update(editinfo) > 0)
                {
                    #region 记录日志
                    OperationLogInfo loginfo = new OperationLogInfo();
                    loginfo.OperatorNO = ConstInfo.const_UserCode.ToString();
                    loginfo.OperatorName = ConstInfo.const_UserTrueName;
                    loginfo.Body = string.Format("修改品类成功!类别编码:{0}", editinfo.DrugCategoryCode);
                    loginfo.OperResult = "成功";
                    loginfo.Source = Clients.GetLocalIP();
                    loginfo.OperateDate = DateTime.Now;
                    OperationLog.Create(loginfo);
                    #endregion
                    frmDrugCategory.Instance.DrugCategoryInit();
                    MessageBox.Show("修改品类成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改品类失败!!");
                }
                #endregion
            }
            else
            {
                #region 新增
                int DrugCategoryCode = 0;
                if(string.IsNullOrEmpty(txbDrugCategoryCode.Text))
                {
                    MessageBox.Show("请输入品类编号!");
                    return;
                }
                if (!int.TryParse(txbDrugCategoryCode.Text, out DrugCategoryCode))
                {
                    MessageBox.Show("请输入品类名称!");
                    return;
                }
                editinfo.DrugCategoryCode = DrugCategoryCode;

                int ParentDrugCategory = 0;
                editinfo.ParentDrugCategory = int.Parse(((ComboBoxItem)cbParentDrugCategory.SelectedItem).Value.ToString());
                //if (cbParentDrugCategory.Text == "")
                //{
                //    ParentDrugCategory = 0;
                //}
                //else
                //{
                //    editinfo.ParentDrugCategory = Convert.ToInt32(cbParentDrugCategory.Text);
                //}
                editinfo.CategoryName = txbCategoryName.Text;
                editinfo.Description = txbDescription.Text;
                editinfo.Operator = ConstInfo.const_UserTrueName;
                editinfo.DrugCategoryID = DrugCategory.Create(editinfo);    //新增一条数据
                if (editinfo.DrugCategoryID > 0)
                {
                    #region 记录日志
                    OperationLogInfo loginfo = new OperationLogInfo();
                    loginfo.OperatorNO = ConstInfo.const_UserCode.ToString();
                    loginfo.OperatorName = ConstInfo.const_UserTrueName;
                    loginfo.Body = string.Format("添加品类成功!类别编码:{0}", editinfo.DrugCategoryCode);
                    loginfo.OperResult = "成功";
                    loginfo.Source = Clients.GetLocalIP();
                    loginfo.OperateDate = DateTime.Now;
                    OperationLog.Create(loginfo);
                    #endregion
                    frmDrugCategory.Instance.DrugCategoryInit();
                    MessageBox.Show("添加品类成功!");
                    this.Close();
                }
                else if (editinfo.DrugCategoryID == -2)
                {
                    MessageBox.Show("添加品类失败!该分类编码已存在!");
                }
                else
                {
                    MessageBox.Show("添加品类失败!!");
                }
                #endregion
            }

        }
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8253次
    • 积分:323
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条