private void btnTimKho_Click(object sender, EventArgs e) { try { list.Add(0); int slCanChuyen = int.Parse(gridSPCanChuyen.CurrentRow.Cells[4].Value.ToString()); int idsp = int.Parse(gridSPCanChuyen.CurrentRow.Cells[0].Value.ToString()); string Ten = gridSPCanChuyen.CurrentRow.Cells[1].Value.ToString(); int idkho = ycch.ID_KHO; List <float> slt = new List <float>(); List <float> slx_tb = new List <float>(); List <ThongTin> dsTT = mode.getTT(idkho, idsp, slCanChuyen, slx_tb, slt); List <float> slt_da_chuanhoa = new List <float>(); List <float> slx_tb_da_chuanhoa = new List <float>(); List <float> Khoangcach_chuanhoa = new List <float>(); mode.chuanhoa(slt, slt_da_chuanhoa); mode.chuanhoa(slx_tb, slx_tb_da_chuanhoa); mode.chuanhoa(list, Khoangcach_chuanhoa); float slchuyen = slt_da_chuanhoa[slt_da_chuanhoa.Count - 1]; float slx = slx_tb_da_chuanhoa[slx_tb_da_chuanhoa.Count - 1]; int tong = 0; int tongcanchuyen = 0; for (int i = 0; i < dsTT.Count; i++) { dsTT[i].Soluongton = slt_da_chuanhoa[i]; dsTT[i].Slx_tb = slx_tb_da_chuanhoa[i]; dsTT[i].Khoangcach = Khoangcach_chuanhoa[i]; } List <float> KQ = mode.tinhkhoangcach(dsTT, slchuyen, slx); for (int i = 0; i < dsTT.Count; i++) { dsTT[i].Kq = KQ[i]; } mode.sapXepTang(dsTT); List <ThongTin> dsThoaDK = new List <ThongTin>(); foreach (ThongTin item in dsTT) { if (tong >= slCanChuyen) { break; } else { int sl = tonkho.get_SL(item.Idkho, idsp); item.Soluongton = sl; tong += (int)item.Soluongton; dsThoaDK.Add(item); } } if (tong < slCanChuyen) { //MessageBox.Show("khong du hang de chuyen"); this.Alert("Không đủ hàng để chuyển!", frmNotificationCustom.enmType.Warning); return; } foreach (ThongTin item in dsThoaDK) { if (tongcanchuyen + item.Soluongton < slCanChuyen) { gridCTCH.Rows.Add(idsp, Ten, item.Idkho, item.Soluongton); tongcanchuyen += (int)item.Soluongton; } else { gridCTCH.Rows.Add(idsp, Ten, item.Idkho, slCanChuyen - tongcanchuyen); } } gridSPCanChuyen.Rows.Remove(gridSPCanChuyen.CurrentRow); btnTimKho.Enabled = false; if (gridSPCanChuyen.Rows.Count == 0) { btnxacnhan.Enabled = true; } } catch { this.Alert("Vui lòng chọn!", frmNotificationCustom.enmType.Warning); } }