关闭

绑定数据 获取值,修改,新增 。记录日志及 获取拼音码及键 回车换行

标签: 绑定数据
99人阅读 评论(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 frmPurchaseCategoryEdit : frmBaseForm
    {
        #region 私有参数
        private List<GroupPermissionsInfo> gpInfos;
        #endregion
        #region 公共参数
        public int iSortDescriptionID = 0;
        #endregion
        private static frmPurchaseCategoryEdit _Instance = null;

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

        public static frmPurchaseCategoryEdit Instance
        {
            get
            {
                //第一次使用,如果没有实例,创建一个 
                if (_Instance == null)
                {
                    _Instance = new frmPurchaseCategoryEdit();
                }
                return _Instance;
            }
        }
        /// <summary>
        /// 初始化
        /// </summary>
        public void InitData()
        {
            frmMain.Instance.StyleType = ConstInfo.const_Stype;
            //ParentDrugCategoryInit();
            PurchaseCategoryInit();

        }
        private void ControlClesrInit()
        {
            txbSortDescriptionCode.Text = "";
            txbSortName.Text = "";
            txbSpellCode.Text = "";
            txbDescription.Text = "";
            txbOperator.Text = "";
            txbSortDescriptionCode.Enabled = true;
        }
        private void PurchaseCategoryInit()
        {
            if (iSortDescriptionID > 0)
            {
                SortDescriptionInfo info = SortDescription.GetBySortDescriptionID(iSortDescriptionID);   //获取值
                this.lbTitle.Text = string.Format("编辑采购类别[{0}]", info.SortName);
                txbSortDescriptionCode.Text = info.SortDescriptionCode.ToString();
                txbSortName.Text = info.SortName;
                txbSpellCode.Text = info.SpellCode;
                txbDescription.Text = info.Description;
                txbOperator.Text = info.Operator;
                txbSortDescriptionCode.Enabled = false;
            }
            else
            {
                this.lbTitle.Text = "新增采购类别";
                ControlClesrInit();

            }
        }
        /// <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(txbSortName.Text))
            {
                MessageBox.Show("请输入类别名称!");
                return;
            }
            #endregion
            SortDescriptionInfo editinfo = new SortDescriptionInfo();
        
            if (iSortDescriptionID > 0)
            {
                #region 修改
                editinfo = SortDescription.GetBySortDescriptionID(iSortDescriptionID);               
                editinfo.SortDescriptionCode = Convert.ToInt32(txbSortDescriptionCode.Text);
                editinfo.SortName = txbSortName.Text;
                editinfo.SpellCode = txbSpellCode.Text;
                editinfo.Operator = txbOperator.Text;
                editinfo.Description = txbDescription.Text;
                if (SortDescription.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.SortDescriptionCode);
                    loginfo.OperResult = "成功";
                    loginfo.Source = Clients.GetLocalIP();
                    loginfo.OperateDate = DateTime.Now;
                    OperationLog.Create(loginfo);
                    #endregion
                    frmPurchaseCategory.Instance.PurchaseCategoryInit();
                    MessageBox.Show("修改类别成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改类别失败!!");
                }
                #endregion
            }
            else
            {
                #region 新增
                int SortDescriptionCode = 0;
                if (string.IsNullOrEmpty(txbSortDescriptionCode.Text))
                {
                    MessageBox.Show("请输入类别编码!");
                    return;
                }
                if (!int.TryParse(txbSortDescriptionCode.Text, out SortDescriptionCode))
                {
                    MessageBox.Show("输入类别编码有误!");
                    return;
                }
                editinfo.SortObject = 2;      
                editinfo.SortDescriptionCode = SortDescriptionCode;
                editinfo.SortName = txbSortName.Text;
                editinfo.SpellCode = txbSpellCode.Text;
                editinfo.Description = txbDescription.Text;
                editinfo.Operator = ConstInfo.const_UserTrueName;
                editinfo.SortDescriptionID = SortDescription.Create(editinfo);  //新增一条数据
                if (editinfo.SortDescriptionID > 0)
                {
                    #region 记录日志
                    OperationLogInfo loginfo = new OperationLogInfo();
                    loginfo.OperatorNO = ConstInfo.const_UserCode.ToString();
                    loginfo.OperatorName = ConstInfo.const_UserTrueName;
                    loginfo.Body = string.Format("添加类别成功!类别编码:{0}", editinfo.SortDescriptionCode);
                    loginfo.OperResult = "成功";
                    loginfo.Source = Clients.GetLocalIP();
                    loginfo.OperateDate = DateTime.Now;
                    OperationLog.Create(loginfo);
                    #endregion
                    frmPurchaseCategory.Instance.PurchaseCategoryInit();
                    MessageBox.Show("添加类别成功!");
                    this.Close();
                }
                else if (editinfo.SortDescriptionID == -2)
                {
                    MessageBox.Show("添加类别失败!该类别编码已存在!");
                }
                else
                {
                    MessageBox.Show("添加类别失败!!");
                }
                #endregion
            }

        }

        private void txbSortName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)    //回车换行
            {
                txbSpellCode.Text = Spell.ChineseFirstShell(txbSortName.Text);   //获取拼音码
                txbSpellCode.Focus();   
            }
        }

        private void txbSpellCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txbDescription.Focus();
            }
        }

    }
}

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8116次
    • 积分:320
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条