Example #1
0
        private void Dgv발주서_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;

            dgv.CurrentRow.Cells[0].ReadOnly = true;
            dgv.CurrentRow.Cells[2].ReadOnly = true;
            int maxRow   = dgv.RowCount;
            int maxColum = dgv.ColumnCount;

            if (e.ColumnIndex == 1)
            {
                dgv[0, e.RowIndex].Value = (DB.발주서.GetCount() + 2).ToString();
                dgv[2, e.RowIndex].Value = DateTime.Today.ToShortDateString();
                if (DB.일반거래처.Get공급업체번호From이름(dgv[1, e.RowIndex].Value.ToString()).Count == 0)
                {
                    MessageBox.Show("등록되지않은 공급업체입니다.");
                    return;
                }
            }

            if (e.ColumnIndex == 3)
            {
                if (dgv[e.ColumnIndex, e.RowIndex].Value != null)
                {
                    발주서 발주서 = new 발주서();
                    발주서.발주번호   = dgv[0, e.RowIndex].Value.ToString();
                    발주서.공급업체번호 = DB.일반거래처.Get공급업체번호From이름(dgv[1, e.RowIndex].Value.ToString()).Select(x => x.거래처코드번호).First().ToString();
                    발주서.주문날짜   = DateTime.Today;
                    발주서.납기일    = DateTime.Parse(dgv.CurrentRow.Cells[3].Value.ToString());//해결하기

                    DB.발주서.Insert(발주서);
                    MessageBox.Show("발주서등록");
                    dgv발주리스트.Rows.Add();
                    dgv발주리스트.Focus();
                    dgv발주리스트.CurrentCell = dgv발주리스트[0, 0];
                }
            }
        }
Example #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(발주리스트);
                }
            }
        }