예제 #1
0
        public string QueryUpdate(Inputcoupon inputcoupon)
        {
            string query = "";
            string ID_InputCoupon; try { ID_InputCoupon = inputcoupon.ID_InputCoupon.ToString().Trim(); } catch { ID_InputCoupon = ""; }

            string CreateDate; try { CreateDate = inputcoupon.CreateDate.ToShortDateString().Trim(); } catch { CreateDate = ""; }
            string ID_Supplier; try { ID_Supplier = inputcoupon.ID_Supplier.ToString().Trim(); } catch { ID_Supplier = ""; }
            string TotalMoney; try { TotalMoney = inputcoupon.TotalMoney.ToString().Trim(); } catch { TotalMoney = ""; }

            if (ID_InputCoupon == "")
            {
                return(query);
            }

            if (CreateDate == "")
            {
                CreateDate = "null";
            }
            if (ID_Supplier == "")
            {
                ID_Supplier = "null";
            }
            if (TotalMoney == "")
            {
                TotalMoney = "0";
            }

            query = "EXEC UpdateINPUTCOUPON " + ID_InputCoupon + ", " + CreateDate + ", " + ID_Supplier + ", " + TotalMoney;

            return(query);
        }
예제 #2
0
        public DataTable Search(Inputcoupon inputcoupon)
        {
            DataTable dt = new DataTable();

            try
            {
                string query = this.QuerySearch(inputcoupon);
                ds.Clear();
                if (query == "")
                {
                    return(this.Load());
                }
                else
                {
                    adapter.SelectCommand = new SqlCommand(query, connection);
                    cb = new SqlCommandBuilder(adapter);
                    adapter.Fill(ds, "INPUTCOUPON");
                    dt = ds.Tables["INPUTCOUPON"];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                connection.Close();
            }
            return(dt);
        }
 public void Insert(Inputcoupon inputcoupon)
 {
     try
     {
         string query = QueryInsert(inputcoupon);
         ExecuteNonQuery(query);
         MessageBox.Show("Thêm thành công", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception)
     {
         MessageBox.Show("Thêm thất bại", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        private void btn_Submit_Click(object sender, EventArgs e)
        {
            Inputcoupon pn = new Inputcoupon();

            pn.CreateDate  = dateTimePicker1.Value;
            pn.ID_Supplier = int.Parse(textBoxMaNCC.Text);
            pn.TotalMoney  = decimal.Parse(textBoxTongTien.Text);
            ctr1.Insert(pn);

            maNCC    = textBoxMaNCC.Text;
            tongtien = textBoxTongTien.Text;
            ngaylap  = dateTimePicker1.Value.Date;

            Close();
        }
예제 #5
0
 public void Insert(Inputcoupon inputcoupon)
 {
     using (var command = new SqlCommand {
         Connection = connection
     })
     {
         connection.Open();
         command.CommandText = QueryInsert(inputcoupon);
         var count = command.ExecuteNonQuery();
         if (count > 0)
         {
             MessageBox.Show("cập nhật thành công", "thông báo", MessageBoxButtons.OK);
         }
         connection.Close();
     }
 }
예제 #6
0
        private string QuerySearch(Inputcoupon inputcoupon)
        {
            string sqlSelect = "";

            string ID_InputCoupon; try { ID_InputCoupon = inputcoupon.ID_InputCoupon.ToString().Trim(); } catch { ID_InputCoupon = ""; }
            string search_StartCreateDate; try { search_StartCreateDate = inputcoupon.Search_StartCreateDate.ToShortDateString().Trim(); } catch { search_StartCreateDate = ""; }
            string search_EndCreateDate; try { search_EndCreateDate = inputcoupon.Search_EndCreateDate.ToShortDateString().Trim(); } catch { search_EndCreateDate = ""; }
            string ID_Supplier; try { ID_Supplier = inputcoupon.ID_Supplier.ToString().Trim(); } catch { ID_Supplier = ""; }
            string search_MinTotalMoney; try { search_MinTotalMoney = inputcoupon.Search_MinTotalMoney.ToString().Trim(); } catch { search_MinTotalMoney = ""; }
            string search_MaxTotalMoney; try { search_MaxTotalMoney = inputcoupon.Search_MaxTotalMoney.ToString().Trim(); } catch { search_MaxTotalMoney = ""; }

            if (ID_InputCoupon != "")
            {
                sqlSelect = sqlSelect + " and ID_InputCoupon like '%" + ID_InputCoupon + "%'";
            }
            if (search_StartCreateDate != "")
            {
                sqlSelect = sqlSelect + " and CreateDate >=  '" + search_StartCreateDate + "'";
            }
            if (search_EndCreateDate != "")
            {
                sqlSelect = sqlSelect + " and CreateDate <=  '" + search_EndCreateDate + "'";
            }
            if (ID_Supplier != "")
            {
                sqlSelect = sqlSelect + " and ID_Supplier like '%" + ID_Supplier + "%'";
            }
            if (search_MinTotalMoney != "")
            {
                sqlSelect = sqlSelect + " and TotalMoney >= " + search_MinTotalMoney;
            }
            if (search_MaxTotalMoney != "")
            {
                sqlSelect = sqlSelect + " and TotalMoney <= " + search_MaxTotalMoney;
            }

            string query = "";

            if (sqlSelect != "")
            {
                sqlSelect = sqlSelect.Remove(0, 4); // xoa chu " and" dau tien
                sqlSelect = " WHERE" + sqlSelect;
                query     = "SELECT* FROM DBO.INPUTCOUPON" + sqlSelect;
            }
            return(query);
        }
 // update 1 Inputcoupon row
 public void Update(Inputcoupon inputcoupon)
 {
     try
     {
         string query = QueryUpdate(inputcoupon);
         if (query == "")
         {
             MessageBox.Show("1 số trường không được bỏ trống", "Lỗi", MessageBoxButtons.OK);
             return;
         }
         ExecuteNonQuery(query);
         MessageBox.Show("Sửa thành công", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception)
     {
         MessageBox.Show("Sửa thất bại", "Thông Báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
예제 #8
0
        // update 1 Inputcoupon row
        public void Update(Inputcoupon inputcoupon)
        {
            string query = QueryUpdate(inputcoupon);

            if (query == "")
            {
                MessageBox.Show("1 số trường không được bỏ trống", "Lỗi", MessageBoxButtons.OK);
                return;
            }
            using (var command = new SqlCommand {
                Connection = connection
            })
            {
                connection.Open();
                command.CommandText = query;
                var count = command.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("cập nhật thành công", "thông báo", MessageBoxButtons.OK);
                }
                connection.Close();
            }
        }
예제 #9
0
        private string QueryInsert(Inputcoupon inputcoupon)
        {
            string query = "";

            string CreateDate; try { CreateDate = inputcoupon.CreateDate.ToShortDateString().Trim(); } catch { CreateDate = ""; }
            string ID_Supplier; try { ID_Supplier = inputcoupon.ID_Supplier.ToString().Trim(); } catch { ID_Supplier = ""; }
            string TotalMoney; try { TotalMoney = inputcoupon.TotalMoney.ToString().Trim(); } catch { TotalMoney = ""; }

            if (CreateDate == "")
            {
                CreateDate = "null";
            }
            if (ID_Supplier == "")
            {
                ID_Supplier = "null";
            }
            if (TotalMoney == "")
            {
                TotalMoney = "0";
            }
            query = "INSERT DBO.INPUTCOUPON(CreateDate, ID_Supplier, TotalMoney) VALUES ( " + CreateDate + ", " + ID_Supplier + ", " + TotalMoney + ")";
            return(query);
        }
        private string QueryInsert(Inputcoupon inputcoupon)
        {
            string query = "";

            string CreateDate; try { CreateDate = inputcoupon.CreateDate.ToShortDateString().Trim(); } catch { CreateDate = ""; }
            string ID_Supplier; try { ID_Supplier = inputcoupon.ID_Supplier.ToString().Trim(); } catch { ID_Supplier = ""; }
            string TotalMoney; try { TotalMoney = inputcoupon.TotalMoney.ToString().Trim(); } catch { TotalMoney = ""; }

            if (CreateDate == "")
            {
                CreateDate = "null";
            }
            if (ID_Supplier == "")
            {
                ID_Supplier = "null";
            }
            if (TotalMoney == "")
            {
                TotalMoney = "0";
            }
            query = $"EXEC InsertINPUTCOUPON '{CreateDate}' , {ID_Supplier} , {TotalMoney}";
            return(query);
        }
        /// <summary>
        /// ////////////////////////////////////////TRUONGGGGGGGGGGGGGGGGGGG
        /// </summary>

        public void ExportInputCoupon(Inputcoupon inputcoupon, DataTable dt, string sheetName)
        {
            //Tạo các đối tượng Excel

            Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();

            Microsoft.Office.Interop.Excel.Workbooks oBooks;

            Microsoft.Office.Interop.Excel.Sheets oSheets;

            Microsoft.Office.Interop.Excel.Workbook oBook;

            Microsoft.Office.Interop.Excel.Worksheet oSheet;

            //Tạo mới một Excel WorkBook

            oExcel.Visible = true;

            oExcel.DisplayAlerts = false;

            oExcel.Application.SheetsInNewWorkbook = 1;

            oBooks = oExcel.Workbooks;

            oBook = (Microsoft.Office.Interop.Excel.Workbook)(oExcel.Workbooks.Add(Type.Missing));

            oSheets = oBook.Worksheets;

            oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oSheets.get_Item(1);

            oSheet.Name = sheetName;

            // Tên hàng thuốc
            Microsoft.Office.Interop.Excel.Range head1 = oSheet.get_Range("B1", "G1");
            head1.MergeCells          = true;
            head1.Value2              = ControllerBase.userInfo.UserName.ToUpper();
            head1.Font.Bold           = true;
            head1.Font.Name           = "Calibri";
            head1.Font.Size           = "10";
            head1.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // Địa chỉ nhà thuốc
            Microsoft.Office.Interop.Excel.Range head2 = oSheet.get_Range("B2", "G2");
            head2.MergeCells          = true;
            head2.Value2              = ControllerBase.userInfo.UserAddress;
            head2.Font.Bold           = true;
            head2.Font.Name           = "Calibri";
            head2.Font.Size           = "10";
            head2.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // tiêu đề ĐƠN THUỐC
            Microsoft.Office.Interop.Excel.Range head3 = oSheet.get_Range("A4", "H4");
            head3.MergeCells          = true;
            head3.Value2              = "PHIẾU NHẬP THUỐC";
            head3.Font.Bold           = true;
            head3.Font.Name           = "Calibri";
            head3.Font.Size           = "30";
            head3.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

            // Mã Phiếu Nhập
            Microsoft.Office.Interop.Excel.Range head4 = oSheet.get_Range("B6", "G6");
            head4.MergeCells          = true;
            head4.Value2              = $"Mã phiếu nhập  : {inputcoupon.ID_InputCoupon}";
            head4.Font.Bold           = true;
            head4.Font.Name           = "Calibri";
            head4.Font.Size           = "11";
            head4.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // Ngày tạo
            Microsoft.Office.Interop.Excel.Range head5 = oSheet.get_Range("B7", "G7");
            head5.MergeCells          = true;
            head5.Value2              = $"Ngày tạo             : {inputcoupon.CreateDate.Day}/{inputcoupon.CreateDate.Month}/{inputcoupon.CreateDate.Year}";
            head5.Font.Bold           = true;
            head5.Font.Name           = "Calibri";
            head5.Font.Size           = "11";
            head5.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // Bác sĩ
            Microsoft.Office.Interop.Excel.Range head6 = oSheet.get_Range("B8", "G8");
            head6.MergeCells          = true;
            head6.Value2              = $"Mã nhà ung cấp        : {inputcoupon.ID_Supplier}";
            head6.Font.Bold           = true;
            head6.Font.Name           = "Calibri";
            head6.Font.Size           = "11";
            head6.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // Hồ sơ bệnh án
            //Microsoft.Office.Interop.Excel.Range head7 = oSheet.get_Range("B9", "G9");
            //head7.MergeCells = true;
            //head7.Value2 = $"Hồ sơ bệnh án : {prescription.MedicalRecord}";
            //head7.Font.Bold = true;
            //head7.Font.Name = "Calibri";
            //head7.Font.Size = "11";
            //head7.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // Danh sách thuốc
            Microsoft.Office.Interop.Excel.Range head8 = oSheet.get_Range("B11", "G11");
            head8.MergeCells          = true;
            head8.Value2              = "Danh sách thuốc";
            head8.Font.Bold           = true;
            head8.Font.Name           = "Calibri";
            head8.Font.Size           = "11";
            head8.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;

            // Tạo tiêu đề cột

            Microsoft.Office.Interop.Excel.Range clnull1 = oSheet.get_Range("A12", "A12");
            Microsoft.Office.Interop.Excel.Range clnull2 = oSheet.get_Range("H12", "H12");
            clnull1.ColumnWidth = 5;
            clnull2.ColumnWidth = 5;

            Microsoft.Office.Interop.Excel.Range cl1 = oSheet.get_Range("B12", "B12");
            cl1.Value2      = "STT";
            cl1.ColumnWidth = 5;

            Microsoft.Office.Interop.Excel.Range cl2 = oSheet.get_Range("C12", "C12");
            cl2.Value2      = "Tên thuốc";
            cl2.ColumnWidth = 30;

            Microsoft.Office.Interop.Excel.Range cl3 = oSheet.get_Range("D12", "D12");
            cl3.Value2      = "Đơn vị";
            cl3.ColumnWidth = 15;

            Microsoft.Office.Interop.Excel.Range cl4 = oSheet.get_Range("E12", "E12");
            cl4.Value2      = "Số lượng";
            cl4.ColumnWidth = 15;

            Microsoft.Office.Interop.Excel.Range cl5 = oSheet.get_Range("F12", "F12");
            cl5.Value2      = "Đơn Giá";
            cl5.ColumnWidth = 20;

            Microsoft.Office.Interop.Excel.Range cl6 = oSheet.get_Range("G12", "G12");
            cl6.Value2      = "Thành tiền";
            cl6.ColumnWidth = 20;

            Microsoft.Office.Interop.Excel.Range rowHead = oSheet.get_Range("B12", "G12");

            rowHead.Font.Bold = true;

            // Kẻ viền

            rowHead.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid;

            // Thiết lập màu nền

            rowHead.Interior.ColorIndex = 15;

            rowHead.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

            // Tạo mẳng đối tượng để lưu dữ toàn bồ dữ liệu trong DataTable,

            // vì dữ liệu được được gán vào các Cell trong Excel phải thông qua object thuần.

            object[,] arr = new object[dt.Rows.Count, dt.Columns.Count];

            //Chuyển dữ liệu từ DataTable vào mảng đối tượng

            for (int r = 0; r < dt.Rows.Count; r++)
            {
                DataRow dr = dt.Rows[r];

                arr[r, 0] = r + 1;
                arr[r, 1] = dr["Name"];
                arr[r, 2] = dr["UnitInput"];
                arr[r, 3] = dr["Amount"];
                arr[r, 4] = dr["Price"];
                arr[r, 5] = dr["IntoMoney"];
            }

            //Thiết lập vùng điền dữ liệu

            int rowStart = 13;

            int columnStart = 2;

            int rowEnd = rowStart + dt.Rows.Count - 1;

            int columnEnd = dt.Columns.Count - 4;

            // Ô bắt đầu điền dữ liệu

            Microsoft.Office.Interop.Excel.Range c1 = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[rowStart, columnStart];

            // Ô kết thúc điền dữ liệu

            Microsoft.Office.Interop.Excel.Range c2 = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[rowEnd, columnEnd];

            // Lấy về vùng điền dữ liệu

            Microsoft.Office.Interop.Excel.Range range = oSheet.get_Range(c1, c2);

            //Điền dữ liệu vào vùng đã thiết lập

            range.Value2 = arr;

            // Kẻ viền

            range.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid;

            // Căn giữa cột STT, MaNV

            Microsoft.Office.Interop.Excel.Range c3 = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[rowEnd, columnStart];

            Microsoft.Office.Interop.Excel.Range c4 = oSheet.get_Range(c1, c3);

            oSheet.get_Range(c3, c4).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

            // Tạo phần tổng tiền
            Microsoft.Office.Interop.Excel.Range range1 = oSheet.get_Range($"B{rowEnd + 1}", $"F{rowEnd + 1}");
            Microsoft.Office.Interop.Excel.Range range2 = oSheet.get_Range($"G{rowEnd + 1}", $"G{rowEnd + 1}");
            Microsoft.Office.Interop.Excel.Range range3 = oSheet.get_Range($"B{rowEnd + 2}", $"C{rowEnd + 2}");
            Microsoft.Office.Interop.Excel.Range range4 = oSheet.get_Range($"D{rowEnd + 2}", $"G{rowEnd + 2}");

            range1.MergeCells        = true;
            range1.Font.Bold         = true;
            range1.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid;
            range1.Value2            = "Tổng tiền (viết bằng số):";

            range2.Font.Bold         = true;
            range2.Value2            = inputcoupon.TotalMoney;
            range2.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid;

            range3.MergeCells        = true;
            range3.Font.Bold         = true;
            range3.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid;
            range3.Value2            = "Tổng tiền (viết bằng chữ):";

            range4.MergeCells        = true;
            range4.Font.Bold         = true;
            range4.Value2            = ConvertFromNumToText.Convert(inputcoupon.TotalMoney.ToString());
            range4.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.xlSolid;
        }