库图代码

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;

namespace YM
{
    public partial class FormYMSM09 : EF.EFForm
    {
        public FormYMSM09()
        {
            InitializeComponent();
        }
        bool moveFlag = false;
        private void FormYMSM09_Load(object sender, EventArgs e)
        {
            EF.Utility.SetGridColumn(new EF.EFDevGrid[] { efDevGrid1 }, new string[] { "YMSM09_INQ" }, "MA9JZ");

            EI.EIInfo inBlock = new EI.EIInfo();
            EI.EIInfo outBlock;
            DataTable tb = new DataTable();
            tb.Columns.Add("STOCK_PLACE_NO");//库位号
            tb.Columns.Add("STOCK_PLACE_DESC");//库位描述
            tb.Columns.Add("HEIGHT");//高度
            tb.Columns.Add("WIDTH");//宽度
            tb.Columns.Add("POINT_X");// 相对于父容器 X轴坐标
            tb.Columns.Add("POINT_Y");// 相对于父容器 Y轴坐标
            tb.Columns.Add("STOCK_TYPE");// 库位属性 : 1 :正常库位  2:装饰(辊道,房子之类)
            tb.Columns.Add("STOCK_COLOR");// 控件背景色 取自 Color 的枚举字符串  Color.Green 写Green 、 Color.Red  写 Red

            //调用service
            outBlock = EI.EIManager.Instance.CallService("MA9JZ", "ymsm09_inq", inBlock);
            if (outBlock.sys_info.flag < 0)
            {
                this.EFMsgInfo = outBlock.sys_info.msg + "\n" + outBlock.sys_info.sysmsg;
                GC.PM_utility2.Dev_messageBoxError(this.EFMsgInfo);//弹出MSG,报错的状态                
                return;
            }
            int in_count = outBlock.Tables[0].Rows.Count;
            //循环添加列
            for (int i = 0; i < in_count;i++ )
            {
                tb.Rows.Add();
                tb.Rows[i][0] = outBlock.Tables[0].Rows[i]["STOCK_PLACE_NO"];//库位号
                tb.Rows[i][1] = outBlock.Tables[0].Rows[i]["MAT_NUM"];//支数
                tb.Rows[i][2] = 75;
                tb.Rows[i][3] = 75;
                tb.Rows[i][4] = (Convert.ToInt32(outBlock.Tables[0].Rows[i]["ADDR_X_CT"])).ToString();//x坐标
                tb.Rows[i][5] = (Convert.ToInt32(outBlock.Tables[0].Rows[i]["ADDR_Y_CT"])).ToString();//y坐标
                tb.Rows[i][6] = 1;
                tb.Rows[i][7] = "Green";
            }
            //添加辊道列(A13,A14之间)
            tb.Rows.Add();
            tb.Rows[in_count][0] = "辊道";
            tb.Rows[in_count][1] = "(S12库)";
            tb.Rows[in_count][2] = 180;
            tb.Rows[in_count][3] = 50;
            tb.Rows[in_count][4] = 275;
            tb.Rows[in_count][5] = 30;
            tb.Rows[in_count][6] = 2;
            tb.Rows[in_count][7] = "Yellow";//SkyBlue
                
            

            

            DrawStock(tb);
        }
        /// <summary>
        /// 画库位
        /// </summary>
        /// <param name="tb"> 传入的table 列名必须按要求</param>
        void DrawStock(DataTable tb)
        {

            for (int i = 0; i < tb.Rows.Count; i++)
            {
                for (int j = 0; j < tb.Columns.Count; j++)
                {
                    if (tb.Rows[i][j].ToString() == "")
                    {
                        continue;
                    }
                }
                Label label = new Label();
                label.Name = tb.Rows[i]["STOCK_PLACE_NO"].ToString();
                label.Text = tb.Rows[i]["STOCK_PLACE_NO"].ToString() + "\r\n" + tb.Rows[i]["STOCK_PLACE_DESC"].ToString();
                label.Height = Convert.ToInt32(tb.Rows[i]["HEIGHT"]);
                label.Width = Convert.ToInt32(tb.Rows[i]["WIDTH"]);
                label.Location = new Point(Convert.ToInt32(tb.Rows[i]["POINT_X"]), Convert.ToInt32(tb.Rows[i]["POINT_Y"]));
                if (Convert.ToInt32(tb.Rows[i]["STOCK_TYPE"]) == 1)
                {
                    label.Click += label_Click;
                    label.MouseMove += label_MouseMove;
                    label.MouseUp += label_MouseUp;
                    label.MouseDown += label_MouseDown;
                    label.Tag = 1;
                }
                label.BorderStyle = BorderStyle.FixedSingle;
                label.BackColor = Color.FromName(tb.Rows[i]["STOCK_COLOR"].ToString());
                label.TextAlign = ContentAlignment.MiddleCenter;
                STOCK.Controls.Add(label);
            }
        }
        int xPos;
        int yPos;

        #region 鼠标事件
        void label_MouseDown(object sender, MouseEventArgs e)// 鼠标按下时
        {
            if(configType)
            {
                moveFlag = true;
                xPos = e.X;
                yPos = e.Y;
            }
        }

        void label_MouseUp(object sender, MouseEventArgs e)// 库位控件,鼠标松开时,将坐标存进临时表, 不按保存,不更新后台
        {
            if (configType)
            {
                moveFlag = false;
                if (ControlDic.ContainsKey(((Label)sender).Name))
                {
                    ControlDic.Remove(((Label)sender).Name);
                }
                ControlDic.Add(((Label)sender).Name, ((Label)sender).Location);
            }
        }

        void label_MouseMove(object sender, MouseEventArgs e)///移动控件用
        {
            if (configType)
            {
                if (moveFlag)
                {
                    ((Label)sender).Left += Convert.ToInt32(e.X - xPos);
                    ((Label)sender).Top += Convert.ToInt32(e.Y - yPos);
                }
            }
        }
        #endregion

        #region 库位的点击事件,根据库位号,查询库位材料
        void label_Click(object sender, EventArgs e)
        {
            if (!configType)
            {
                //MessageBox.Show(((Label)sender).Name.ToString());
                EI.EIInfo inBlock = new EI.EIInfo();
                EI.EIInfo outBlock;
                inBlock.Tables[0].Columns.Add("STOCK_PLACE_NO");//库位号
                //获取库位号
                inBlock.Tables[0].Rows.Add();
                inBlock.Tables[0].Rows[0]["STOCK_PLACE_NO"] = ((Label)sender).Name.ToString();

                //调用service
                outBlock = EI.EIManager.Instance.CallService("MA9JZ", "ymsm09_inqm", inBlock);
                if (outBlock.sys_info.flag < 0)
                {
                    this.EFMsgInfo = outBlock.sys_info.msg + "\n" + outBlock.sys_info.sysmsg;
                    GC.PM_utility2.Dev_messageBoxError(this.EFMsgInfo);//弹出MSG,报错的状态                
                    return;
                }
                //将信息压入指定的GRID, 
                EF.Utility.SetCustomGridValue(efDevGrid1, outBlock, false);
            }
        }
        #endregion
        #region 维护模式
        bool configType = false;
        private void button1_Click(object sender, EventArgs e)
        {
            if (configType)//维护模式已经开,再按就是关
            {
                configType = false;
                button1.Text = "维护模式(关)";
            }
            else//维护模式已经关,再按就是开
            {
                configType = true;
                button1.Text = "维护模式(开)";
            }
        }
        Dictionary<string, Point> ControlDic = new Dictionary<string, Point>();//保存所有拖动过的控件Name 和 最后坐标, 保存的时候 更新给后台
        #endregion

        #region 保存坐标
        private void button2_Click(object sender, EventArgs e)
        {
            if (configType)//维护模式开的时候 。保存才会获取数据
            {
                int i=0;//记录坐标
                EI.EIInfo inBlock = new EI.EIInfo();
                EI.EIInfo outBlock;
                inBlock.Tables[0].Columns.Add("STOCK_PLACE_NO");//库位号
                inBlock.Tables[0].Columns.Add("ADDR_X_CT");//横坐标
                inBlock.Tables[0].Columns.Add("ADDR_Y_CT");//纵坐标
                //遍历坐标,传入后台更新
                foreach (var item in ControlDic)
                {
                    inBlock.Tables[0].Rows.Add();
                    inBlock.Tables[0].Rows[i]["STOCK_PLACE_NO"] = item.Key.ToString();
                    inBlock.Tables[0].Rows[i]["ADDR_X_CT"] = item.Value.X.ToString();
                    inBlock.Tables[0].Rows[i]["ADDR_Y_CT"] = item.Value.Y.ToString();
                    i++;
                }
                //调用service
                outBlock = EI.EIManager.Instance.CallService("MA9JZ", "ymsm09_upd", inBlock);
                if (outBlock.sys_info.flag < 0)
                {
                    this.EFMsgInfo = outBlock.sys_info.msg + "\n" + outBlock.sys_info.sysmsg;
                    GC.PM_utility2.Dev_messageBoxError(this.EFMsgInfo);//弹出MSG,报错的状态                
                    return;
                }
                else
                {
                    this.EFMsgInfo = "报存成功。";
                }
               
            }
        }
        #endregion
    }

}

 

上一篇:阿里云服务器CentOS 5.7(64位)安装配置LAMP服务器(Apache+PHP5+MySQL)


下一篇:Qt-设置背景色的几种方式