入库采集委托使用

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace MES.ThinClient.APP.Main
{
    public partial class FFinishSnBackInv : BaseForm
    {
        #region 属性
        private MES.ThinClient.APP.Main.WebService.WebService _service = new MES.ThinClient.APP.Main.WebService.WebService();
        /// <summary>
        /// 数据源
        /// </summary>
        private DataTable g_dtSource = null;
        FMessageBoxForm msgBox = null;
        #endregion

        public FFinishSnBackInv()
        {
            BaseForm.menuName = "完工返数采集";
            InitializeComponent();
        }
        private void FFinishSnBackInv_Load(object sender, EventArgs e)
        {
            _service.Url = LoginInfo.Current.Url;
            this.InitGrid();
            this.InitTransStyle();
            if (msgBox == null)
                msgBox = new FMessageBoxForm();
            this.cboInvCode.Enabled = false;
            this.dgInfo.Visible = false;
        }

        #region 初始化datagrid
        private void InitGrid()
        {
            this.g_dtSource = new DataTable();
            this.g_dtSource.Columns.Add("ID").ReadOnly = true;
            this.g_dtSource.Columns.Add("MoName").ReadOnly = true;

            this.g_dtSource.Columns.Add("MoPlanQty").ReadOnly = true;
            this.g_dtSource.Columns.Add("CollectionQty").ReadOnly = true;
            this.g_dtSource.Columns.Add("SYQty").ReadOnly = true;

            this.g_dtSource.Columns.Add("MoItemName").ReadOnly = true;
            this.g_dtSource.Columns.Add("MOItemDescription").ReadOnly = true;
            this.g_dtSource.Columns.Add("MoPlanDate").ReadOnly = true;
            this.g_dtSource.Columns.Add("MoOffQty").ReadOnly = true;
            this.g_dtSource.Columns.Add("CurShiftQty").ReadOnly = true;
            this.g_dtSource.Columns.Add("MoOnQty").ReadOnly = true;
            this.g_dtSource.DefaultView.AllowNew = false;
            this.dgInfo.DataSource = this.g_dtSource.DefaultView;

            #region grid 标题与样式
            DataGridTableStyle dg = new DataGridTableStyle();
            if (dgInfo.TableStyles.Count == 0)
            {
                dg.MappingName = (dgInfo.DataSource as DataView).Table.TableName;
                this.dgInfo.TableStyles.Add(dg);

                dg.GridColumnStyles[0].HeaderText = "*";
                dg.GridColumnStyles[1].HeaderText = "作业号";

                dg.GridColumnStyles[2].HeaderText = "排产量";
                dg.GridColumnStyles[3].HeaderText = "已采";
                dg.GridColumnStyles[4].HeaderText = "剩余";

                dg.GridColumnStyles[5].HeaderText = "装配件编码";
                dg.GridColumnStyles[6].HeaderText = "装配件描述";
                dg.GridColumnStyles[7].HeaderText = "排产日期";
                dg.GridColumnStyles[8].HeaderText = "下线";
                dg.GridColumnStyles[9].HeaderText = "当班";
                dg.GridColumnStyles[10].HeaderText = "上线";

                dg.GridColumnStyles[0].Width = 20;
                dg.GridColumnStyles[1].Width = 80;
                dg.GridColumnStyles[2].Width = 50;
                dg.GridColumnStyles[3].Width = 40;
                dg.GridColumnStyles[4].Width = 40;
                dg.GridColumnStyles[5].Width = 100;
                dg.GridColumnStyles[6].Width = 80;
                dg.GridColumnStyles[7].Width = 60;
                dg.GridColumnStyles[8].Width = 40;
                dg.GridColumnStyles[9].Width = 40;
                dg.GridColumnStyles[10].Width = 40;

                for (int i = 0; i <= dgInfo.TableStyles.Count - 1; i++)
                {
                    dg.GridColumnStyles[i].NullText = string.Empty;
                }
            }
            #endregion
        }
        #endregion

        #region 初始化事物类型
        private void InitTransStyle()
        {
            ItemObject ioTransType = new ItemObject() { ItemValue = "FINISH_GOOD_INV_BACK", ItemText = "完工返数" };
            this.cboTransStyle.Items.Add(ioTransType);
            this.cboTransStyle.SelectedIndex = 0;//默认为完工返数
            this.cboTransStyle.Enabled = false;
        }
        #endregion

        #region 完工返数采集
        private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != ‘\r‘ || this.txtBarcode.Text.Trim() == "")
            {
                return;
            }
            if (this.IsFullWidth(this.txtBarcode.Text.Trim()))
            {
                MessageBox.Show("条码中包含全角字符!");
                Application.DoEvents();
                this.txtBarcode.Focus();
                return;
            }
            //是否将条码转成大写
            this.txtBarcode.Text = this.txtBarcode.Text.ToUpper();
            this.cboInvCode.Items.Clear();
            this.lblMsg.Text = string.Empty;
            try
            {
                OutputWebMessage output = this._service.FGBackInv_SaveBackInv(this.txtBarcode.Text.Trim(), -1, string.Empty, LoginInfo.Current.UserCode,"BACK", DateTime.Now, LoginInfo.Current.OrgID);
                if (output != null && output.IsSuccess == true)
                {
                    if (output.ExtendData != null)
                    {
                        DataTable tableResMoQty = output.ExtendData as DataTable;
                        if (tableResMoQty.Rows.Count > 0)
                        {
                            //string strQty = "0";
                            //string strSSName = string.Empty;
                            //string strSegName = string.Empty;
                            string strMoName = string.Empty;
                            string strItemDesc = string.Empty;
                            string strItemCode = string.Empty;
                            //string strPlanQty = string.Empty;
                            //string strOnLineQty = string.Empty;
                            //string strOffLineQty = string.Empty;
                            string strMoPlanStartDate = string.Empty;
                            //string strCurShiftQty = string.Empty;
                            if (tableResMoQty.Rows[0]["MONAME"] != DBNull.Value && tableResMoQty.Rows[0]["MONAME"].ToString() != "null")
                            {
                                strMoName = tableResMoQty.Rows[0]["MONAME"].ToString();
                            }

                            //if (tableResMoQty.Rows[0]["SSNAME"] != DBNull.Value && tableResMoQty.Rows[0]["SSNAME"].ToString() != "null")
                            //{
                            //    strSSName = tableResMoQty.Rows[0]["SSNAME"].ToString();
                            //}

                            //if (tableResMoQty.Rows[0]["SEGNAME"] != DBNull.Value && tableResMoQty.Rows[0]["SEGNAME"].ToString() != "null")
                            //{
                            //    strSegName = tableResMoQty.Rows[0]["SEGNAME"].ToString();
                            //}

                            if (tableResMoQty.Rows[0]["ITEMDESC"] != DBNull.Value && tableResMoQty.Rows[0]["ITEMDESC"].ToString() != "null")
                            {
                                strItemDesc = tableResMoQty.Rows[0]["ITEMDESC"].ToString();
                            }
                            if (tableResMoQty.Rows[0]["ITEMCODE"] != DBNull.Value && tableResMoQty.Rows[0]["ITEMCODE"].ToString() != "null")
                            {
                                strItemCode = tableResMoQty.Rows[0]["ITEMCODE"].ToString();
                            }
                            //if (tableResMoQty.Rows[0]["OUTPUTQTY"] != DBNull.Value && tableResMoQty.Rows[0]["OUTPUTQTY"].ToString() != "null")
                            //{
                            //    strQty = tableResMoQty.Rows[0]["OUTPUTQTY"].ToString();
                            //}
                            //if (tableResMoQty.Rows[0]["PLANQTY"] != DBNull.Value && tableResMoQty.Rows[0]["PLANQTY"].ToString() != "null")
                            //{
                            //    strPlanQty = tableResMoQty.Rows[0]["PLANQTY"].ToString();
                            //}
                            //if (tableResMoQty.Rows[0]["ONLINEQTY"] != DBNull.Value && tableResMoQty.Rows[0]["ONLINEQTY"].ToString() != "null")
                            //{
                            //    strOnLineQty = tableResMoQty.Rows[0]["ONLINEQTY"].ToString();
                            //}
                            //if (tableResMoQty.Rows[0]["OFFLINEQTY"] != DBNull.Value && tableResMoQty.Rows[0]["OFFLINEQTY"].ToString() != "null")
                            //{
                            //    strOffLineQty = tableResMoQty.Rows[0]["OFFLINEQTY"].ToString();
                            //}
                            if (tableResMoQty.Rows[0]["DATETIME_SCHE_START"] != DBNull.Value && tableResMoQty.Rows[0]["DATETIME_SCHE_START"].ToString() != "null")
                            {
                                strMoPlanStartDate = tableResMoQty.Rows[0]["DATETIME_SCHE_START"].ToString();
                            }
                            //if (tableResMoQty.Rows[0]["curshiftqty"] != DBNull.Value && tableResMoQty.Rows[0]["curshiftqty"].ToString() != "null")
                            //{
                            //    strCurShiftQty = tableResMoQty.Rows[0]["curshiftqty"].ToString();
                            //}
                            //提示
                            this.DisplayMessage("采集成功!", "OK");
                            //头信息
                            //返数数量+1
                            int temp = string.IsNullOrEmpty(this.lblBackNum.Text) ? 0 : Convert.ToInt32(this.lblBackNum.Text);
                            this.lblBackNum.Text = (temp + 1).ToString();
                            //子库
                            if (tableResMoQty.Rows[0]["DefaultInv"] != DBNull.Value && tableResMoQty.Rows[0]["DefaultInv"].ToString() != "null")
                            {
                                this.cboInvCode.Items.Add(tableResMoQty.Rows[0]["DefaultInv"].ToString());
                                this.cboInvCode.SelectedIndex = 0;
                            }
                            //作业号
                            this.lblMOName.Text = strMoName;
                            //装配件
                            this.lblMitemName.Text = strItemDesc;
                            //统计信息
                            //this.BindCollectQty(strSSName, strSegName, strMoName, strItemCode, strItemDesc, strPlanQty, strQty, strOnLineQty, strOffLineQty, strMoPlanStartDate, strCurShiftQty);
                        }
                        else
                        {
                            //提示
                            this.DisplayMessage(string.Format("[{0}]采集成功!", this.txtBarcode.Text), "OK");
                            this.lblMsg.Text = "采集成功!但查询统计信息失败!";
                        }
                    }
                    //提示
                    this.DisplayMessage(string.Format("[{0}]采集成功!", this.txtBarcode.Text), "OK");
                }
                else
                {
                    this.DisplayMessage(string.Format("[{0}]采集失败!{1}", this.txtBarcode.Text, output.ErrorMessage), "Fail");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.lblMsg.Text = ex.Message;
            }
        } 
        #endregion

        #region 更新列表
        public void BindCollectQty(string ssname, string segname, string moname, string itemcode, string itemdesc, string planqty, string outputqty, string onlineqty, string offlineqty, string moplanstartdate, string curshiftqty)
        {
            try
            {
                bool bFlag = false;
                if (this.g_dtSource != null && g_dtSource.Rows.Count > 0)
                {
                    //bool bFlag = false;
                    for (int i = 0; i < this.g_dtSource.Rows.Count; i++)
                    {
                        if (this.lblMOName.Text == this.g_dtSource.Rows[i]["MoName"].ToString())
                        {
                            this.g_dtSource.Columns["CurShiftQty"].ReadOnly = false;
                            this.g_dtSource.Columns["CollectionQty"].ReadOnly = false;
                            this.g_dtSource.Columns["SYQty"].ReadOnly = false;
                            //计划量
                            int iPlanQty = ConverToInt32(this.g_dtSource.Rows[i]["MOPLANQTY"].ToString(), 0);
                            //工位采集总数量
                            int iSumQty = ConverToInt32(this.g_dtSource.Rows[i]["CollectionQty"].ToString(), 0);
                            //当班数量
                            int iShiftCodeQty = ConverToInt32(this.g_dtSource.Rows[i]["CurShiftQty"].ToString(), 0);
                            //临时存放
                            int iTemp = int.Parse(outputqty) - iSumQty;

                            // 如果差异数值小于0,或者大于2,则重新加载表格
                            //if (iTemp < 0 || iTemp >= 2)
                            if (iTemp > 0 || iTemp <= -2)
                                break;

                            this.g_dtSource.Rows[i]["CollectionQty"] = outputqty;
                            this.g_dtSource.Rows[i]["CurShiftQty"] = iShiftCodeQty + iTemp;
                            this.g_dtSource.Rows[i]["SYQty"] = (iPlanQty - int.Parse(outputqty));
                            bFlag = true;

                            this.g_dtSource.Columns["CurShiftQty"].ReadOnly = true;
                            this.g_dtSource.Columns["CollectionQty"].ReadOnly = true;
                            this.g_dtSource.Columns["SYQty"].ReadOnly = true;
                            break;
                        }
                    }
                }
                else
                {
                    bFlag = false;
                }
                if (bFlag == false)
                {
                    //计划量
                    int iPlanQty = ConverToInt32(planqty, 0);
                    //工位采集总数
                    int iSumQty = ConverToInt32(outputqty, 0);
                    //剩余量
                    int iQty = iPlanQty - iSumQty;
                    string strDate = "";
                    try
                    {
                        strDate = moplanstartdate;//dt.Rows[i]["MOPLANSTARTDATE"].ToString();
                    }
                    catch { }
                    DataTable dtTmp = this.g_dtSource.Clone();
                    DataRow[] rows = dtTmp.Select("MONAME=‘" + moname + "‘");

                    if (rows != null && rows.Length > 0)
                    {
                        if (int.Parse(rows[0]["CurShiftQty"].ToString()) > 0)
                            rows[0]["CurShiftQty"] = Convert.ToInt32(rows[0]["CurShiftQty"]) + Convert.ToInt32(curshiftqty);
                        else
                            rows[0]["CurShiftQty"] = curshiftqty;
                        rows[0]["CollectionQty"] = Convert.ToInt32(rows[0]["CollectionQty"]) + Convert.ToInt32(outputqty);
                        rows[0]["SYQty"] = iPlanQty - Convert.ToInt32(rows[0]["CollectionQty"]);
                    }
                    else
                    {
                        dtTmp.Rows.Add(
                                new object[] {  
                                this.g_dtSource.Rows.Count+1,
                                moname,
                                iPlanQty.ToString(),
                                iSumQty.ToString(),
                                iQty.ToString(),

                                itemcode,
                                itemdesc,
                                strDate,
                               
                                offlineqty,
                                curshiftqty,
                                onlineqty
                            });
                    }
                    this.g_dtSource = dtTmp;

                    DataView dv = new DataView(g_dtSource);
                    dv.AllowNew = false;
                    dv.AllowEdit = false;
                    dv.AllowDelete = false;
                    dgInfo.DataSource = dv;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        } 
        #endregion

        #region Convert string to Int32
        private int ConverToInt32(string s, int defaultvalue)
        {
            try
            {
                Int32.Parse(s);
                return Int32.Parse(s);
            }
            catch
            {
                return defaultvalue;
            }
        } 
        #endregion

        #region 其他事件
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void txtBarcode_GotFocus(object sender, EventArgs e)
        {
            Control_GotFocus(sender);
        }
        private void txtBarcode_LostFocus(object sender, EventArgs e)
        {
            Control_LostFocus(sender);
        }

        private void FFinishSnBackInv_Closing(object sender, CancelEventArgs e)
        {
            AutoConnent.Enabled = false;
            AutoConnent.Dispose();
        }

        private void AutoConnent_Tick(object sender, EventArgs e)
        {
            this.checkConnent();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            this.cboInvCode.Items.Clear();
            this.cboInvCode.Text = string.Empty;
            this.lblMOName.Text = string.Empty;
            this.lblMitemName.Text = string.Empty;
            this.lblBackNum.Text = string.Empty;
            this.txtBarcode.Text = string.Empty;
            this.lblMsg.Text = string.Empty;
            this.g_dtSource.Rows.Clear();
            this.txtBarcode.Focus();
        }
        #endregion

        #region 信息显示
        public void DisplayMessage(string message, string type)
        {
            this.lblMsg.Text = message;
            if (type == "OK")
            {
                this.lblMsg.ForeColor = Color.Blue;
                msgBox.ShowSuccess();
            }
            else
            {
                this.lblMsg.ForeColor = Color.Red;
                msgBox.ShowError();
            }
        }
        #endregion

        #region 检查是否存在全角字符
        /// <summary>
        /// 检查是否存在全角字符
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private bool IsFullWidth(string text)
        {
            for (int i = 0; i < text.Length; i++)
            {
                int count = System.Text.Encoding.Default.GetByteCount(text.Substring(i, 1));
                if (count == 2)
                {
                    return true;
                }
            }
            return false;
        }
        #endregion

        #region TextBox根据焦点状态改变背景色
        private void Control_GotFocus(object sender)
        {
            if (sender is TextBox)
            {
                ((TextBox)sender).SelectAll();
                ((TextBox)sender).BackColor = Color.GreenYellow;
            }
        }
        private void Control_LostFocus(object sender)
        {
            if (sender is TextBox)
            {
                ((TextBox)sender).BackColor = Color.Yellow;
            }
        }
        #endregion

        #region 网络监测
        private bool checkConnent()
        {
            try
            {
                string testNet = _service.HelloWorld();
                this.Invoke(new SetAttributeDelegate(SetAttribute), lblNetMsg, "Label", "ForeColor", Color.PaleGreen.ToArgb().ToString());

                this.Invoke(new SetAttributeDelegate(SetAttribute), this.txtBarcode, "TextBox", "Enabled", "true");
                return true;
            }
            catch
            {
                this.Invoke(new SetAttributeDelegate(SetAttribute), lblNetMsg, "Label", "ForeColor", Color.Red.ToArgb().ToString());

                this.Invoke(new SetAttributeDelegate(SetAttribute), this.txtBarcode, "TextBox", "Enabled", "false");
                return false;
            }
        }

        public delegate void SetAttributeDelegate(Control control, string type, string attribute, string content);

        public delegate string GetAttributeDelegate(Control control, string type, string attribute);

        private void SetAttribute(Control control, string type, string attribute, string content)
        {
            if (attribute == "ForeColor")
            {
                if (type == "Label")
                {
                    try
                    {
                        ((Label)control).ForeColor = Color.FromArgb(int.Parse(content));
                    }
                    catch { }
                }
            }
            else if (attribute == "Text")
            {
                if (type == "Label")
                {
                    ((Label)control).Text = content;
                }
                else if (type == "Button")
                {
                    ((Button)control).Text = content;
                }
                else if (type == "TextBox")
                {
                    ((TextBox)control).Text = content;
                }
            }
            else if (attribute == "Enabled")
            {
                if (type == "Button")
                {
                    try
                    {
                        ((Button)control).Enabled = bool.Parse(content);
                    }
                    catch { }
                }
            }
            else if (attribute == "Focus")
            {
                if (type == "TextBox")
                {
                    ((TextBox)control).Focus();
                }
            }
        }

        private string GetAttribute(Control control, string type, string attribute)
        {
            if (attribute == "Text")
            {
                if (type == "ComboBox")
                {
                    try
                    {
                        return ((ComboBox)control).Text;
                    }
                    catch { }
                }
            }

            return "";

        }
        #endregion

        
    }
}
时间: 2024-11-04 19:01:34

入库采集委托使用的相关文章

python下保持mysql连接,避免“MySQL server has gone away“方法

因需要对saltstack的所有动作进行入库采集,网上采集脚本mysql连接会因超时而断开,导致守护进程在下一次采集数据时提示: Traceback (most recent call last):   File "./salt_event_to_mysql.py", line 39, in <module>     ret['success'], json.dumps(ret)))   File "build/bdist.linux-x86_64/egg/MyS

初学ELK

一.ELK介绍ELK是Elasticsearch.Logstash.Kibana三大开源框架首字母大写简称.二.我司应用1)同花顺PC客户端防外挂报送系统2)同花顺智能客服系统下面简单介绍下我司PC客户端防外挂系统.由于之前没有了解过ELK,在部署同花顺防外挂报送系统时候才逐步知道,同花顺自研了数据流引擎collect及pms,用于采集委托主站上日志到ES上,实时分析功能的kibana未要求安装,不方便对ES进行管理,故自行安装了下kibana,上面可以查询ES相关状态,数据等,对不熟悉界面查看

基于PHP采集数据入库程序(二)

在上篇基于PHP采集数据入库程序(二) 中提到采集新闻信息页的列表数据,接下来讲讲关于采集新闻具体内容 这是上篇博客的最终数据表截图: 接下来要做的操作就是从数据库中读取所需要采集的URL,进行页面抓取就行 新建一个content表 不过需要注意的一点是,不能再采用采集URL这种id递增的方法去采集,因为数据表中可能出现id断续,比如id=9,id=11,当采集到id=10的时候,URL是空白的,这样可能会导致采集到了空字段. 这里用到的一个技巧是数据库的查询语句,在我们采集完第一条数据的时候,

基于PHP采集数据入库程序(一)

前几天有一朋友要我帮做一个采集新闻信息的程序,抽了点时间写了个PHP版本的,随笔记录下. 说到采集,无非就是远程获取信息->提取所需内容->分类存储->读取->展示 也算是简单"小偷程序"的加强版吧 下面是对应核心代码(别拿去做坏事哦^_^) 所要采集的内容是某游戏网站上的公告,如下图: 可先利用file_get_contents和简单正则获取基本页面信息 整理下基本信息,采集入库: <?php include_once("conn.php&qu

采集入库程序原理

php开发通用采集程序(一) php采集程序构建基本步骤:采集程序是什么?获取远程数据(文字.图片.图片)并快速保存到本地或指定地址.如天气预报(小偷程序):远程获取-->替换内容-->展示给用户如实时更新的新闻(采集内容):远程获取-->提取内容-->分类存储-->读取内容--->展示内容 *************************设计PHP采集入库UML 列表正则: 终端正则:**************************file_get_conten

CMDB3 完善采集端代码(ssh方案的多线程采集), 异常处理, 服务端目录结构的设计(django的app), API数据分析比对入库

完善一下采集端代码 ssh方案的多线程采集 线程和进程,协程的区别 (90% 问到) 提高并发的话,使用多线程 python2 多进程有 多线程没有 python3 多进程有 多线程有 from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor p = ThreadPoolExecutor(10) def test(i): time.sleep(1) print(i) for i in range(100): p.s

webmagic采集CSDN的Java_WebDevelop页面

项目中使用到了webmagic,采集论坛一类的页面时需要一些特殊的配置.在此记录一下 先来看看我要采集的页面 点击第2页可以看到它的url是http://bbs.csdn.net/forums/Java_WebDevelop?page=2 点击尾页可以看到它的url是http://bbs.csdn.net/forums/Java_WebDevelop?page=758 也就是说我们需要采集的范围是从2到758页 这样我们就可以通过自己拼接一个url来模拟所有 的连接了代码如下: <span st

CMDB资产采集

Agent(方式) 1:服务器每台都需要安装Agent 达到采集速度快,简单:造成性能损耗 获取每台服务器的资产并有返回值:v=subprocess.getoutput('dir')或者ipconfig 返回给api api在进行入库 (api 1.url 2.指定发送数据格式 3.并有返回值给客户端) 2:应用场景:服务较多的公司 客户端: import subprocess v1=subprocess.getoutput('ipconfig') # print(v1) value1=v1[2

电信采集子项目1(大体架构)

大体分为两个方面: 1.客户端  负责采集各个区域产生的数据信息分为5个模块 1.1 配置模块 1.2 日志模块 1.3 采集模块 1.4 备份模块 1.5 网络模块 2.服务器 接收数据 1.1 配置模块 1.2 日志模块 1.3 入库模块 1.4 备份模块 1.5 网络模块 BIDR类 用来分装采集好的数据 接口 Gather接口 客户端采集模块 负责采集指定文件中的数据(AAA服务器产生的文件) 需要实现的方法: Collection<BIDR> gather(); 采集文件样例: #b