//수정할 반제품의 조합데이터를 List에 받아서 사용자 컨트롤에 할당
        private void UpdateInfoLoad()
        {
            try
            {
                BOMService service = new BOMService();
                list = service.GetAllProduct();
                List <BOMVO> productList = service.GetAllCombination($"'{pCode}'");
                foreach (Control control in splitContainer2.Panel1.Controls)
                {
                    if (control is SemiProductCompControl)
                    {
                        SemiProductCompControl spc = (SemiProductCompControl)control;

                        for (int i = 0; i < productList.Count; i++)
                        {
                            if (spc.LblName.Tag.ToString().Equals(productList[i].Product_Category))
                            {
                                spc.TxtName.Text  = productList[i].Product_Name;
                                spc.TxtName.Tag   = productList[i].Combination_Product_ID;
                                spc.Qty.Tag       = productList[i].Product_Price;
                                spc.Qty.Value     = productList[i].Combination_RequiredQty;
                                spc.LblMoney.Tag  = 1;
                                spc.LblMoney.Text = productList[i].Product_Price.ToString("#,##0") + "원";
                            }
                        }
                        spc.Qty.ValueChanged += new EventHandler(TotalPrice);
                    }
                }
            }
            catch (Exception err)
            {
                Log.WriteError(err.Message, err);
            }
        }
示例#2
0
        private void InsertProduct()
        {
            //이미지를 Byte 배열로 변환
            Cursor currentCursor = this.Cursor;

            this.Cursor = Cursors.WaitCursor;
            string localFile = pictureBox1.Tag.ToString().Replace("\\", "/");

            byte[]       ImageData;
            FileStream   fs = new FileStream(localFile, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            ImageData = br.ReadBytes((int)fs.Length);
            br.Close();
            fs.Close();

            ProductVO Pitem = new ProductVO
            {
                Product_Name     = txtProductName.Text,
                Product_Price    = Convert.ToInt32(txtProductMoney.Text.Replace(",", "").Replace("원", "")),
                Product_Category = cboProductCategory.SelectedValue.ToString(),
                Product_Origin   = Convert.ToInt32(lblOrigin.Text.Replace(",", "").Replace("원", "")),
                Product_Image    = ImageData
            };

            List <BOMVO> citemList = new List <BOMVO>();

            foreach (Control control in splitContainer2.Panel1.Controls)
            {
                if (control is SemiProductCompControl)
                {
                    SemiProductCompControl spc = (SemiProductCompControl)control;

                    BOMVO citem = new BOMVO
                    {
                        Combination_Product_ID  = spc.TxtName.Tag.ToString(),
                        Combination_RequiredQty = Convert.ToInt32(spc.Qty.Value)
                    };

                    count += spc.Controls.Count;
                    citemList.Add(citem);
                }
            }

            try
            {
                BOMService service = new BOMService();
                service.InsertProduct(Pitem, citemList, count);
            }
            catch (Exception err)
            {
                Log.WriteError(err.Message, err);
            }
        }
        //반제품의 카테고리를 선택하면 유저컨트롤을 반제품의 카테고리에 속해있는 원자재 카테고리 수 만큼 생성하고 라벨 이름을 원자재 카테고리명으로 바꾼다.
        private void CategoryLabelName(List <ComboItemVO> countList)
        {
            for (int i = 1; i < countList.Count; i++)
            {
                spc              = new SemiProductCompControl();
                spc.Location     = new Point(0, i * 40);
                spc.LblName.Text = countList[i].Name;
                spc.LblName.Tag  = countList[i].ID;

                spc.Qty.ValueChanged += new EventHandler(TotalPrice);

                splitContainer2.Panel1.Controls.Add(spc);
            }
        }
        //원자재를 선택하면 해당하는 원자재 카테고리 ID와 유저컨트롤 태그 ID를 비교해서 맞는 부분에 원자재 이름과 가격을 설정한다.
        private void dgvSemiProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && dgvSemiProduct.SelectedRows.Count > 0)
            {
                foreach (Control control in splitContainer2.Panel1.Controls)
                {
                    if (control is SemiProductCompControl)
                    {
                        SemiProductCompControl spc = (SemiProductCompControl)control;

                        //데이터그리드뷰에서 선택한 원자재 카테고리와 사용자 컨트롤 원자재 카테고리가 같을 때
                        if (spc.LblName.Tag.ToString() == dgvSemiProduct.SelectedRows[0].Cells[2].Value.ToString())
                        {
                            //사용자컨트롤에 아무정보가 없을 때
                            if (spc.TxtName.Tag == null)
                            {
                                spc.TxtName.Text  = dgvSemiProduct.SelectedRows[0].Cells[0].Value.ToString();                               //제품이름
                                spc.TxtName.Tag   = dgvSemiProduct.SelectedRows[0].Cells[3].Value;                                          //제품ID
                                spc.LblMoney.Text = Convert.ToInt32(dgvSemiProduct.SelectedRows[0].Cells[1].Value).ToString("#,##0") + "원"; //제품가격
                                spc.LblMoney.Tag  = 1;
                                spc.Qty.Tag       = dgvSemiProduct.SelectedRows[0].Cells[1].Value;                                          //제품가격
                                spc.Qty.Value    += 1;
                            }
                            //사용자컨트롤에 정보가 있을 때
                            else
                            {
                                //데이터그리드뷰에서 선택한 원자재 ID와 사용자컨트롤에 있는 원자재의 ID가 같을 때
                                if (spc.TxtName.Tag.ToString() == dgvSemiProduct.SelectedRows[0].Cells[3].Value.ToString())
                                {
                                    spc.Qty.Value += 1;
                                }
                                else
                                {
                                    spc.TxtName.Text  = dgvSemiProduct.SelectedRows[0].Cells[0].Value.ToString();                               //제품이름
                                    spc.TxtName.Tag   = dgvSemiProduct.SelectedRows[0].Cells[3].Value;                                          //제품ID
                                    spc.LblMoney.Text = Convert.ToInt32(dgvSemiProduct.SelectedRows[0].Cells[1].Value).ToString("#,##0") + "원"; //제품가격
                                    spc.LblMoney.Tag  = 2;
                                    spc.Qty.Tag       = dgvSemiProduct.SelectedRows[0].Cells[1].Value;                                          //제품가격
                                    spc.Qty.Value     = 0;
                                    spc.Qty.Value    += 1;
                                }
                            }
                        }
                    }
                }
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            bool check = true;

            foreach (Control control in splitContainer2.Panel1.Controls)
            {
                if (control is SemiProductCompControl)
                {
                    SemiProductCompControl spc = (SemiProductCompControl)control;

                    if (spc.TxtName.Tag == null)
                    {
                        check = false;
                    }
                }
            }

            if (Convert.ToInt32(txtSemiproductMoney.Text.Replace(",", "").Replace("원", "")) > 0)
            {
                if (cboCategory.SelectedValue != null && check && cboWarehouse.SelectedValue != null && txtSemiproductName.Text.Length > 0 && numSafety.Value > 0 && txtSemiproductMoney.Text.Length > 0)
                {
                    if (mode.Equals("Insert"))
                    {
                        InsertSemiProduct();
                        DialogResult = MessageBox.Show(Resources.AddDone, Resources.AddDone, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        UpdateSemiProduct();
                        DialogResult = MessageBox.Show(Resources.ModDone, Resources.ModDone, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show(Resources.isEssential, Resources.MsgBoxTitleWarn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show(Resources.isEssential, Resources.MsgBoxTitleWarn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        //원자재의 개수를 수정하면 하단에 있는 단가를 수정한다.
        private void TotalPrice(object sender, EventArgs e)
        {
            int sum = 0;

            foreach (Control control in splitContainer2.Panel1.Controls)
            {
                if (control is SemiProductCompControl)
                {
                    SemiProductCompControl spc = (SemiProductCompControl)control;

                    if (!string.IsNullOrEmpty(spc.LblMoney.Text))
                    {
                        sum += Convert.ToInt32(list.Find(i => i.Product_ID == spc.TxtName.Tag.ToString()).Product_Price *spc.Qty.Value);
                    }

                    txtSemiproductMoney.Tag  = sum;
                    txtSemiproductMoney.Text = Convert.ToInt32(txtSemiproductMoney.Tag).ToString("#,##0") + "원";
                }
            }
        }
        //Product 테이블과 Combination 테이블 수정
        private void UpdateSemiProduct()
        {
            ProductVO Pitem = new ProductVO
            {
                Product_ID       = pCode,
                Product_Name     = txtSemiproductName.Text,
                Product_Price    = Convert.ToInt32(txtSemiproductMoney.Text.Replace(",", "").Replace("원", "")),
                Product_Safety   = Convert.ToInt32(numSafety.Value),
                Warehouse_ID     = Convert.ToInt32(cboWarehouse.SelectedValue),
                Product_Category = cboCategory.SelectedValue.ToString()
            };

            List <BOMVO> citemList = new List <BOMVO>();

            foreach (Control control in splitContainer2.Panel1.Controls)
            {
                if (control is SemiProductCompControl)
                {
                    SemiProductCompControl spc = (SemiProductCompControl)control;

                    BOMVO citem = new BOMVO
                    {
                        Combination_Product_ID  = spc.TxtName.Tag.ToString(),
                        Combination_RequiredQty = Convert.ToInt32(spc.Qty.Value)
                    };

                    citemList.Add(citem);
                }
            }

            try
            {
                BOMService service = new BOMService();
                service.UpdateSemiProduct(Pitem, citemList, splitContainer2.Panel1.Controls.Count);
            }
            catch (Exception err)
            {
                Log.WriteError(err.Message, err);
            }
        }