/// <summary>
        /// 设置箱子编码
        /// </summary>
        private void SetBoxNo()
        {
            Dictionary <CE_GoodsAttributeName, object> dic = UniversalFunction.GetGoodsInfList_Attribute_AttchedInfoList(m_barCodeInfo.GoodsID);

            if (!dic.Keys.ToList().Contains(CE_GoodsAttributeName.装箱数))
            {
                throw new Exception(UniversalFunction.GetGoodsMessage(m_barCodeInfo.GoodsID) + "基础属性未设置【装箱数】");
            }

            string prefix = "";

            if (dic.Keys.ToList().Contains(CE_GoodsAttributeName.CVT) && Convert.ToBoolean(dic[CE_GoodsAttributeName.CVT]))
            {
                prefix = CE_GoodsAttributeName.CVT.ToString();
            }
            else if (dic.Keys.ToList().Contains(CE_GoodsAttributeName.TCU) && Convert.ToBoolean(dic[CE_GoodsAttributeName.TCU]))
            {
                prefix = CE_GoodsAttributeName.TCU.ToString();
            }

            if (prefix == "")
            {
                throw new Exception("该物品基础属性未设置【TCU】或者【CVT】");
            }

            if (dataGridView1.Rows.Count == 0 || dataGridView1 == null)
            {
                txtBoxNo.Text = m_findSellIn.GetBoxNo(prefix);
            }
            else
            {
                if (txtBoxNo.Text.Trim() == "")
                {
                    DataTable dtTemp = (DataTable)dataGridView1.DataSource;

                    dtTemp = GlobalObject.DataSetHelper.SelectDistinct("", dtTemp, "BoxNo");

                    for (int i = 0; i < dtTemp.Rows.Count; i++)
                    {
                        DataTable dt = (DataTable)dataGridView1.DataSource;
                        DataRow[] dr = dt.Select("BoxNo = '" + dtTemp.Rows[i][0].ToString() + "'");

                        if (dr.Length != Convert.ToInt32(dic[CE_GoodsAttributeName.装箱数]))
                        {
                            txtBoxNo.Text = dtTemp.Rows[i][0].ToString();
                            return;
                        }
                    }

                    txtBoxNo.Text = m_findSellIn.GetBoxNo(prefix);
                }
                else
                {
                    DataTable dt = (DataTable)dataGridView1.DataSource;
                    DataRow[] dr = dt.Select("BoxNo = '" + txtBoxNo.Text + "'");

                    if (dr.Length == Convert.ToInt32(dic[CE_GoodsAttributeName.装箱数]))
                    {
                        string strGetNo = (Convert.ToInt32(txtBoxNo.Text.Substring(9, 4)) + 1).ToString("D4");
                        txtBoxNo.Text = txtBoxNo.Text.Substring(0, 9) + strGetNo;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            Dictionary <CE_GoodsAttributeName, object> dic = UniversalFunction.GetGoodsInfList_Attribute_AttchedInfoList(Convert.ToInt32(cmbProduct.Tag));

            if (!dic.Keys.ToList().Contains(CE_GoodsAttributeName.装箱数))
            {
                throw new Exception(UniversalFunction.GetGoodsMessage(Convert.ToInt32(cmbProduct.Tag)) + "基础属性未设置【装箱数】");
            }

            DataTable dt = (DataTable)dataGridView1.DataSource;

            if (dt == null || dt.Rows.Count == 0)
            {
                return;
            }

            dt.Columns.Add("BoxNo");

            string prefix = "";

            if (Convert.ToBoolean(dic[CE_GoodsAttributeName.CVT]))
            {
                prefix = CE_GoodsAttributeName.CVT.ToString();
            }
            else if (Convert.ToBoolean(dic[CE_GoodsAttributeName.TCU]))
            {
                prefix = CE_GoodsAttributeName.TCU.ToString();
            }

            string boxNo    = m_findSellIn.GetBoxNo(prefix);
            int    boxCount = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["入库方式"].ToString() == "未知")
                {
                    MessageDialog.ShowPromptMessage("入库方式不能为【未知】,请选择正确的入库方式");
                    return;
                }

                if (cmbStorage.Text == "售后库房" &&
                    (dt.Rows[i]["入库方式"].ToString() == "生产入库" || dt.Rows[i]["入库方式"].ToString() == "生产返修入库"))
                {
                    MessageDialog.ShowPromptMessage("入库方式错误,请选择正确的入库方式");
                    return;
                }

                if (boxCount == Convert.ToInt32(dic[CE_GoodsAttributeName.装箱数]))
                {
                    boxNo    = prefix + (Convert.ToInt64(boxNo.Substring(prefix.Length, boxNo.Length - prefix.Length)) + 1).ToString();
                    boxCount = 0;
                }

                dt.Rows[i]["BoxNo"] = boxNo;
                boxCount           += 1;
            }

            if (!m_findSellIn.BatchCreateBill(dt, out m_err))
            {
                MessageDialog.ShowPromptMessage(m_err);
                return;
            }
            else
            {
                MessageDialog.ShowPromptMessage("自动生成成功!");

                List <string> listBarcode = new List <string>();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    listBarcode.Add(dt.Rows[i]["箱体编号"].ToString());

                    if (i + 1 == dt.Rows.Count || dt.Rows[i]["BoxNo"] != dt.Rows[i + 1]["BoxNo"])
                    {
                        PrintPartBarcode.PrintBarcodeCVTNumberList(listBarcode);
                        PrintPartBarcode.PrintBarcode_120X30(dt.Rows[i]["BoxNo"].ToString());
                        listBarcode = new List <string>();
                    }
                }

                this.Close();
            }
        }