Example #1
0
        private void gridViewQLNhapKho_DoubleClick(object sender, EventArgs e)
        {
            int     RowIndex    = gridViewQLNhapKho.FocusedRowHandle;
            string  stockincode = gridViewQLNhapKho.GetRowCellValue(RowIndex, "StockInCode").ToString();
            StockIn si          = dc.StockIns.Where(x => x.StockInCode == stockincode).SingleOrDefault();
            //goi su kien click form(show form) => biding du lieu ra form
            //binding du lieu phien
            NhapKho nhapkho = new NhapKho();

            nhapkho.Show();
            nhapkho.txtMaPN.Text           = stockincode;
            nhapkho.datePN.EditValue       = si.DateIn;
            nhapkho.txtMaNV.Text           = si.EmployeeCode;
            nhapkho.txtUser.Text           = si.UserID;
            nhapkho.txtGhiChuPhien.Text    = si.Note;
            nhapkho.txtTongTrongLuong.Text = si.TotalWeight.ToString();
            nhapkho.txtSoLuong.Text        = si.Quantity.ToString();
            //binding du lieu luoi
            var model = (from sid in dc.StockInDetails
                         join bar in dc.BarcodeDetails on sid.Barcode equals bar.Barcode
                         where (sid.StockInCode == stockincode)
                         select new
            {
                bar.Barcode,
                bar.WasteCode,
                bar.FactoryCode,
                bar.StorageCode,
                bar.Weigh,
                bar.Note,
            }).ToList();
            //tao moi datatable va datarow
            DataTable datatable = new DataTable();
            DataRow   datarow;

            //addcolum
            datatable.Columns.Add("Barcode");
            datatable.Columns.Add("TrongLuong");
            datatable.Columns.Add("Xuong");
            datatable.Columns.Add("Kho");
            datatable.Columns.Add("TenRac");
            datatable.Columns.Add("GhiChu");
            datatable.Columns.Add("DonVi");
            foreach (var item1 in model)
            {
                datarow               = datatable.NewRow();
                datarow["Barcode"]    = item1.Barcode;
                datarow["TrongLuong"] = item1.Weigh;
                datarow["Xuong"]      = item1.FactoryCode;
                datarow["Kho"]        = item1.StorageCode;
                datarow["TenRac"]     = item1.WasteCode;
                datarow["GhiChu"]     = item1.Note;
                Waste var = (from c in dc.Wastes
                             where c.WasteCode == item1.WasteCode
                             select c).FirstOrDefault();
                datarow["DonVi"] = var.Unit;
                datatable.Rows.Add(datarow);
            }
            nhapkho.gridControlBarcode.DataSource = datatable;
        }
Example #2
0
        private void gridViewBaoCao_DoubleClick(object sender, EventArgs e)
        {
            //lay dc stockincode hoac stockout code
            int    RowIndex = gridViewBaoCao.FocusedRowHandle;
            string stockoutcode;
            string stockincode;

            try
            {
                stockincode = gridViewBaoCao.GetRowCellValue(RowIndex, "StockInCode").ToString();
            }
            catch (Exception ex)
            {
                stockincode = "";
            }

            try
            {
                stockoutcode = gridViewBaoCao.GetRowCellValue(RowIndex, "StockOutCode").ToString();
            }
            catch (Exception ex)
            {
                stockoutcode = "";
            }
            //tim ma lay duoc trong hai bang stockin va stock out
            if (stockincode != "" && stockoutcode == "")
            {
                //truong hop lay duoc ma nhap kho
                StockIn si      = dc.StockIns.Where(x => x.StockInCode == stockincode).SingleOrDefault();
                NhapKho nhapkho = new NhapKho();
                nhapkho.Show();
                nhapkho.txtMaPN.Text           = stockincode;
                nhapkho.datePN.EditValue       = si.DateIn;
                nhapkho.txtMaNV.Text           = si.EmployeeCode;
                nhapkho.txtUser.Text           = si.UserID;
                nhapkho.txtGhiChuPhien.Text    = si.Note;
                nhapkho.txtTongTrongLuong.Text = si.TotalWeight.ToString();
                nhapkho.txtSoLuong.Text        = si.Quantity.ToString();

                //binding du lieu luoi
                var model = (from sid in dc.StockInDetails
                             join bar in dc.BarcodeDetails on sid.Barcode equals bar.Barcode
                             where (sid.StockInCode == stockincode)
                             select new
                {
                    bar.Barcode,
                    bar.WasteCode,
                    bar.FactoryCode,
                    bar.StorageCode,
                    bar.Weigh,
                    bar.Note,
                }).ToList();
                //tao moi datatable va datarow
                DataTable datat = new DataTable();
                DataRow   datar;
                //addcolum
                datat.Columns.Add("Barcode");
                datat.Columns.Add("TrongLuong");
                datat.Columns.Add("Xuong");
                datat.Columns.Add("Kho");
                datat.Columns.Add("TenRac");
                datat.Columns.Add("GhiChu");
                datat.Columns.Add("DonVi");
                foreach (var item1 in model)
                {
                    datar               = datat.NewRow();
                    datar["Barcode"]    = item1.Barcode;
                    datar["TrongLuong"] = item1.Weigh;
                    datar["Xuong"]      = item1.FactoryCode;
                    datar["Kho"]        = item1.StorageCode;
                    datar["TenRac"]     = item1.WasteCode;
                    datar["GhiChu"]     = item1.Note;
                    Waste var = (from c in dc.Wastes
                                 where c.WasteCode == item1.WasteCode
                                 select c).FirstOrDefault();
                    datar["DonVi"] = var.Unit;
                    datat.Rows.Add(datar);
                }
                nhapkho.gridControlBarcode.DataSource = datat;
            }
            if (stockincode == "" && stockoutcode != "")
            {
                StockOut so      = dc.StockOuts.Where(x => x.StockOutCode == stockoutcode).SingleOrDefault();
                XuatKho  xuatkho = new XuatKho();
                xuatkho.Show();
                xuatkho.txtMaPX.Text           = stockoutcode;
                xuatkho.dateNgayPX.EditValue   = so.DateOut;
                xuatkho.txtUser.Text           = so.UserID;
                xuatkho.txtTenNguoiNhan.Text   = so.RecipientName;
                xuatkho.txtCMND.Text           = so.IDCard;
                xuatkho.txtCongTy.Text         = so.Company;
                xuatkho.txtTongTrongLuong.Text = so.TotalWeight.ToString();
                xuatkho.txtSoLuong.Text        = so.Quantity.ToString();
                //binding du lieu luoi
                var model = (from sod in dc.StockOutDetails
                             join bar in dc.BarcodeDetails on sod.Barcode equals bar.Barcode
                             join w in dc.Wastes on bar.WasteCode equals w.WasteCode
                             where (sod.StockOutCode == stockoutcode)
                             select new
                {
                    sod.Barcode,
                    w.WasteName,
                    w.Type,
                    bar.Weigh,
                    w.Unit,
                    bar.Note
                }).ToList();
                //tao moi datatable va datarow
                DataTable datat1 = new DataTable();
                DataRow   datar1;
                //addcolum
                datat1.Columns.Add("Barcode");
                datat1.Columns.Add("WasteName");
                datat1.Columns.Add("Type");
                datat1.Columns.Add("Weigh");
                datat1.Columns.Add("Unit");
                datat1.Columns.Add("Note");
                foreach (var item1 in model)
                {
                    datar1              = datat1.NewRow();
                    datar1["Barcode"]   = item1.Barcode;
                    datar1["WasteName"] = item1.WasteName;
                    datar1["Type"]      = item1.Type;
                    datar1["Weigh"]     = item1.Weigh;
                    datar1["Unit"]      = item1.Unit;
                    datar1["Note"]      = item1.Note;
                    //Waste var = (from c in dc.Wastes
                    //             where c.WasteCode == item1.WasteCode
                    //             select c).FirstOrDefault();
                    //datarow["DonVi"] = var.Unit;
                    datat1.Rows.Add(datar1);
                }
                xuatkho.gridControlBarcode.DataSource = datat1;
            }
        }