Пример #1
0
 void LoadOrderDetails()
 {
     Class.clsListOrder cls = new Class.clsListOrder();
     cls.OrderCode = "";
     dtOrderDetail = cls.tbOrderDetails_GetByCode();
     gridItem.DataSource = dtOrderDetail;
     dtOrderDetail.Clear();
 }
Пример #2
0
 void LoadOrderDetails(string Ordercode)
 {
     Class.clsListOrder cls = new Class.clsListOrder();
     cls.OrderCode = Ordercode;
     dtOrderDetail = cls.tbOrderDetails_GetByCode();
     gridItem.DataSource = dtOrderDetail;
     cls.OrderCode = "";
     dtOrderDetailTemp = cls.tbOrderDetails_GetByCode();
 }
Пример #3
0
        //xuat du lieu tu grid ra table file excel
        private void btnExportFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridItemDetail.SelectedRowsCount > 0)
                {
                    int[] selectedRows = gridItemDetail.GetSelectedRows();

                    object[] result = new object[selectedRows.Length];
                    DataTable dt = new DataTable();
                    dt.Columns.Add("SoHD");
                    dt.Columns.Add("NgayDN");
                    dt.Columns.Add("NhaCC");
                    dt.Columns.Add("MoTa");
                    dt.Columns.Add("SoLuong");
                    dt.Columns.Add("DonVi");
                    dt.Columns.Add("Gia");
                    dt.Columns.Add("ThanhTien");
                    dt.Columns.Add("VAT");

                    for (int i = 0; i < selectedRows.Length; i++)
                    {
                        int rowHandle = selectedRows[i];
                        if (!gridItemDetail.IsGroupRow(rowHandle))
                        {
                            result[i] = gridItemDetail.GetRowCellValue(rowHandle, colOrderCode);
                            DataRow dr = dt.NewRow();
                            dr["SoHD"] = gridItemDetail.GetRowCellValue(rowHandle, colOrderCode);
                            dr["NgayDN"] = "'" + ((DateTime)gridItemDetail.GetRowCellValue(rowHandle, colDateSuggest)).ToString("dd/MM/yyyy");
                            dr["NhaCC"] = gridItemDetail.GetRowCellValue(rowHandle, colSupplierName);
                            Class.clsListOrder cls = new Class.clsListOrder();
                            //xu ly in cac chi tiet hoa don tu vi tri tren luoi dua vao ordercode
                            string code = gridItemDetail.GetRowCellValue(rowHandle, colOrderCode).ToString();
                            cls.OrderCode = code;
                            DataTable dtct = cls.tbOrderDetails_GetByCode();

                            if (dtct.Rows.Count > 0)
                            {
                                dr["MoTa"] = dtct.Rows[0]["Describe"].ToString();
                                dr["SoLuong"] = dtct.Rows[0]["Number"].ToString();
                                dr["DonVi"] = dtct.Rows[0]["Unit"].ToString();
                                dr["Gia"] = dtct.Rows[0]["Price"].ToString();
                                dr["ThanhTien"] = dtct.Rows[0]["Monetize"].ToString();
                            }
                            dr["VAT"] = gridItemDetail.GetRowCellValue(rowHandle, colVAT);
                            dt.Rows.Add(dr);
                            int soct = dtct.Rows.Count;
                            if (soct > 1)
                            {
                                for (int ii = 1; ii < soct; ii++)
                                {
                                    DataRow dr1 = dt.NewRow();
                                    dr1["MoTa"] = dtct.Rows[ii]["Describe"].ToString();
                                    dr1["SoLuong"] = dtct.Rows[ii]["Number"].ToString();
                                    dr1["DonVi"] = dtct.Rows[ii]["Unit"].ToString();
                                    dr1["Gia"] = dtct.Rows[ii]["Price"].ToString();
                                    dr1["ThanhTien"] = dtct.Rows[ii]["Monetize"].ToString();
                                    dt.Rows.Add(dr1);
                                }
                            }
                        }
                    }

                    // xuat excel
                    SaveFileDialog saveFile = new SaveFileDialog();
                    saveFile.Filter = "Excel File|*.xls";
                    saveFile.Title = "Exprot to Excel File";
                    saveFile.ShowDialog();
                    if (saveFile.FileName != "")
                    {
                        Excel.Application xlApp;

                        Excel.Workbook xlWorkBook;

                        Excel.Worksheet xlWorkSheet;

                        object misValue = System.Reflection.Missing.Value;

                        xlApp = new Excel.Application();

                        xlWorkBook = xlApp.Workbooks.Add(misValue);

                        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                        xlWorkSheet.Cells[1, 1] = "Số HĐ";
                        xlWorkSheet.Cells[1, 2] = "Ngày đề nghị";
                        xlWorkSheet.Cells[1, 3] = "Nhà Cung cấp";
                        xlWorkSheet.Cells[1, 4] = "Mô tả";
                        xlWorkSheet.Cells[1, 5] = "Số lượng";
                        xlWorkSheet.Cells[1, 6] = "Đơn vị tính";
                        xlWorkSheet.Cells[1, 7] = "Đơn Giá";
                        xlWorkSheet.Cells[1, 8] = "Thành tiền";
                        xlWorkSheet.Cells[1, 9] = "VAT";

                        object[,] Array_Record;
                        Array_Record = new object[dt.Rows.Count, dt.Columns.Count];
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            for (int j = 0; j < dt.Columns.Count; j++)
                            {
                                Array_Record[i, j] = dt.Rows[i][j].ToString();
                            }
                        }
                        xlWorkSheet.get_Range("A2", "I" + (dt.Rows.Count + 1)).Value = Array_Record;

                        xlWorkBook.SaveAs(saveFile.FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

                        xlWorkBook.Close(true, misValue, misValue);

                        xlApp.Quit();

                        releaseObject(xlWorkSheet);
                        releaseObject(xlWorkBook);
                        releaseObject(xlApp);
                        MessageBox.Show("Xuất file thành công !..");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi " + ex.ToString());
            }
        }