Exemplo n.º 1
0
        async private void Btn_selectMaterial_Click(object sender, EventArgs e)
        {
            //根据产品型号查询物料信息
            var typeNo = cb_material_typeNo.Text.Trim();

            MesService.ProductMaterial productMaterial = new MesService.ProductMaterial();
            productMaterial.TypeNo = typeNo;
            //DataTable dt = (await serviceClient.SelectProductMaterialAsync(productMaterial)).Tables[0];
            //this.radGridViewMaterial.DataSource = dt;
        }
        async private void DeleteRowData()
        {
            if (materialType == MaterialType.MATERIAL_BINDING)
            {
                if (this.radGridViewBind.RowCount < 1)
                {
                    MessageBox.Show("当前没有可删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                MesService.ProductMaterial productMaterial = new MesService.ProductMaterial();
                if (this.radGridViewBind.CurrentRow.Cells[2].Value != null)
                {
                    productMaterial.MaterialCode = this.radGridViewBind.CurrentRow.Cells[2].Value.ToString();
                }
                if (this.radGridViewBind.CurrentRow.Cells[1].Value != null)
                {
                    productMaterial.TypeNo = this.radGridViewBind.CurrentRow.Cells[1].Value.ToString();
                }
                if (this.radGridViewBind.CurrentRow.Cells[1].Value == null && this.radGridViewBind.CurrentRow.Cells[2].Value == null &&
                    this.radGridViewBind.CurrentRow.Cells[3].Value == null)
                {
                    this.radGridViewBind.CurrentRow.Delete();
                    return;
                }
                if (MessageBox.Show($"确认解除物料【{productMaterial.MaterialCode}】与产品【{productMaterial.TypeNo}】的绑定?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    int res = await serviceClient.DeleteProductMaterialAsync(productMaterial);

                    if (res > 0)
                    {
                        MessageBox.Show("解除绑定成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("解除绑定失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    SelectData();
                }
            }
            else if (materialType == MaterialType.MATERIAL_STOCK_MODIFY)
            {
                if (this.radGridViewStock.RowCount < 1)
                {
                    MessageBox.Show("当前没有可删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                var materialRid = this.radGridViewStock.CurrentRow.Cells[3].Value.ToString();
                if (MessageBox.Show($"确认删除料盘号为【{materialRid}】的物料?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    var materialCode = serviceClient.GetMaterialCode(materialRid);
                    int res          = serviceClient.DeleteMaterial(materialCode);
                    if (res > 0)
                    {
                        MessageBox.Show("删除物料成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("删除物料失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    SelectData();
                }
            }
        }
        async private void UpdateData()
        {
            this.radGridViewBind.CurrentRow = this.radGridViewBind.Rows[this.radGridViewBind.Rows.Count - 1];
            int rowCount = CalRowCount();

            MesService.ProductMaterial[] productMaterialList = new MesService.ProductMaterial[rowCount];
            int row = 0;

            foreach (var rowInfo in this.radGridViewBind.Rows)
            {
                MesService.ProductMaterial productMaterial = new MesService.ProductMaterial();
                if (rowInfo.Cells[1].Value != null)
                {
                    productMaterial.TypeNo = rowInfo.Cells[1].Value.ToString();
                }
                if (rowInfo.Cells[2].Value != null)
                {
                    var materialPn = rowInfo.Cells[2].Value.ToString();
                    if (materialPn.Contains("("))
                    {
                        materialPn = materialPn.Substring(0, materialPn.IndexOf('('));
                    }
                    productMaterial.MaterialCode = materialPn;
                    //更新编码库存
                    if (productMaterial.MaterialCode.Contains("&"))
                    {
                        productMaterial.Stock = AnalysisMaterialCode.GetMaterialDetail(productMaterial.MaterialCode).MaterialQTY;
                    }
                }
                if (rowInfo.Cells[3].Value != null)
                {
                    productMaterial.MaterialName = rowInfo.Cells[3].Value.ToString();
                }
                if (rowInfo.Cells[4].Value != null)
                {
                    productMaterial.Describle = rowInfo.Cells[4].Value.ToString();
                }
                productMaterial.UserName = MESMainForm.currentUser;

                if (rowInfo.Cells[1].Value != null && rowInfo.Cells[2].Value != null)
                {
                    productMaterialList[row] = productMaterial;
                }
                row++;
            }
            //delete修改数据
            foreach (var item in pmListTemp)
            {
                MesService.ProductMaterial productMaterial = new MesService.ProductMaterial();
                productMaterial.MaterialCode = item.keyMaterialCode;
                productMaterial.TypeNo       = item.keyTypeNo;
                int del = await serviceClient.DeleteProductMaterialAsync(productMaterial);
            }
            pmListTemp.Clear();
            MesService.ProductMaterial[] materialList = await serviceClient.CommitProductMaterialAsync(productMaterialList);

            foreach (var material in materialList)
            {
                if (material.Result != 1)
                {
                    MessageBox.Show("更新失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            MessageBox.Show("更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            SelectData();
        }