예제 #1
0
        private void Dgv발주리스트_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;

            int maxRow   = dgv.RowCount;
            int maxColum = dgv.ColumnCount;

            if (e.ColumnIndex == 0)
            {
                if ((DB.자재.Get자재번호(dgv[0, e.RowIndex].Value.ToString()).Count == 0))
                {
                    MessageBox.Show("등록되지 않은 자재입니다");
                    return;
                }
            }

            if (e.ColumnIndex == 1)
            {
                if (dgv[e.ColumnIndex, e.RowIndex].Value != null)
                {
                    string 자재번호 = DB.자재.Get자재번호(dgv.CurrentRow.Cells[0].Value.ToString()).Select(x => x.자재번호).First().ToString();
                    var    list
                        = DB.발주리스트.Search발주리스트(자재번호, dgv발주서.CurrentRow.Cells[0].Value.ToString());

                    if (list.Count == 0)
                    {
                        발주리스트 발주리스트 = new 발주리스트();
                        발주리스트.발주번호 = dgv발주서.CurrentRow.Cells[0].Value.ToString();
                        발주리스트.자재번호 = dgv[0, e.RowIndex].Value.ToString();
                        발주리스트.수량   = int.Parse(dgv[1, e.RowIndex].Value.ToString());

                        DB.발주리스트.Insert(발주리스트);
                        MessageBox.Show("발주리스트");
                    }

                    else
                    {
                        if (list.First().수량 != int.Parse(dgv.CurrentRow.Cells[1].Value.ToString()))
                        {
                            list.First().수량 = int.Parse(dgv.CurrentRow.Cells[1].Value.ToString());
                            DB.발주리스트.Update(list.First());
                            MessageBox.Show("수량변경");
                        }
                    }
                }
            }
        }
예제 #2
0
        void Register발주()
        {
            var Last수주 = DB.수주.Search수주(dgv엑셀.CurrentRow.Cells[0].Value.ToString(), dgv엑셀.CurrentRow.Cells[1].Value.ToString()).FirstOrDefault(); //최근에 등록된 수주
            var 자재명세서  = DB.자재명세서.Get자재명세서(Last수주.제품번호);                                                                                          //등록된 수주의 자재명세서
            var 자재     = DB.자재.GetAll(Last수주.제품번호);

            var   제품     = DB.제품.Get제품(Last수주.제품번호);
            var   Last제품 = 제품[제품.Count - 1]; //수주받은 제품에 대한 정보
            var   수량     = new List <int>();
            발주리스트 발주리스트  = new 발주리스트();
            var   list   = new List <발주서>();
            var   자재List = new List <string>();

            //만들어야할 제품의 갯수
            Last제품.재고량 = (int)Last제품.재고량 - Last수주.주문수량 - (int)Last제품.안전재고량;

            for (int i = 0; i < 자재명세서.Count; i++)
            {
                for (int j = 0; j < 자재.Count; j++)
                {
                    if (자재명세서[i].자재번호 == 자재[j].자재번호)
                    {
                        if (Last제품.재고량 < 0)
                        {
                            자재[j].재고량 = 자재[j].재고량 + 자재명세서[i].수량 * (int)Last제품.재고량; //재공
                            if (자재[j].재고량 < 0)
                            {
                                int preStockAmount = 자재[j].재고량;
                                자재[j].재고량 = 0;
                                DB.자재.Update(자재[j]);
                                자재[j].재고량 = preStockAmount;
                            }
                            else
                            {
                                DB.자재.Update(자재[j]);
                            }

                            자재[j].재고량 -= 자재[j].안전재고량;
                        }

                        if (자재[j].재고량 < 0)
                        {
                            발주서 발주서 = new 발주서();

                            if (DB.발주서.Search발주서(DateTime.Today).Count == 0)
                            {
                                발주서.발주번호 = DateTime.Today.ToShortDateString().ToString().Replace("-", "").Substring(2, 6) + "001";
                            }

                            else
                            {
                                발주서.발주번호 = (int.Parse(DB.발주서.GetAll().Select(x => x.발주번호).LastOrDefault()) + 1).ToString();
                            }
                            발주서.공급업체번호 = DB.공급자재리스트.Get공급업체번호(자재명세서[i].자재번호);
                            발주서.주문날짜   = DateTime.Today;
                            발주서.납기일    = Last수주.납기일.AddDays(-Last제품.리드타임 - 자재[j].리드타임);

                            list.Add(발주서);
                            수량.Add(자재[j].재고량);
                            자재List.Add(자재[j].자재번호);
                        }
                    }
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[i].공급업체번호 == list[j].공급업체번호)
                    {
                        list[i].발주번호 = list[j].발주번호;
                        if (list[i].납기일 <= list[j].납기일)
                        {
                            list[i].납기일 = list[j].납기일;
                        }
                        else
                        {
                            list[j].납기일 = list[i].납기일;
                        }
                        break;
                    }
                }
                if (DB.발주서.Is발주번호(list[i].발주번호).Count == 0)
                {
                    DB.발주서.Insert(list[i]);
                    발주리스트.발주번호 = list[i].발주번호;
                    발주리스트.자재번호 = 자재List[i];
                    발주리스트.수량   = 수량[i] * (-1);
                    DB.발주리스트.Insert(발주리스트);
                    for (int j = i + 1; j < list.Count; j++)
                    {
                        list[j].발주번호 = (int.Parse(DB.발주서.GetAll().Select(x => x.발주번호).LastOrDefault()) + 1).ToString();
                    }
                }
                else
                {
                    발주리스트.발주번호 = list[i].발주번호;
                    발주리스트.자재번호 = 자재List[i];
                    발주리스트.수량   = 수량[i] * (-1);
                    DB.발주리스트.Insert(발주리스트);
                }
            }
        }