コード例 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("无数据需要导入!");
                return;
            }

            string checkdate = "";
            string kpno      = "";
            string plant     = "";
            string stock_id  = "";
            Dictionary <string, object> dic = new Dictionary <string, object>();

            try
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    checkdate = dataGridView1[1, i].Value.ToString();
                    kpno      = dataGridView1[2, i].Value.ToString();
                    plant     = dataGridView1[3, i].Value.ToString();
                    stock_id  = dataGridView1[4, i].Value.ToString();

                    dic.Clear();
                    dic.Add("check_date", checkdate);
                    dic.Add("material_no", kpno);
                    dic.Add("plant", plant);
                    dic.Add("stock_id", stock_id);
                    SearchInventoryCheckByMaterialNo sc = new SearchInventoryCheckByMaterialNo(dic);
                    sc.ExecuteQuery();
                    DataTable dt = sc.GetResult();
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        continue;
                    }

                    InsertInventoryCheckByMaterialNo ic = new InsertInventoryCheckByMaterialNo(checkdate, kpno, plant, stock_id);
                    ic.ExecuteUpdate();
                }

                _woid     = dataGridView1[1, 0].Value.ToString();
                _plant    = dataGridView1[3, 0].Value.ToString();
                _stock_id = dataGridView1[4, 0].Value.ToString();

                MessageBox.Show("导入成功!");

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show("导入异常:" + ex.Message);
            }
        }
コード例 #2
0
        private bool CreateStockCountTask()
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            DataTable dt       = new DataTable();
            string    date     = string.Format("{0:D4}{1:D2}{2:D2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);;
            string    plant    = "";
            string    stock_id = "";
            //string woid = "";
            int qty = 0;

            try
            {
                SearchMaterialPickAssign sm = new SearchMaterialPickAssign(dic);
                sm.ExecuteQuery();

                dt = sm.GetResult();
                if (dt != null && dt.Rows.Count > 0)
                {
                    date = dt.Rows[0]["StockOutNo"].ToString().Trim();
                    qty  = int.Parse(dt.Rows[0]["Qty"].ToString().Trim());
                    if (qty != -1)
                    {
                        ShowHint("请先完成单号:" + woid + " 的出库任务", Color.Red);
                        return(false);
                    }
                }

                if (qty == -1)   //存在盘点任务
                {
                    dic.Clear();
                    dic.Add("check_date", date);
                    dic.Add("status", "0");
                    SearchInventoryCheckByMaterialNo sc = new SearchInventoryCheckByMaterialNo(dic);
                    sc.ExecuteQuery();
                    dt = sc.GetResult();
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        plant    = dt.Rows[0]["Plant"].ToString();
                        stock_id = dt.Rows[0]["Stock_Id"].ToString();
                        string kpno = dt.Rows[0]["KpNo"].ToString();
                        if (kpno.Trim().Equals("*"))
                        {
                            ShowHint("请先完成:" + date + " 的全部盘点任务!", Color.Red);
                            comboBox_pd.SelectedIndex = 1;
                        }
                        else
                        {
                            ShowHint("请先完成:" + date + " 的料号盘点任务!", Color.Red);
                            comboBox_pd.SelectedIndex = 2;
                        }
                    }
                    else
                    {
                        ShowHint("请先完成:" + date + " 的储位盘点任务!", Color.Red);
                        comboBox_pd.SelectedIndex = 3;
                    }

                    return(true);
                }

                if (comboBox_pd.SelectedIndex == 0)
                {
                    ShowHint("请选择一个盘点类型!", Color.Red);
                    comboBox_pd.Focus();
                    return(false);
                }
                else if (comboBox_pd.SelectedIndex == 1) //全部盘点
                {
                    using (SetStockDate ss = new SetStockDate())
                    {
                        if (ss.ShowDialog() != DialogResult.OK)
                        {
                            return(false);
                        }

                        date     = ss.GetDate();
                        plant    = ss.GetPlant();
                        stock_id = ss.GetStockId();
                    }
                }
                else if (comboBox_pd.SelectedIndex == 2)//料号盘点,导入数据
                {
                    using (ImportKpNoData ic = new ImportKpNoData())
                    {
                        if (ic.ShowDialog() != DialogResult.OK)
                        {
                            return(false);
                        }

                        date     = ic.GetWoId();
                        plant    = ic.GetPlant();
                        stock_id = ic.GetStockId();
                    }

                    //查询导入数据是否需要盘点,status=0
                    try
                    {
                        dic.Clear();
                        dic.Add("check_date", date);
                        dic.Add("plant", plant);
                        dic.Add("stock_id", stock_id);
                        dic.Add("status", "0");
                        SearchInventoryCheckByMaterialNo sc = new SearchInventoryCheckByMaterialNo(dic);
                        sc.ExecuteQuery();
                        dt = sc.GetResult();
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            ShowHint("无料号需要盘点", Color.Red);
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowHint("SearchInventoryCheckByMaterialNo:" + ex.Message, Color.Red);
                        return(false);
                    }
                }
                else if (comboBox_pd.SelectedIndex == 3)
                {
                    using (ImportLocIdData ic = new ImportLocIdData())
                    {
                        if (ic.ShowDialog() != DialogResult.OK)
                        {
                            return(false);
                        }

                        date     = ic.GetWoId();
                        plant    = ic.GetPlant();
                        stock_id = ic.GetStockId();
                    }

                    //查询导入数据是否需要盘点,status=0
                    try
                    {
                        dic.Clear();
                        dic.Add("check_date", date);
                        dic.Add("plant", plant);
                        dic.Add("stock_id", stock_id);
                        dic.Add("status", "0");
                        SearchInventoryCheckByLocId sc = new SearchInventoryCheckByLocId(dic);
                        sc.ExecuteQuery();
                        dt = sc.GetResult();
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            ShowHint("无料号需要盘点", Color.Red);
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowHint("SearchInventoryCheckByLocId:" + ex.Message, Color.Red);
                        return(false);
                    }
                }

                //生成盘点任务
                string result = DBPCaller.CreateCheckTask(date, comboBox_pd.SelectedIndex - 1);
                if (!result.ToUpper().Trim().Equals("OK"))
                {
                    AddLog("生成任务失败:" + result);
                    ShowHint("生成盘点任务失败:" + result, Color.Red);
                    return(false);
                }
                AddLog("盘点日期:" + date);
            }
            catch (Exception ex)
            {
                ShowHint(ex.Message, Color.Red);
                return(false);
            }

            try
            {
                SearchTaskCount st = new SearchTaskCount(2, MyData.GetStationId());
                st.ExecuteQuery();

                int result = st.GetResult();

                label_pd_ShelfCnt.Text = result.ToString();

                if (result > 0)
                {
                    AddLog("生成盘点任务成功!");
                    ShowHint("生成盘点任务成功!", Color.Lime);
                    return(true);
                }
                else
                {
                    AddLog("生成任务失败,不需要搬运货架!");
                    ShowHint("生成任务失败,不需要搬运货架!", Color.Red);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ShowHint("获取货架数目异常: " + ex.Message, Color.Red);
                return(false);
            }
        }
コード例 #3
0
        private void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            if (string.IsNullOrEmpty(textBox3.Text.Trim()))
            {
                MessageBox.Show("库位不能为空!");
                textBox3.Focus();
                return;
            }

            if (string.IsNullOrEmpty(textBox2.Text.Trim()))
            {
                MessageBox.Show("工厂不能为空!");
                textBox2.Focus();
                return;
            }

            if (string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                MessageBox.Show("盘点日期不能为空!");
                textBox1.Focus();
                return;
            }

            try
            {
                _date     = textBox1.Text.Trim();
                _plant    = textBox2.Text.Trim();
                _stock_id = textBox3.Text.Trim();
                if (_date.Length != 10)
                {
                    MessageBox.Show("长度不对,应为8位");
                    return;
                }
                if (!_date.All(c => (c >= '0' && c <= '9')))
                {
                    MessageBox.Show("输入格式不对,格式必须为:20180608,请重新输入!");
                    return;
                }

                Dictionary <string, object> dic = new Dictionary <string, object>();

                //检查要盘点的信息是否有记录
                dic.Clear();
                dic.Add("plant", _plant);
                dic.Add("stock_id", _stock_id);
                dic.Add("status", "1");
                SearchRInventoryDetail sr = new SearchRInventoryDetail(dic);
                sr.ExecuteQuery();
                DataTable dt = sr.GetResult();
                if (dt == null || dt.Rows.Count == 0)
                {
                    MessageBox.Show("根据工厂和库位查询不到在库物料,请修改盘点条件!");
                    textBox3.Focus();
                    return;
                }

                //检查盘点是否重复
                dic.Clear();
                dic.Add("check_date", _date);
                dic.Add("plant", _plant);
                dic.Add("stock_id", _stock_id);
                SearchInventoryCheckByMaterialNo sc = new SearchInventoryCheckByMaterialNo(dic);
                sc.ExecuteQuery();
                dt = sc.GetResult();
                if (dt != null && dt.Rows.Count > 0)
                {
                    string status = dt.Rows[0]["Status"].ToString();
                    if (status.Equals("1"))
                    {
                        MessageBox.Show("该日期,工厂,库位的条件已经盘点过,请修改盘点信息!");
                        textBox1.Text = "";
                        textBox1.Focus();
                        return;
                    }
                }
                else
                {
                    //插入盘点信息
                    InsertInventoryCheckByMaterialNo ic = new InsertInventoryCheckByMaterialNo(_date, "*", _plant, _stock_id);
                    ic.ExecuteUpdate();
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                textBox1.Text = "";
                textBox1.Focus();
            }
        }