code
stringlengths 1
2.01M
| repo_name
stringlengths 3
62
| path
stringlengths 1
267
| language
stringclasses 231
values | license
stringclasses 13
values | size
int64 1
2.01M
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _1042009_1042034
{
public partial class uctStyle : UserControl
{
public uctStyle()
{
InitializeComponent();
}
private void uctStyle_Load(object sender, EventArgs e)
{
this.pnlChange.BackColor = MyColor.Change;
this.pnlDefault.BackColor = MyColor.Default;
this.pnlError.BackColor = MyColor.Eror;
this.pnlReadOnly.BackColor = MyColor.ReadOnly;
this.pnlEdit.BackColor = MyColor.Edit;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctStyle.cs
|
C#
|
asf20
| 746
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
namespace _1042009_1042034
{
public partial class uctDanhSachKhachThuePhong : UserControl
{
public uctDanhSachKhachThuePhong()
{
InitializeComponent();
}
List<LoaiKhachHangDTO> ListLoaiKhachHang = Business.LoaiKhachHangService.LayDanhSach();
MyDataGridView dgv = new MyDataGridView();
protected void CreateColumn()
{
this.dgv.Columns.Clear();
DataTable DataLoaiKhachHang = Business.LoaiKhachHangService.ConvertListLoaiKhachHangDTOToDataTable(ListLoaiKhachHang);
this.dgv.AddTextColumn(true, "STT", "STT");
//this.dgv.Columns["STT"].AutoIncrementSeed = 1;
this.dgv.AddTextColumn(true, "MaKhachHang", "Mã Khách");
this.dgv.AddTextColumn(false, "HoTen", "Họ và Tên");
this.dgv.AddComboBoxColumns(false, "MaLoaiKhachHang", "Loại Khách", DataLoaiKhachHang, LoaiKhachHangDTO.ValueMember, LoaiKhachHangDTO.DisplayMember);
this.dgv.AddTextColumn(false, "CMND", "CMND");
this.dgv.AddTextColumn(false, "DiaChi", "Địa Chỉ");
this.dgv.AddCheckBoxColumn("Check", "Check");
GetColoumnIndex();
}
int iMaKhachHang;
int iCheck;
int iMaLoaiKhachHang;
int iHoTen;
int iCMND;
int iDiaChi;
void GetColoumnIndex()
{
iMaKhachHang = this.dgv.GetColumIndexByName("MaKhachHang");
iHoTen = this.dgv.GetColumIndexByName("HoTen");
iMaLoaiKhachHang = this.dgv.GetColumIndexByName("MaLoaiKhachHang");
iCMND = this.dgv.GetColumIndexByName("CMND");
iDiaChi = this.dgv.GetColumIndexByName("DiaChi");
iCheck = this.dgv.GetColumIndexByName("Check");
}
void SetUpForm()
{
this.AutoSize = false;
this.AutoScroll = false;
this.Size = Form1.SizeContext;
panel.Size = this.dgv.Size;
panel.Controls.Add(this.dgv);
panel.AutoScroll = false;
panel.AutoSize = false;
}
protected void SetUpDataGridView()
{
this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
this.dgv.Rows.Clear();
this.dgv.Columns.Clear();
this.dgv.Location = new Point(0, 0);
this.dgv.Size = new Size(Form1.SizeContext.Width - 180, 140);
this.dgv.ScrollBars = ScrollBars.Both;
this.dgv.TopLeftHeaderCell.Value = "Select All";
this.dgv.BackgroundColor = Color.White;
// dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
// cho hien dong trang.
this.dgv.AllowUserToAddRows = true;
}
private void uctDanhSachKhachThuePhong_Load(object sender, EventArgs e)
{
this.SetUpDataGridView();
this.SetUpForm();
this.CreateColumn();
this.dgv.Rows.Add(5);
//su kien
this.dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged);
}
int iStt = 0;
int iMaKhachHangIdentity = Business.KhachHangService.GetIdentity();
void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int ColIndex = this.dgv.SelectedCells[0].ColumnIndex;
int RowIndex = this.dgv.SelectedCells[0].RowIndex;
if (this.dgv.Rows[RowIndex].Cells[0].Value == null)
{
if (iStt == RowIndex)
{
iStt++;
this.dgv.Rows[RowIndex].Cells[0].Value = iStt.ToString();
this.dgv.Rows[RowIndex].Cells[iMaKhachHang].Value = (this.iStt + this.iMaKhachHangIdentity).ToString();
}
else
{
this.dgv[ColIndex, RowIndex].Value = null;
return;
}
}
if (ColIndex != 0 )
{
this.dgv.SetRowColor(RowIndex, MyColor.Edit);
}
if (ColIndex != iCheck && ColIndex != 0)//0 la Stt
{
this.dgv.Rows[RowIndex].Cells[iCheck].Value = "Checked";
}
}
void RemoveRow(int iRow)
{
this.dgv[this.iCheck, 0].Selected = true;
for (int i = iRow; i < this.dgv.Rows.Count - 1; i++)
{
if (this.dgv.Rows[i + 1].Cells[0].Value != null)
{
this.dgv.Rows[i].Cells[this.iMaLoaiKhachHang].Value = this.dgv.Rows[i + 1].Cells[iMaLoaiKhachHang].Value;
this.dgv.Rows[i].Cells[this.iHoTen].Value = this.dgv.Rows[i + 1].Cells[iHoTen].Value;
this.dgv.Rows[i].Cells[iCMND].Value = this.dgv.Rows[i + 1].Cells[iCMND].Value;
this.dgv.Rows[i].Cells[this.iDiaChi].Value = this.dgv.Rows[i + 1].Cells[iDiaChi].Value;
this.dgv.Rows[i].Cells[this.iCheck].Value = this.dgv.Rows[i + 1].Cells[this.iCheck].Value;
}
else
{
this.dgv.Rows[i].Cells[0].Value = null;
this.dgv.Rows[i].Cells[this.iMaKhachHang].Value = null;
this.dgv.Rows[i].Cells[this.iMaLoaiKhachHang].Value = null;
this.dgv.Rows[i].Cells[this.iHoTen].Value = null;
this.dgv.Rows[i].Cells[iCMND].Value = null;
this.dgv.Rows[i].Cells[this.iDiaChi].Value = null;
this.dgv.Rows[i].Cells[this.iCheck].Value = null;
}
}
if (this.dgv.Rows.Count > 8)
{
this.dgv.Rows.RemoveAt(this.iStt - 1);
}
else
{
this.dgv.SetRowColor(this.iStt - 1, MyColor.White);
}
this.iStt--;
}
private void btnXoa_Click(object sender, EventArgs e)
{
int CheckColIndex = iCheck;
for (int i = this.dgv.Rows.Count - 1; i >= 0; i--)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value.ToString() == "Checked")
{
//tien hanh xoa du lieu tren form
this.RemoveRow(i);
}
}
}
}
/////////////////////////
//kiem tra khach trong phong co hop le hay khong
KhachHangDTO GetDataOfRows(int iRow)
{
KhachHangDTO x = new KhachHangDTO();
if( this.dgv[this.iMaKhachHang, iRow].Value != null)
{
x.MaKhachHang = int.Parse(this.dgv[this.iMaKhachHang, iRow].Value.ToString());
}
if (this.dgv[this.iMaLoaiKhachHang, iRow].Value != null)
{
x.MaLoaiKhachHang = int.Parse(this.dgv[this.iMaLoaiKhachHang, iRow].Value.ToString());
}
if (this.dgv[this.iHoTen, iRow].Value != null)
{
x.HoTen = this.dgv[this.iHoTen, iRow].Value.ToString();
}
if (this.dgv[this.iCMND, iRow].Value != null)
{
x.CMND = this.dgv[this.iCMND, iRow].Value.ToString();
}
if (this.dgv[iDiaChi, iRow].Value != null)
{
x.DiaChi = this.dgv[this.iDiaChi, iRow].Value.ToString();
}
return x;
}
List<KhachHangDTO> lst = new List<KhachHangDTO>();
public bool KiemTraKhach()
{
//kiem tra tinh hop le cua du lieu
lst.Clear();
KhachHangDTO Kh = new KhachHangDTO();
bool Flag = true;
for (int i = 0; i < this.dgv.Rows.Count; i++)
{
if (this.dgv[this.iCheck, i].Value != null && this.dgv[this.iCheck, i].Value.ToString() == "Checked")
{
Kh = this.GetDataOfRows(i);
if (Kh.KiemTra() == false)
{
Flag = false;
this.dgv.SetRowColor(i, MyColor.Eror);
}
this.lst.Add(Kh);
}
}
if (Flag == false)
this.lst.Clear();
return Flag;
}
public List<KhachHangDTO> LayDanhSachKhachThue()
{
this.KiemTraKhach();
return this.lst;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctDanhSachKhachThuePhong.cs
|
C#
|
asf20
| 9,232
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _1042009_1042034
{
public partial class UctTimKiem : UserControl
{
public UctTimKiem()
{
InitializeComponent();
}
private void UctTimKiem_Load(object sender, EventArgs e)
{
this.Size = new Size(796, 457);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/UctTimKiem.cs
|
C#
|
asf20
| 518
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _1042009_1042034
{
public partial class uctLapHoaDon : UserControl
{
public uctLapHoaDon()
{
InitializeComponent();
}
private void textBox1_Leave(object sender, EventArgs e)
{
MessageBox.Show("Leave");
}
private void uctLapHoaDon_Load(object sender, EventArgs e)
{
}
private void uctDanhSachPhongThue1_Load(object sender, EventArgs e)
{
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctLapHoaDon.cs
|
C#
|
asf20
| 712
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Windows.Forms;
namespace _1042009_1042034
{
class ComboBoxTinhTrang:ComboBox
{
public void Load()
{
List<LoaiPhongDTO> lst = new List<LoaiPhongDTO>();
this.DataSource = lst;
this.DisplayMember = LoaiPhongDTO.DisplayMember;
this.ValueMember = LoaiPhongDTO.ValueMember;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/ComboBoxTinhTrang.cs
|
C#
|
asf20
| 492
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _1042009_1042034
{
public partial class UctBaoCaoDoanhThuTheoLoaiPhong : UserControl
{
public UctBaoCaoDoanhThuTheoLoaiPhong()
{
InitializeComponent();
}
private void UctDoanhThuTheoLoaiPhong_Load(object sender, EventArgs e)
{
this.Size = new Size(796, 457);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/UctBaoCaoDoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 572
|
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("1042009-1042034")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("1042009-1042034")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5b7bb7ce-29fa-4b70-80c0-a0a14a12a975")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/Properties/AssemblyInfo.cs
|
C#
|
asf20
| 1,441
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
namespace _1042009_1042034
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static public Size SizeContext = new Size(800, 800);
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(Business.HoaDonService.Count().ToString());
PhongDTO p = new PhongDTO();
int malonnhat = Business.PhongService.GetIdentity();
uctCapNhatDanhMucPhong cut = new uctCapNhatDanhMucPhong();
this.tabControl1.TabPages[2].Controls.Add(cut);
//int count = Business.ThamSoService.GetIdentity();
//MessageBox.Show(count.ToString());
// MessageBox.Show(DateTime.Today.ToString());
}
int i = 0;
private void btnColor_Click(object sender, EventArgs e)
{
i = i + 10;
Color cl = Color.FromArgb(i);
this.btnColor.BackColor = cl;
this.lblColor.Text = i.ToString();
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/Form1.cs
|
C#
|
asf20
| 1,314
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.ConstrainedExecution;
using System.Data;
using System.Drawing;
namespace _1042009_1042034
{
class MyDataGridView:DataGridView
{
public int iPage = 1;
public int iRecord = 6;
public int iRecordDefaul = 7;
public bool m_Reload;
// cac ham he thong.( coi thoi khong nen sua)
private List<string> ListColumnName = new List<string>();
public int GetColumIndexByName(string ColumnName)
{
int index = new int();
for (int i = 0; i < this.ListColumnName.Count; i ++)
{
if (this.ListColumnName[i] == ColumnName)
{
index = i;
}
}
return index;
}
private void AddColumnName(string ColumnName)
{
int Flag = 0;
for (int i = 0; i < this.ListColumnName.Count; i++)
{
if (this.ListColumnName[i] == ColumnName)
{
Flag ++;
break;
}
}
if (Flag == 0) this.ListColumnName.Add(ColumnName);
}
public void AddRows()
{
try
{
this.Rows.Clear();
if (this.MyDataTable.Rows.Count > iRecord)
{
this.Rows.Add(this.iRecordDefaul);
}
else
{
this.Rows.Add(this.MyDataTable.Rows.Count);
}
}
catch
{ }
}
public void AddColumnStt()
{
DataGridViewTextBoxColumn TextColumn = new DataGridViewTextBoxColumn();
TextColumn.HeaderText = "STT1";
TextColumn.DataPropertyName = "STT1";
TextColumn.ReadOnly = true;
TextColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
TextColumn.Resizable = DataGridViewTriState.True;
TextColumn.ValueType = Type.GetType("int");
if (ReadOnly == true)
{
TextColumn.DefaultCellStyle.BackColor = MyColor.ReadOnly;
}
this.Columns.Add(TextColumn);
}
public void AddComboBoxColumns(bool ReadOnly, string ColumnName, string Header, object dataSource, string ValueMember, string DisplayMember)
{
this.AddColumnName(ColumnName);
DataGridViewComboBoxColumn cbbColumn;
cbbColumn = this.CreateComboBoxColumn(ColumnName, Header, ReadOnly);
cbbColumn.ValueMember = ValueMember;
cbbColumn.DisplayMember = DisplayMember;
cbbColumn.DataSource = dataSource;
this.Columns.Add(cbbColumn);
}
public void AddLinkColumn(string ColumnName, string Header)
{
this.AddColumnName(ColumnName);
DataGridViewLinkColumn links = new DataGridViewLinkColumn();
links.HeaderText = Header;
links.DataPropertyName = ColumnName;
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;
this.Columns.Add(links);
}
private DataGridViewComboBoxColumn CreateComboBoxColumn(string ColumnName, string Header, bool ReadOnly)
{
this.AddColumnName(ColumnName);
DataGridViewComboBoxColumn cbbColumn = new DataGridViewComboBoxColumn();
cbbColumn.Name = ColumnName;
cbbColumn.HeaderText = Header;
cbbColumn.DropDownWidth = 160;
cbbColumn.Width = 90;
//cbbColumn.DisplayStyleForCurrentCellOnly = true;
cbbColumn.DisplayStyleForCurrentCellOnly = true;
cbbColumn.MaxDropDownItems = 3;
if (ReadOnly == true)
{
cbbColumn.ReadOnly = ReadOnly;
cbbColumn.DefaultCellStyle.BackColor = MyColor.ReadOnly;
cbbColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
}
cbbColumn.FlatStyle = FlatStyle.Flat;
return cbbColumn;
}
public void AddTextColumn(bool ReadOnly, string ColumnName, string Header)
{
this.AddColumnName(ColumnName);
DataGridViewTextBoxColumn TextColumn = new DataGridViewTextBoxColumn();
TextColumn.HeaderText = Header;
TextColumn.DataPropertyName = ColumnName;
TextColumn.ReadOnly = ReadOnly;
TextColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
if (ReadOnly == true)
{
TextColumn.DefaultCellStyle.BackColor = MyColor.ReadOnly;
}
this.Columns.Add(TextColumn);
}
public void AddButtonColumn(string ColumnName, string Header)
{
this.AddColumnName(ColumnName);
DataGridViewButtonColumn buttons = new DataGridViewButtonColumn();
buttons.HeaderText = ColumnName;
buttons.Text = Header;
buttons.UseColumnTextForButtonValue = true;
buttons.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
buttons.FlatStyle = FlatStyle.Standard;
buttons.CellTemplate.Style.BackColor = Color.Honeydew;
buttons.DisplayIndex = 0;
this.Columns.Add(buttons);
}
public void AddDateTimeColumn(bool ReadOnly, string ColumnName, string Header)
{
this.AddColumnName(ColumnName);
DataGridViewTextBoxColumn TextColumn = new DataGridViewTextBoxColumn();
TextColumn.HeaderText = Header;
TextColumn.DataPropertyName = ColumnName;
TextColumn.ReadOnly = ReadOnly;
this.Columns.Add(TextColumn);
}
public void AddCheckBoxColumn(string ColumnName, string Header)
{
this.AddColumnName(ColumnName);
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
column.HeaderText = Header;
column.Name = ColumnName;
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
column.FlatStyle = FlatStyle.Standard;
column.CellTemplate.Style.BackColor = Color.Beige;
column.TrueValue = "Checked";
column.FalseValue = "Unchecked";
this.Columns.Add(column);
}
public void uctMyDataGridView_Load(object sender, EventArgs e)
{
}
public void RemoveRows(int iRow)
{
try
{
this.MyDataTable.Rows.RemoveAt(iRow);
}
catch { }
}
public DataTable MyDataTable;
public void SetRowColor( int iRow, Color color, bool AllCells = false)
{
for (int i = 0; i < this.Columns.Count; i++)
{
if (AllCells == false)
{
if (this.Columns[i].ReadOnly == false)
{
this.Rows[iRow].Cells[i].Style.BackColor = color;
}
else
{
this.Rows[iRow].Cells[i].Style.BackColor = MyColor.ReadOnly;
}
}
else
{
this.Rows[iRow].Cells[i].Style.BackColor = color;
}
}
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/MyDataGridView.cs
|
C#
|
asf20
| 8,085
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _1042009_1042034
{
public partial class uctPhanTrang : UserControl
{
private int m_PageIndex = 1;
private int m_Page = 1;
public uctPhanTrang()
{
InitializeComponent();
}
private Color DefaultColor;
private void Reload()
{
this.Controls.Clear();
for (int i = 1; i <= this.m_Page; i++)
{
Button btn = new Button();
this.DefaultColor = btn.BackColor;
btn.Text = i.ToString();
btn.Location = new Point(i * 40, 0);
btn.Size = new Size(35, 35);
btn.Click += new EventHandler(btn_Click);
this.Controls.Add(btn);
}
}
public delegate void PageClick(int Page);
public event PageClick OnPageClick = null;
// Lam dep o day.
void UpdatePageIndex(int iPage)
{
this.Controls[this.m_PageIndex - 1 ].BackColor = this.DefaultColor;
this.Controls[this.m_PageIndex - 1].Enabled = true;
this.Controls[iPage -1].Enabled = false;
this.Controls[iPage -1].BackColor = Color.Red;
this.m_PageIndex = iPage;
}
void btn_Click(object sender, EventArgs e)
{
Button x = (Button)sender;
int NewPage = int.Parse(x.Text);
this.UpdatePageIndex(NewPage);
if (OnPageClick != null)
{
OnPageClick(NewPage);
}
}
public void SetValue(int TongSoBoDuLieu, int SoBoTrong1Trang, int iPageIndex = 1)
{
this.m_Page = TongSoBoDuLieu / SoBoTrong1Trang;
if (TongSoBoDuLieu % SoBoTrong1Trang > 0)
{
this.m_Page++;
}
if (this.m_Page == 0)
{
this.m_Page++;
}
this.m_PageIndex = iPageIndex;
if (iPageIndex >= this.m_Page)
{
this.m_PageIndex = this.m_Page;
}
this.Reload();
this.UpdatePageIndex(this.m_PageIndex);
}
public int GetPageIndex()
{
return this.m_PageIndex;
}
public int GetTotalPage()
{
return this.m_Page;
}
private void uctPhanTrang_Load(object sender, EventArgs e)
{
this.Reload();
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctPhanTrang.cs
|
C#
|
asf20
| 2,791
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
namespace _1042009_1042034
{
public partial class uctQuanLyLoaiPhong : UserControl
{
public uctQuanLyLoaiPhong()
{
InitializeComponent();
}
int iColStt, iColMaLoaiPhong, iColTenLoaiPhong, iColCheck, iColDonGia;
List<LoaiPhongDTO> LstLoaiPhong = Business.LoaiPhongService.LayDanhSach();
protected void CreateColumn()
{
this.dgv.Columns.Clear();
this.dgv.AddTextColumn(true, "STT", "STT");
this.dgv.AddColumnStt();
this.dgv.AddTextColumn(true, "MaLoaiPhong", "Mã Loại Phòng");
this.dgv.AddTextColumn(false, "TenLoaiPhong", "Tên Loại Phòng");
this.dgv.AddTextColumn(false, "DonGia", "Đơn giá");
this.dgv.AddCheckBoxColumn("Check", "Check");
this.iColStt = this.dgv.GetColumIndexByName("STT");
this.iColMaLoaiPhong = this.dgv.GetColumIndexByName("MaLoaiPhong");
this.iColTenLoaiPhong = this.dgv.GetColumIndexByName("TenLoaiPhong");
this.iColCheck = this.dgv.GetColumIndexByName("Check");
this.iColDonGia = this.dgv.GetColumIndexByName("DonGia");
}
void SetUpDataGridView()
{
this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
this.dgv.Location = new Point(0, 0);
this.dgv.ScrollBars = ScrollBars.Both;
this.dgv.TopLeftHeaderCell.Value = "Select All";
this.dgv.BackgroundColor = Color.White;
DataTable dt = Business.LoaiPhongService.ConvertListLoaiPhongDTOToDataTable(LstLoaiPhong);
this.dgv.MyDataTable = dt;
this.dgv.AddRows();
}
int iStt = 0;
void LoadRows(int iRow)
{
iStt = this.dgv.iRecord * (this.dgv.iPage - 1) + 1 + iRow;
this.dgv[this.iColStt, iRow].Value = this.iStt.ToString();
}
void ReLoad()
{
for (int i = 0; i < this.dgv.Rows.Count; i++)
{
this.LoadRows(i);
}
}
private void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
int iColIndex = this.dgv.SelectedCells[0].ColumnIndex;
int iRowIndex = this.dgv.SelectedCells[0].RowIndex;
this.dgv.SetRowColor(iRowIndex, MyColor.Edit);
if (iColIndex != this.iColCheck)
{
this.dgv[this.iColCheck, iRowIndex].Value = "Checked";
}
}
catch { }
}
private void uctQuanLyLoaiPhong_Load(object sender, EventArgs e)
{
CreateColumn();
this.SetUpDataGridView();
this.dgv.DataSource = this.dgv.MyDataTable;
//this.ReLoad();
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctQuanLyLoaiPhong.cs
|
C#
|
asf20
| 3,235
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
namespace _1042009_1042034
{
public partial class uctLapPhieuThue : UserControl
{
public uctLapPhieuThue()
{
InitializeComponent();
}
List<PhongDTO> lst = new List<PhongDTO>();
private void uctLapPhieuThue_Load(object sender, EventArgs e)
{
int MaPhieuThue = Business.PhieuThueService.GetIdentity();
this.txtMaPhieuThue.Text = (MaPhieuThue + 1).ToString();
this.cbbLoaiPhong.Load();
this.cbbLoaiPhong.SelectedItem = null;
int SoKhachToiDa = Business.ThamSoService.SoKhachToiDa();
this.lblGhiChu.Text = "(*) Đơn giá chỉ áp dụng cho phòng có từ " + SoKhachToiDa.ToString() + " khách trở xuống và không có người nước ngoài.";
this.lst = Business.PhongService.LayDanhSach();
this.lst = Business.PhongService.LayDanhSachPhongChuaThueTuList(lst);
this.SetDataComboBoxPhong(lst);
this.txtNgayThue.Text = this.dateTimePickerNgatyThue.Value.ToString();
}
void SetDataComboBoxPhong(List<PhongDTO> lstPhong)
{
this.cbbPhong.Text = "";
this.cbbPhong.DataSource = lstPhong;
this.cbbPhong.DisplayMember = PhongDTO.DisplayMember;
this.cbbPhong.ValueMember = PhongDTO.ValueMember;
}
private void cbbLoaiPhong_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int MaloaiPhong = int.Parse(this.cbbLoaiPhong.SelectedValue.ToString());
List<PhongDTO> lstPhongChuaThue = Business.PhongService.LayDanhSachPhongChuaThueTuList(this.lst, MaloaiPhong);
this.SetDataComboBoxPhong(lstPhongChuaThue);
LoaiPhongDTO Lp = (LoaiPhongDTO)this.cbbLoaiPhong.SelectedItem;
this.txtDonGia.Text = Lp.DonGia.ToString();
}
catch { }
}
private bool KiemTraThongTinPhong(ref string Mes)
{
bool kt = true;
if (this.cbbPhong.Items.Count == 0)
{
Mes = "Chưa chọn phòng";
return false;
}
return kt;
}
private void btnTaoPhieuThue_Click(object sender, EventArgs e)
{
//kiem tra thong tin phong thue
string Mes = "";
bool kt = this.KiemTraThongTinPhong(ref Mes);
if ( kt== false)
{
MessageBox.Show(Mes);
return;
}
//kiem tra quy dinh o day
int SoKhachToiDa = Business.ThamSoService.SoKhachToiDa();
List<KhachHangDTO> LstKhach = this.uctDanhSachKhachThue.LayDanhSachKhachThue();
if (LstKhach.Count == 0 || LstKhach.Count > SoKhachToiDa)
{
MessageBox.Show("Số lượng ( dữ liệu) Khách hàng không hợp lệ");
return;
}
//them khach hang vao gio hang
for (int i = 0; i < LstKhach.Count; i++)
{
Business.KhachHangService.Them(LstKhach[i]);
}
//khi du lieu da day du
PhieuThueDTO PhieuThue = new PhieuThueDTO();
double DonGiaPhong = double.Parse(this.txtDonGia.Text);
double TiLePhuTHuKhachNuocNgoai = Business.ThamSoService.PhuThuKhachNuocNgoai(LstKhach);
double TiLePhuTHuSoLuongKhach = Business.ThamSoService.PhuThuSoLuongKhach(LstKhach);
PhieuThue.DonGia = (DonGiaPhong * TiLePhuTHuKhachNuocNgoai) + (DonGiaPhong * TiLePhuTHuSoLuongKhach);
PhieuThue.MaPhieuThue = int.Parse(this.txtMaPhieuThue.Text);
PhongDTO p = (PhongDTO)this.cbbPhong.SelectedItem;
p.MaTinhTrang = TinhTrangDTO.MaDaThue;
Business.PhongService.CapNhat(p);
PhieuThue.MaPhong = p.MaPhong;
PhieuThue.NgayBatDauThue = this.dateTimePickerNgatyThue.Value;
PhieuThue.NgayKetThuc = this.dateTimePickerNgatyThue.Value;
Business.PhieuThueService.Them(PhieuThue);
//them chi tiet phieu thue
ChiTietPhieuThueDTO ct = new ChiTietPhieuThueDTO();
for (int i = 0; i < LstKhach.Count; i++)
{
ct.MaPhieuThue = PhieuThue.MaPhieuThue;
ct.MaKhachHang = LstKhach[i].MaKhachHang;
Business.ChiTietPhieuThueService.Them(ct);
}
MessageBox.Show("Đặt phòng thành công");
}
private void cbbPhong_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
PhongDTO phong = (PhongDTO)this.cbbPhong.SelectedItem;
LoaiPhongDTO Lp = Business.LoaiPhongService.LayTheoMa(phong.MaLoaiPhong);
this.txtDonGia.Text = Lp.DonGia.ToString();
}
catch { }
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctLapPhieuThue.cs
|
C#
|
asf20
| 5,349
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
namespace _1042009_1042034
{
public partial class uctDanhSachPhongThue : UserControl
{
public uctDanhSachPhongThue()
{
InitializeComponent();
}
int iColStt, iColMaPhong, iColTenPhong, iColDonGia, iColSoNgayThue, iColThanhTien, iColCheck;
protected void CreateColumn()
{
this.dgv.Columns.Clear();
this.dgv.AddTextColumn(true, "STT", "STT");
List<PhongDTO> lst = Business.PhongService.LayDanhSachPhongDaThue();
DataTable dt = Business.PhongService.ConvertListPhongDTOToDataTable(lst);
this.dgv.AddComboBoxColumns(false, "MaPhong", "Mã phòng", dt, PhongDTO.ValueMember, PhongDTO.ValueMember);
this.dgv.AddComboBoxColumns(false, "TenPhong", "Tên phòng", dt, PhongDTO.ValueMember, PhongDTO.DisplayMember);
this.dgv.AddTextColumn(true, "DonGia", "Đơn Giá");
this.dgv.AddTextColumn(true, "SoNgayThue", "Số ngày thuê");
this.dgv.AddTextColumn(true, "ThanhTien", "Thành tiền");
this.dgv.AddCheckBoxColumn("Check", "Check");
iColStt = this.dgv.GetColumIndexByName("STT");
iColMaPhong = this.dgv.GetColumIndexByName("MaPhong");
iColTenPhong = this.dgv.GetColumIndexByName("TenPhong");
iColDonGia = this.dgv.GetColumIndexByName("DonGia");
iColSoNgayThue = this.dgv.GetColumIndexByName("SoNgayThue");
iColThanhTien = this.dgv.GetColumIndexByName("ThanhTien");
iColCheck = this.dgv.GetColumIndexByName("Check");
}
void SetupDataGriew()
{
this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
this.dgv.Location = new Point(0, 0);
this.dgv.ScrollBars = ScrollBars.Both;
this.dgv.TopLeftHeaderCell.Value = "Select All";
this.dgv.BackgroundColor = Color.White;
// dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
// cho hien dong trang.
this.dgv.AllowUserToAddRows = true;
}
private void uctDanhSachPhongThue_Load(object sender, EventArgs e)
{
this.CreateColumn();
this.SetupDataGriew();
}
int iStt = 0;
int TinhKhoangCanh2Ngay(DateTime d1, DateTime d2)
{
int dd = ( d1 - d2).Days + 1;
// int kq = int.Parse(dd.ToString());
return dd;
}
private void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
int iRowIndex = this.dgv.SelectedCells[0].RowIndex;
int iColIndex = this.dgv.SelectedCells[0].ColumnIndex;
int iMa = int.Parse(this.dgv.SelectedCells[0].Value.ToString());
PhieuThueDTO pt = Business.PhieuThueService.LayPhieuThueHienTaiCuaPhong(iMa);
this.dgv[this.iColMaPhong, iRowIndex].Value = iMa.ToString();
this.dgv[this.iColTenPhong, iRowIndex].Value = iMa.ToString();
this.dgv[this.iColDonGia, iRowIndex].Value = pt.DonGia.ToString();
int SoNgayThue = TinhKhoangCanh2Ngay(DateTime.Now, pt.NgayBatDauThue);
this.dgv[this.iColSoNgayThue, iRowIndex].Value = SoNgayThue.ToString();
//thanh tien
double ThanhTien = pt.DonGia * SoNgayThue;
this.dgv[this.iColThanhTien, iRowIndex].Value = ThanhTien.ToString();
if (this.dgv[this.iStt, iRowIndex].Value == null)
{
this.iStt++;
this.dgv[this.iStt, iRowIndex].Value = this.iStt.ToString();
}
if (iColIndex != this.iColCheck)
{
this.dgv[this.iColCheck, iRowIndex].Value = "Checked";
}
}
catch { }
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctDanhSachPhongThue.cs
|
C#
|
asf20
| 4,320
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
namespace _1042009_1042034
{
public partial class uctCapNhatDanhMucPhong : UserControl
{
public uctCapNhatDanhMucPhong()
{
InitializeComponent();
}
int iColStt, iColMaPhong, iColTenPhong, iColMaLoaiPhong, iColDonGia, iColMaTinhTrang, iColGhiChu, iColCheck;
protected void CreateColumn()
{
this.dgv.Columns.Clear();
//lay data
List<LoaiPhongDTO> ListLoaiPhong = Business.LoaiPhongService.LayDanhSach();
List<TinhTrangDTO> ListTinhTrang = Business.TinhTrangService.LayDanhSach();
DataTable DataLoaiPhong = Business.LoaiPhongService.ConvertListLoaiPhongDTOToDataTable(ListLoaiPhong);
DataTable DataTinhTrang = Business.TinhTrangService.ConvertListTinhTrangDTOToDataTable(ListTinhTrang);
this.dgv.AddTextColumn(true, "STT", "STT");
this.dgv.AddTextColumn(true,"MaPhong", "Mã Phòng");
this.dgv.AddTextColumn(false, "TenPhong", "Tên Phòng");
this.dgv.AddComboBoxColumns(false, "MaLoaiPhong", "Loại Phòng", DataLoaiPhong, LoaiPhongDTO.ValueMember, LoaiPhongDTO.DisplayMember);
this.dgv.AddComboBoxColumns(true, "DonGia", "Đơn Giá", DataLoaiPhong, LoaiPhongDTO.ValueMember, "DonGia");
this.dgv.AddTextColumn(false, "GhiChu", "Ghi Chú");
this.dgv.AddComboBoxColumns(false, "MaTinhTrang", "Tình Trạng", DataTinhTrang, TinhTrangDTO.ValueMember, TinhTrangDTO.DisplayMember);
this.dgv.AddCheckBoxColumn("Check", "Check");
iColStt = this.dgv.GetColumIndexByName("STT");
iColMaPhong = this.dgv.GetColumIndexByName("MaPhong");
iColTenPhong = this.dgv.GetColumIndexByName("TenPhong");
iColMaLoaiPhong = this.dgv.GetColumIndexByName("MaLoaiPhong");
iColMaTinhTrang = this.dgv.GetColumIndexByName("MaTinhTrang");
iColGhiChu = this.dgv.GetColumIndexByName("GhiChu");
iColCheck = this.dgv.GetColumIndexByName("Check");
iColDonGia = this.dgv.GetColumIndexByName("DonGia");
}
protected void LoadRows(int iRow)
{
this.dgv.Rows[iRow].ReadOnly = false;
//coi no dang o trang may
int Start = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;
int Stt = Start + 1;
string[] lst = new string[]
{
Stt.ToString(),
this.dgv.MyDataTable.Rows[iRow]["MaPhong"].ToString(),
this.dgv.MyDataTable.Rows[iRow]["TenPhong"].ToString(),
this.dgv.MyDataTable.Rows[iRow]["MaloaiPhong"].ToString(),/////2 cot dung chung 1 Datasource
this.dgv.MyDataTable.Rows[iRow]["MaloaiPhong"].ToString(),/////
this.dgv.MyDataTable.Rows[iRow]["GhiChu"].ToString(),
this.dgv.MyDataTable.Rows[iRow]["MaTinhTrang"].ToString(),
"Unchecked"
};
this.dgv.Rows[iRow].SetValues(lst);
this.dgv.SetRowColor(iRow,MyColor.Default,true);
}
void SetUpForm()
{
this.AutoSize = false;
this.AutoScroll = false;
this.Size = Form1.SizeContext;
}
protected void SetUpDataGridView()
{
this.dgv.iRecord = 7;
this.dgv.BackgroundColor = MyColor.White;
this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
this.dgv.ScrollBars = ScrollBars.Horizontal;
this.dgv.TopLeftHeaderCell.Value = "Select All";
this.dgv.AutoSize = false;
//khong cho hien dong trang.
this.dgv.AllowUserToAddRows = false;
this.dgv.AllowUserToDeleteRows = false;
}
protected void ReLoad()
{
//phan trang lai
this.iTongSoBoDuLieu = Business.PhongService.Count();
this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord,this.dgv.iPage);
this.dgv.iPage = this.uctPhanTrang1.GetPageIndex();
int Start = this.dgv.iRecord * (this.dgv.iPage - 1);
ListPhong = Business.PhongService.LayDanhSach(Start + 1, this.dgv.iRecord);
DataTable DataPhong = Business.PhongService.ConvertListPhongDTOToDataTable(ListPhong);
this.dgv.MyDataTable = DataPhong;
//cap nhat lai trang.
uctPhanTrang1.Refresh();
this.dgv.AddRows();
if (this.dgv.MyDataTable != null)
{
for (int iRow = 0; iRow < this.dgv.iRecord; iRow++)
{
if (iRow < this.dgv.MyDataTable.Rows.Count)
{
this.LoadRows(iRow);
}
}
}
//xoa nhung du lieu da bi xoa di
for (int i = this.ListPhong.Count - 1; i >= 0; i--)
{
int index = Business.PhongService.KiemTraMaPhongTrongListPhong(this.ListPhong[i].MaPhong, this.ListRowsRemove);
if (index >= 0)
{
this.RemoveRow(i);
}
}
}
int iTongSoBoDuLieu = 0;
List<PhongDTO> ListPhong;
private void UctDanhMucPhong_Load(object sender, EventArgs e)
{
////////////////
this.SetUpDataGridView();
this.CreateColumn();
this.ReLoad();
this.SetUpForm();
//su kien
this.dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged);
this.uctPhanTrang1.OnPageClick += new uctPhanTrang.PageClick(uctPhanTrang1_OnPageClick);
}
void uctPhanTrang1_OnPageClick(int Page)
{
this.dgv.iPage = Page;
this.ReLoad();
}
void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int ColIndex = e.ColumnIndex;
int RowIndex = e.RowIndex;
if (ColIndex == this.iColMaLoaiPhong)
{
this.dgv.Rows[RowIndex].Cells[this.iColDonGia].Value = this.dgv.Rows[RowIndex].Cells[ColIndex].Value;
}
if (ColIndex != this.iColStt && this.dgv.Rows[RowIndex].Cells[this.iColCheck].Style.BackColor != MyColor.Delete)
{
this.dgv.SetRowColor(RowIndex, MyColor.Change,true);
}
if (ColIndex != this.iColCheck && ColIndex != this.iColStt)
{
this.dgv.Rows[RowIndex].Cells[this.iColCheck].Value = "Checked";
}
}
PhongDTO GetDataOfRows(int iRow)
{
PhongDTO p = new PhongDTO();
p.MaPhong = int.Parse(this.dgv.Rows[iRow].Cells[iColMaPhong].Value.ToString());
p.MaLoaiPhong = int.Parse(this.dgv.Rows[iRow].Cells[iColMaLoaiPhong].Value.ToString());
p.MaTinhTrang = int.Parse(this.dgv.Rows[iRow].Cells[iColMaTinhTrang].Value.ToString());
p.TenPhong = "";
if( this.dgv.Rows[iRow].Cells[iColTenPhong].Value != null)
{
p.TenPhong = (this.dgv.Rows[iRow].Cells[iColTenPhong].Value.ToString());
}
p.GhiChu = "";
if( this.dgv.Rows[iRow].Cells[iColGhiChu].Value != null)
{
p.GhiChu = (this.dgv.Rows[iRow].Cells[iColGhiChu].Value.ToString());
}
return p;
}
List<PhongDTO> ListRowsRemove = new List<PhongDTO>();
private void btnCapNhat_Click(object sender, EventArgs e)
{
int CheckColIndex = this.iColCheck;
PhongDTO objPhong = new PhongDTO();
for (int i = 0; i < this.dgv.Rows.Count; i++)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
{
DataGridViewCheckBoxCell CheckCell = (DataGridViewCheckBoxCell)this.dgv.Rows[i].Cells[CheckColIndex];
if (CheckCell.Value.ToString() == "Checked" && CheckCell.Style.BackColor != MyColor.Delete)
{
try
{
objPhong = this.GetDataOfRows(i);
}
catch
{
this.dgv.SelectedColumns[this.iColCheck].Selected = true;
this.dgv.Rows[i].Cells[this.iColCheck].Value = "Unchecked";
continue;
}
if (objPhong.KiemTra() == false)
{
this.dgv.SetRowColor(i, MyColor.Eror);
}
else
{
Business.PhongService.CapNhat(objPhong);
//cập nhật lại datasource, chua cap nhat lai DataBase
this.dgv.Rows[i].Cells[this.iColCheck].Selected = true;
this.dgv.Rows[i].Cells[this.iColCheck].Value = "Unchecked";
int iRecord = i + (this.dgv.iPage - 1)*this.dgv.iRecord;
//to mau cho dong do
this.dgv.SetRowColor(i, MyColor.Edit, true);
}
}
}
}
}
void SetStt()
{
int Stt = (this.dgv.iPage - 1) * this.dgv.iRecord + 1;
for (int i = 0; i < this.dgv.Rows.Count; i++)
{
this.dgv[this.iColStt, i].Value = Stt.ToString();
Stt++;
}
}
void RemoveRow(int iRow)
{
this.dgv.Rows.RemoveAt(iRow);
this.SetStt();
}
private void btnXoa_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Bạn có chắc chắn xóa dữ liệu", "Câu hỏi dành cho bạn", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
!= DialogResult.Yes)
{
return;
}
int CheckColIndex = this.iColCheck;
int Dem = 0;
for (int i = this.dgv.Rows.Count - 1; i >= 0; i--)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value.ToString() == "Checked")
{
//luu vao ListXoa
PhongDTO PhongXoa = this.GetDataOfRows(i);
if (Business.PhongService.KiemTraMaPhongTrongListPhong(PhongXoa.MaPhong, this.ListRowsRemove) == -1)
{
this.ListRowsRemove.Add(PhongXoa);
}
Dem++;
//tien hanh xoa du lieu tren form
this.RemoveRow(i);
}
}
}
if (Dem > 0)
{
//this.ReLoad();
}
}
private void btnCapNhatCSDL_Click(object sender, EventArgs e)
{
//Xoa
if (MessageBox.Show("Dữ liệu sau khi xóa sẽ không thể phục hồi, tiếp tục?", "DataBase", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.No)
{
return;
}
for (int k = this.ListRowsRemove.Count - 1; k >= 0 ; k -- )
{
bool bXoaPhong = Business.PhongService.Xoa(this.ListRowsRemove[k].MaPhong);
if ( bXoaPhong== false)
{
if (MessageBox.Show("Phòng có Mã " + this.ListRowsRemove[k].MaPhong + " đang bị tham chiếu, Bạn có muốn xóa hết dữ liệu liên quan không?", "DataBase", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
if( Business.PhongService.Xoa(this.ListRowsRemove[k].MaPhong, true) == true)
this.ListRowsRemove.RemoveAt(k);
}
}
else
{
this.ListRowsRemove.RemoveAt(k);
}
}
this.ReLoad();
}
private void btnPhucHoiCSDL_Click(object sender, EventArgs e)
{
DataTable dt = Business.PhongService.ConvertListPhongDTOToDataTable(this.ListRowsRemove);
PhucHoiDuLieu frm = new PhucHoiDuLieu(dt);
frm.OnLayDanhSachMaPhucHoi += new PhucHoiDuLieu.LayDanhSachMaPhucHoi(frm_OnLayDanhSachMaPhucHoi);
frm.ShowDialog();
}
void frm_OnLayDanhSachMaPhucHoi(List<int> lstMa)
{
for (int i = this.ListRowsRemove.Count - 1; i >= 0; i--)
{
int Ma = ListRowsRemove[i].MaPhong;
if (TimPhanTuTrongList(Ma, lstMa) > -1)
{
this.ListRowsRemove.RemoveAt(i);
}
}
this.ReLoad();
}
int TimPhanTuTrongList(int Value, List<int> lst)
{
for (int i = 0; i < lst.Count; i++)
{
if (lst[i] == Value)
return i;
}
return -1;
}
private void dgv_CellLeave(object sender, DataGridViewCellEventArgs e)
{
try
{
int iRow = this.dgv.SelectedCells[0].RowIndex;
Color x = dgv[this.iColCheck, iRow].Style.BackColor;
dgv.SetRowColor(iRow, x, true);
}
catch { }
}
private void dgv_CellEnter(object sender, DataGridViewCellEventArgs e)
{
try
{
int iRow = this.dgv.SelectedCells[0].RowIndex;
Color x = dgv[this.iColCheck, iRow].Style.BackColor;
dgv.SetRowColor(iRow, x);
}
catch { }
}
private void dgv_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
int iRow = e.RowIndex;
DataGridViewCheckBoxCell checkcell = (DataGridViewCheckBoxCell)this.dgv[this.iColCheck, iRow];
if (checkcell.Value.ToString() == "Checked")
{
checkcell.Value = "Unchecked";
}
else
{
checkcell.Value = "Checked";
}
}
catch { }
}
string Check = "Checked";
string UnCheck = "Unchecked";
private void dgv_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == this.iColCheck)
{
for (int i = 0; i < this.dgv.Rows.Count; i++)
{
if (dgv[iColCheck, i].Value.ToString() != Check)
{
dgv[iColCheck, i].Value = Check;
}
}
}
string c = Check;
Check = UnCheck;
UnCheck = c;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/uctCapNhatDanhMucPhong.cs
|
C#
|
asf20
| 16,336
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace _1042009_1042034
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/1042009-1042034/Program.cs
|
C#
|
asf20
| 508
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class ChiTietDoanhThuTheoLoaiPhongDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaChiTietDoanhThu;
private int m_MaDoanhThu;
private int m_MaLoaiPhong;
private double m_DoanhThu;
private double m_TyLe;
public int MaChiTietDoanhThu
{
get { return this.m_MaChiTietDoanhThu; }
set { this.m_MaChiTietDoanhThu = value; }
}
public int MaDoanhThu
{
get { return this.m_MaDoanhThu; }
set { this.m_MaDoanhThu = value; }
}
public int MaLoaiPhong
{
get { return this.m_MaLoaiPhong; }
set { this.m_MaLoaiPhong = value; }
}
public double DoanhThu
{
get { return this.m_DoanhThu; }
set { this.m_DoanhThu = value; }
}
public double TyLe
{
get { return this.m_TyLe; }
set { this.m_TyLe = value; }
}
public static readonly string DisplayMember ="MaDoanhThu";
public static readonly string ValueMember ="MaChiTietDoanhThu";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.ChiTietDoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 1,360
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class TinhTrangDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaTinhTrang;
private string m_TenTinhTrang;
public int MaTinhTrang
{
get { return this.m_MaTinhTrang; }
set { this.m_MaTinhTrang = value; }
}
public string TenTinhTrang
{
get { return this.m_TenTinhTrang; }
set { this.m_TenTinhTrang = value; }
}
public static readonly string DisplayMember ="TenTinhTrang";
public static readonly string ValueMember ="MaTinhTrang";
public static readonly int MaDaThue = 1;
public static readonly int MaChuaThue = 2;
public static readonly int MaDangSuaChua = 3;
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.TinhTrang.cs
|
C#
|
asf20
| 1,068
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class PhieuThueDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaPhieuThue;
private DateTime m_NgayBatDauThue;
private int m_MaPhong;
private DateTime m_NgayKetThuc;
private double m_DonGia;
public int MaPhieuThue
{
get { return this.m_MaPhieuThue; }
set { this.m_MaPhieuThue = value; }
}
public DateTime NgayBatDauThue
{
get { return this.m_NgayBatDauThue; }
set { this.m_NgayBatDauThue = value; }
}
public int MaPhong
{
get { return this.m_MaPhong; }
set { this.m_MaPhong = value; }
}
public DateTime NgayKetThuc
{
get { return this.m_NgayKetThuc; }
set { this.m_NgayKetThuc = value; }
}
public double DonGia
{
get { return this.m_DonGia; }
set { this.m_DonGia = value; }
}
public static readonly string DisplayMember ="NgayBatDauThue";
public static readonly string ValueMember ="MaPhieuThue";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.PhieuThue.cs
|
C#
|
asf20
| 1,349
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class PhongDTO
{
//////////////////////////////////////////////////////////
public bool KiemTra()
{
if (this.TenPhong == "")
return false;
if (this.MaLoaiPhong == -1)
return false;
if (this.m_MaTinhTrang == -1)
return false;
if (this.GhiChu == "")
return false;
return true;
}
public PhongDTO()
{
this.m_MaPhong = -1;
this.m_TenPhong = "";
this.m_MaLoaiPhong = -1;
this.m_GhiChu = "";
this.m_MaTinhTrang = -1;
}
//////////////////////////////////////////////////////////
private int m_MaPhong;
private string m_TenPhong;
private int m_MaLoaiPhong;
private string m_GhiChu;
private int m_MaTinhTrang;
public int MaPhong
{
get { return this.m_MaPhong; }
set { this.m_MaPhong = value; }
}
public string TenPhong
{
get { return this.m_TenPhong; }
set { this.m_TenPhong = value; }
}
public int MaLoaiPhong
{
get { return this.m_MaLoaiPhong; }
set { this.m_MaLoaiPhong = value; }
}
public string GhiChu
{
get { return this.m_GhiChu; }
set { this.m_GhiChu = value; }
}
public int MaTinhTrang
{
get { return this.m_MaTinhTrang; }
set { this.m_MaTinhTrang = value; }
}
public static readonly string DisplayMember ="TenPhong";
public static readonly string ValueMember ="MaPhong";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.Phong.cs
|
C#
|
asf20
| 1,749
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class MatDoSuDungPhongDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaMatDoPhong;
private int m_Thang;
public int MaMatDoPhong
{
get { return this.m_MaMatDoPhong; }
set { this.m_MaMatDoPhong = value; }
}
public int Thang
{
get { return this.m_Thang; }
set { this.m_Thang = value; }
}
public static readonly string DisplayMember ="Thang";
public static readonly string ValueMember ="MaMatDoPhong";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.MatDoSuDungPhong.cs
|
C#
|
asf20
| 879
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class LoaiKhachHangDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaLoaiKhachHang;
private string m_TenLoaiKhachHang;
public int MaLoaiKhachHang
{
get { return this.m_MaLoaiKhachHang; }
set { this.m_MaLoaiKhachHang = value; }
}
public string TenLoaiKhachHang
{
get { return this.m_TenLoaiKhachHang; }
set { this.m_TenLoaiKhachHang = value; }
}
public static readonly string DisplayMember ="TenLoaiKhachHang";
public static readonly string ValueMember ="MaLoaiKhachHang";
public static readonly int MaKhachNuocNgoai = 1;
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.LoaiKhachHang.cs
|
C#
|
asf20
| 1,013
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class LoaiPhongDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
public bool KiemTra()
{
if (this.DonGia <= 0
|| this.TenLoaiPhong == string.Empty
|| this.MaLoaiPhong < 0)
return false;
return true;
}
//////////////////////////////////////////////////////////
private int m_MaLoaiPhong;
private string m_TenLoaiPhong;
private double m_DonGia;
public int MaLoaiPhong
{
get { return this.m_MaLoaiPhong; }
set { this.m_MaLoaiPhong = value; }
}
public string TenLoaiPhong
{
get { return this.m_TenLoaiPhong; }
set { this.m_TenLoaiPhong = value; }
}
public double DonGia
{
get { return this.m_DonGia; }
set { this.m_DonGia = value; }
}
public static readonly string DisplayMember ="TenLoaiPhong";
public static readonly string ValueMember ="MaLoaiPhong";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.LoaiPhong.cs
|
C#
|
asf20
| 1,228
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class DoanhThuTheoLoaiPhongDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaDoanhThu;
private int m_Thang;
public int MaDoanhThu
{
get { return this.m_MaDoanhThu; }
set { this.m_MaDoanhThu = value; }
}
public int Thang
{
get { return this.m_Thang; }
set { this.m_Thang = value; }
}
public static readonly string DisplayMember ="Thang";
public static readonly string ValueMember ="MaDoanhThu";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.DoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 874
|
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DTO")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DTO")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e8ea8e6d-9c27-48ed-96cd-1f987538aa29")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/Properties/AssemblyInfo.cs
|
C#
|
asf20
| 1,417
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class NhanVienDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaNhanVien;
private string m_HoTen;
private int m_MaChucVu;
private string m_UserName;
private string m_Pass;
private string m_CMDN;
private string m_DiaChi;
private string m_SoDienThoai;
public int MaNhanVien
{
get { return this.m_MaNhanVien; }
set { this.m_MaNhanVien = value; }
}
public string HoTen
{
get { return this.m_HoTen; }
set { this.m_HoTen = value; }
}
public int MaChucVu
{
get { return this.m_MaChucVu; }
set { this.m_MaChucVu = value; }
}
public string UserName
{
get { return this.m_UserName; }
set { this.m_UserName = value; }
}
public string Pass
{
get { return this.m_Pass; }
set { this.m_Pass = value; }
}
public string CMDN
{
get { return this.m_CMDN; }
set { this.m_CMDN = value; }
}
public string DiaChi
{
get { return this.m_DiaChi; }
set { this.m_DiaChi = value; }
}
public string SoDienThoai
{
get { return this.m_SoDienThoai; }
set { this.m_SoDienThoai = value; }
}
public static readonly string DisplayMember ="HoTen";
public static readonly string ValueMember ="MaNhanVien";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.NhanVien.cs
|
C#
|
asf20
| 1,691
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class ChiTietMatDoSuDungPhongDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaChiTietMatDoPhong;
private int m_MaPhong;
private int m_MaMatDoPhong;
private int m_SoNgayThue;
private double m_TyLe;
public int MaChiTietMatDoPhong
{
get { return this.m_MaChiTietMatDoPhong; }
set { this.m_MaChiTietMatDoPhong = value; }
}
public int MaPhong
{
get { return this.m_MaPhong; }
set { this.m_MaPhong = value; }
}
public int MaMatDoPhong
{
get { return this.m_MaMatDoPhong; }
set { this.m_MaMatDoPhong = value; }
}
public int SoNgayThue
{
get { return this.m_SoNgayThue; }
set { this.m_SoNgayThue = value; }
}
public double TyLe
{
get { return this.m_TyLe; }
set { this.m_TyLe = value; }
}
public static readonly string DisplayMember ="MaPhong";
public static readonly string ValueMember ="MaChiTietMatDoPhong";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.ChiTietMatDoSuDungPhong.cs
|
C#
|
asf20
| 1,356
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class HoaDonDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaHoaDon;
private double m_TriGia;
private int m_MaKhachHang;
public int MaHoaDon
{
get { return this.m_MaHoaDon; }
set { this.m_MaHoaDon = value; }
}
public double TriGia
{
get { return this.m_TriGia; }
set { this.m_TriGia = value; }
}
public int MaKhachHang
{
get { return this.m_MaKhachHang; }
set { this.m_MaKhachHang = value; }
}
public static readonly string DisplayMember ="TriGia";
public static readonly string ValueMember ="MaHoaDon";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.HoaDon.cs
|
C#
|
asf20
| 1,009
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class ChucVuDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaChucVu;
private string m_TenChucVu;
public int MaChucVu
{
get { return this.m_MaChucVu; }
set { this.m_MaChucVu = value; }
}
public string TenChucVu
{
get { return this.m_TenChucVu; }
set { this.m_TenChucVu = value; }
}
public static readonly string DisplayMember ="TenChucVu";
public static readonly string ValueMember ="MaChucVu";
}
}
/*
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
namespace _1042009_1042034
{
public partial class uctCapNhatDanhMucPhong : UserControl
{
public uctCapNhatDanhMucPhong()
{
InitializeComponent();
}
int iColStt, iColMaPhong, iColTenPhong, iColMaLoaiPhong, iColDonGia, iColMaTinhTrang, iColGhiChu, iColCheck;
protected void CreateColumn()
{
this.dgv.Columns.Clear();
DataTable DataLoaiPhong = Business.LoaiPhongService.ConvertListLoaiPhongDTOToDataTable(ListLoaiPhong);
DataTable DataTinhTrang = Business.TinhTrangService.ConvertListTinhTrangDTOToDataTable(ListTinhTrang);
DataTable DataPhong = Business.PhongService.ConvertListPhongDTOToDataTable(ListPhong);
this.dgv.MyDataTable = DataPhong;
this.dgv.AddTextColumn(true, "STT", "STT");
this.dgv.AddTextColumn(true,"MaPhong", "Mã Phòng");
this.dgv.AddTextColumn(false, "TenPhong", "Tên Phòng");
this.dgv.AddComboBoxColumns(false, "MaLoaiPhong", "Loại Phòng", DataLoaiPhong, LoaiPhongDTO.ValueMember, LoaiPhongDTO.DisplayMember);
this.dgv.AddComboBoxColumns(true, "DonGia", "Đơn Giá", DataLoaiPhong, LoaiPhongDTO.ValueMember, "DonGia");
this.dgv.AddTextColumn(false, "GhiChu", "Ghi Chú");
this.dgv.AddComboBoxColumns(false, "MaTinhTrang", "Tình Trạng", DataTinhTrang, TinhTrangDTO.ValueMember, TinhTrangDTO.DisplayMember);
this.dgv.AddCheckBoxColumn("Check", "Check");
iColStt = this.dgv.GetColumIndexByName("STT");
iColMaPhong = this.dgv.GetColumIndexByName("MaPhong");
iColTenPhong = this.dgv.GetColumIndexByName("TenPhong");
iColMaLoaiPhong = this.dgv.GetColumIndexByName("MaLoaiPhong");
iColMaTinhTrang = this.dgv.GetColumIndexByName("MaTinhTrang");
iColGhiChu = this.dgv.GetColumIndexByName("GhiChu");
iColCheck = this.dgv.GetColumIndexByName("Check");
iColDonGia = this.dgv.GetColumIndexByName("DonGia");
}
protected void LoadRows(int iRow)
{
this.dgv.Rows[iRow].ReadOnly = false;
//coi no dang o trang may
int Start = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;
int Stt = Start + 1;
string[] lst = new string[] {Stt.ToString(),
this.dgv.MyDataTable.Rows[Start]["MaPhong"].ToString(),
this.dgv.MyDataTable.Rows[Start]["TenPhong"].ToString(),
this.dgv.MyDataTable.Rows[Start]["MaloaiPhong"].ToString(),/////2 cot dung chung 1 Datasource
this.dgv.MyDataTable.Rows[Start]["MaloaiPhong"].ToString(),/////
this.dgv.MyDataTable.Rows[Start]["GhiChu"].ToString(),
this.dgv.MyDataTable.Rows[Start]["MaTinhTrang"].ToString(),
"Unchecked"};
this.dgv.Rows[iRow].SetValues(lst);
this.dgv.SetRowColor(iRow,MyColor.Default);
}
void SetUpForm()
{
this.AutoSize = false;
this.AutoScroll = false;
this.Size = Form1.SizeContext;
}
protected void SetUpDataGridView()
{
this.dgv.iRecord = 7;
this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
this.dgv.ScrollBars = ScrollBars.Horizontal;
this.dgv.TopLeftHeaderCell.Value = "Select All";
this.dgv.AutoSize = false;
// dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
//khong cho hien dong trang.
this.dgv.AllowUserToAddRows = false;
}
protected void ReLoad()
{
this.dgv.m_Reload = true;
//cap nhat lai trang.
uctPhanTrang1.Refresh();
this.dgv.AddRows();
if (this.dgv.MyDataTable != null)
{
int Start = this.dgv.iRecord * (this.dgv.iPage - 1);
int iRow = 0;
for (int i = Start; i < Start + this.dgv.iRecord; i++)
{
if (i < this.dgv.MyDataTable.Rows.Count)
{
this.LoadRows(iRow);
iRow++;
}
}
}
}
int iTongSoBoDuLieu = 0;
List<PhongDTO> ListPhong;
List<PhongDTO> ListPhongDuTru;
List<LoaiPhongDTO> ListLoaiPhong;
List<TinhTrangDTO> ListTinhTrang;
private void UctDanhMucPhong_Load(object sender, EventArgs e)
{
//lay data
ListPhong = Business.PhongService.LayDanhSach();
ListPhongDuTru = Business.PhongService.LayDanhSach();
ListLoaiPhong = Business.LoaiPhongService.LayDanhSach();
ListTinhTrang = Business.TinhTrangService.LayDanhSach();
////////////////
this.SetUpDataGridView();
this.CreateColumn();
this.ReLoad();
this.SetUpForm();
//su kien
this.dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged);
//click thay doi trang.
this.iTongSoBoDuLieu = Business.PhongService.Count();
this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord);
this.uctPhanTrang1.OnPageClick += new uctPhanTrang.PageClick(uctPhanTrang1_OnPageClick);
}
void uctPhanTrang1_OnPageClick(int Page)
{
this.dgv.iPage = Page;
this.ReLoad();
}
void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int ColIndex = this.dgv.SelectedCells[0].ColumnIndex;
int RowIndex = this.dgv.SelectedCells[0].RowIndex;
if (this.dgv.Rows[RowIndex].ReadOnly == true)
{
return;
}
if (ColIndex == this.iColMaLoaiPhong)
{
this.dgv.Rows[RowIndex].Cells[ColIndex + 1].Value = this.dgv.Rows[RowIndex].Cells[ColIndex].Value;
}
if (ColIndex != 0)
{
this.dgv.SetRowColor(RowIndex, MyColor.Edit);
}
if (ColIndex != this.iColCheck && ColIndex != this.iColStt)
{
this.dgv.Rows[RowIndex].Cells[this.iColCheck].Value = "Checked";
}
}
PhongDTO GetDataOfRows(int iRow)
{
PhongDTO p = new PhongDTO();
p.MaPhong = int.Parse(this.dgv.Rows[iRow].Cells[iColMaPhong].Value.ToString());
p.MaLoaiPhong = int.Parse(this.dgv.Rows[iRow].Cells[iColMaLoaiPhong].Value.ToString());
p.MaTinhTrang = int.Parse(this.dgv.Rows[iRow].Cells[iColMaTinhTrang].Value.ToString());
p.TenPhong = "";
if( this.dgv.Rows[iRow].Cells[iColTenPhong].Value != null)
{
p.TenPhong = (this.dgv.Rows[iRow].Cells[iColTenPhong].Value.ToString());
}
p.GhiChu = "";
if( this.dgv.Rows[iRow].Cells[iColGhiChu].Value != null)
{
p.GhiChu = (this.dgv.Rows[iRow].Cells[iColGhiChu].Value.ToString());
}
return p;
}
void UpdateDataSource(int iRow, PhongDTO obj)
{
int Start = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;
this.dgv.MyDataTable.Rows[Start][1] = obj.TenPhong.ToString();
this.dgv.MyDataTable.Rows[Start][2] = obj.MaLoaiPhong.ToString();
this.dgv.MyDataTable.Rows[Start][3] = obj.GhiChu.ToString();
this.dgv.MyDataTable.Rows[Start][4] = obj.MaTinhTrang.ToString();
}
List<PhongDTO> ListRowsChange = new List<PhongDTO>();
private void btnCapNhat_Click(object sender, EventArgs e)
{
int CheckColIndex = this.iColCheck;
PhongDTO objPhong = new PhongDTO();
int Dem = 0;
for (int i = 0; i < this.dgv.Rows.Count; i++)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value.ToString() == "Checked")
{
try
{
objPhong = this.GetDataOfRows(i);
}
catch
{
this.dgv.SelectedColumns[this.iColCheck].Selected = true;
this.dgv.Rows[i].Cells[this.iColCheck].Value = "Unchecked";
continue;
}
if (objPhong.KiemTra() == false)
{
this.dgv.SetRowColor(i, MyColor.Eror);
}
else
{
//Business.PhongService.CapNhat(objPhong);
//cập nhật lại datasource, chua cap nhat lai DataBase
this.UpdateDataSource(i, objPhong);
this.dgv.Rows[i].Cells[this.iColCheck].Selected = true;
this.dgv.Rows[i].Cells[this.iColCheck].Value = "Unchecked";
int iRecord = i + (this.dgv.iPage - 1)*this.dgv.iRecord;
int index = Business.PhongService.KiemTraMaPhongTrongListPhong(objPhong.MaPhong, this.ListRowsChange);
if (index >= 0)
{
this.ListRowsChange.RemoveAt(index);
}
this.ListRowsChange.Add(objPhong);
Dem++;
}
}
}
}
if (Dem > 0)
{
MessageBox.Show("Đã cập nhật lại dữ liệu trên Form");
}
}
List<PhongDTO> ListRowsRemove = new List<PhongDTO>();
void RemoveRow(int iRow)
{
//xoa trong List
try
{
int iCount = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;
//add vao danh sach xoa
this.ListPhong.RemoveAt(iCount);
this.iTongSoBoDuLieu--;
this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord, this.dgv.iPage);
this.dgv.iPage = this.uctPhanTrang1.GetPageIndex();
}
catch { }
//xoa DataSource
this.dgv.RemoveRows(iRow);
}
private void btnXoa_Click(object sender, EventArgs e)
{
int CheckColIndex = this.iColCheck;
int Dem = 0;
for (int i = this.dgv.Rows.Count - 1; i >= 0; i--)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
{
if (this.dgv.Rows[i].Cells[CheckColIndex].Value.ToString() == "Checked")
{
//luu vao ListXoa
PhongDTO PhongXoa = this.GetDataOfRows(i);
if (Business.PhongService.KiemTraMaPhongTrongListPhong(PhongXoa.MaPhong, this.ListRowsRemove) == -1)
{
this.ListRowsRemove.Add(PhongXoa);
}
Dem++;
//tien hanh xoa du lieu tren form
this.RemoveRow(i);
}
}
}
if (Dem > 0)
{
this.ReLoad();
}
}
private void btnCapNhatCSDL_Click(object sender, EventArgs e)
{
//Cap nhat
for (int i = 0; i < this.ListRowsChange.Count; i++)
{
Business.PhongService.CapNhat(this.ListRowsChange[i]);
}
//Cap nhat
for (int i = 0; i < this.ListRowsRemove.Count; i++)
{
Business.PhongService.Xoa(this.ListRowsRemove[i].MaPhong);
}
this.ListRowsChange.Clear();
this.ListRowsRemove.Clear();
MessageBox.Show("Đã ghi xuống CSDL");
}
void PhucHoiDuLieuTrenForm()
{
for (int i = 0; i < this.ListPhong.Count; i++)
{
Business.PhongService.CapNhat(this.ListPhong[i]);
}
//cap nhat lai Data cua dgv
// this.bReLoadDataSource = true;
}
private void btnPhucHoiCSDL_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Chỉ phục hồi những dữ liệu bị thay đổi, không phục hồi dữ liệu đã xóa", "Phục hồi dữ liệu đã cập nhật", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
for (int i = 0; i < this.ListPhong.Count; i++)
{
//phuc hoi CSDL
Business.PhongService.CapNhat(this.ListPhong[i]);
//kho a nha. phuc hoi tren form.
this.PhucHoiDuLieuTrenForm();
}
///phuc hoi nhung bo du lieu da xoa tren form nhung chua ghi vao CSDL
for( int i = 0; i < this.ListRowsRemove.Count; i++)
{
int index = Business.PhongService.TimViTriPhongTrongListPhong(this.ListRowsRemove[i].MaPhong, this.ListPhongDuTru);
if (index > -1)
{
this.ListPhong.Add(this.ListPhongDuTru[index]);
this.iTongSoBoDuLieu++;
this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord);
}
}
this.ListRowsChange.Clear();
this.ListRowsRemove.Clear();
this.dgv.iPage = 1;
this.ReLoad();
}
}
}
}
*/
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.ChucVu.cs
|
C#
|
asf20
| 15,801
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class ThamSoDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
static public readonly int MaThamSoSoLoaiPhongToiDa = 2;
static public readonly int MaThamSoSoTinhTrangToiDa = 3;
static public readonly int MaThamSoLuongKhachToiDaMoiPhong = 1;
static public readonly int MaThamSoPhuThuSoLuongKhach = 5;
static public readonly int MaThamSoPhuThuKhachNuocNgoai = 7;
//////////////////////////////////////////////////////////
private int m_MaThamSo;
private string m_TenThamSo;
private double m_GiaTri;
private string m_GhiChu;
private Boolean m_SuDung;
public int MaThamSo
{
get { return this.m_MaThamSo; }
set { this.m_MaThamSo = value; }
}
public string TenThamSo
{
get { return this.m_TenThamSo; }
set { this.m_TenThamSo = value; }
}
public double GiaTri
{
get { return this.m_GiaTri; }
set { this.m_GiaTri = value; }
}
public string GhiChu
{
get { return this.m_GhiChu; }
set { this.m_GhiChu = value; }
}
public Boolean SuDung
{
get { return this.m_SuDung; }
set { this.m_SuDung = value; }
}
public static readonly string DisplayMember = "TenThamSo";
public static readonly string ValueMember = "MaThamSo";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.ThamSo.cs
|
C#
|
asf20
| 1,756
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
public class ChiTietHoaDonDTO
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
private int m_MaChiTietHoaDon;
private int m_MaHoaDon;
private int m_MaPhieuThue;
private double m_ThanhTien;
public int MaChiTietHoaDon
{
get { return this.m_MaChiTietHoaDon; }
set { this.m_MaChiTietHoaDon = value; }
}
public int MaHoaDon
{
get { return this.m_MaHoaDon; }
set { this.m_MaHoaDon = value; }
}
public int MaPhieuThue
{
get { return this.m_MaPhieuThue; }
set { this.m_MaPhieuThue = value; }
}
public double ThanhTien
{
get { return this.m_ThanhTien; }
set { this.m_ThanhTien = value; }
}
public static readonly string DisplayMember ="MaHoaDon";
public static readonly string ValueMember ="MaChiTietHoaDon";
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/DTO/DTO.ChiTietHoaDon.cs
|
C#
|
asf20
| 1,202
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class LoaiKhachHangService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListLoaiKhachHangDTOToDataTable( List<LoaiKhachHangDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaLoaiKhachHang");
dt.Columns.Add( "TenLoaiKhachHang");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaLoaiKhachHang,
lst[i].TenLoaiKhachHang
);
}
return dt;
}
static public int GetIdentity()
{
Data.LoaiKhachHangRepository repo = new LoaiKhachHangRepository();
return repo.GetIdentity();
}
static public int Count()
{
return LoaiKhachHangRepository.Count();
}
public static bool Them(LoaiKhachHangDTO objDTO)
{
LoaiKhachHangRepository repo = new LoaiKhachHangRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaLoaiKhachHang, bool XoaKhoaNgoai=false)
{
LoaiKhachHangRepository Repo = new LoaiKhachHangRepository();
return Repo.Xoa(MaLoaiKhachHang,XoaKhoaNgoai);
}
public static void CapNhat(LoaiKhachHangDTO objDTO)
{
try
{
LoaiKhachHangRepository Repo = new LoaiKhachHangRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<LoaiKhachHangDTO> LayDanhSach()
{
List<LoaiKhachHangDTO> lst = new List<LoaiKhachHangDTO>();
try
{
LoaiKhachHangRepository obj = new LoaiKhachHangRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<LoaiKhachHangDTO> LayDanhSach(int Start, int Record)
{
Data.LoaiKhachHangRepository repo = new LoaiKhachHangRepository();
return repo.LayDanhSach(Start, Record);
}
public static LoaiKhachHangDTO LayTheoMa(int MaLoaiKhachHang)
{
LoaiKhachHangDTO objDTO = new LoaiKhachHangDTO();
try
{
LoaiKhachHangRepository Repo = new LoaiKhachHangRepository();
objDTO = Repo.LayTheoMa(MaLoaiKhachHang);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.LoaiKhachHang.cs
|
C#
|
asf20
| 3,229
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class ChiTietHoaDonService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListChiTietHoaDonDTOToDataTable( List<ChiTietHoaDonDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaChiTietHoaDon");
dt.Columns.Add( "MaHoaDon");
dt.Columns.Add( "MaPhieuThue");
dt.Columns.Add( "ThanhTien");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaChiTietHoaDon,
lst[i].MaHoaDon,
lst[i].MaPhieuThue,
lst[i].ThanhTien
);
}
return dt;
}
static public int GetIdentity()
{
Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
return repo.GetIdentity();
}
static public int Count()
{
return ChiTietHoaDonRepository.Count();
}
public static bool Them(ChiTietHoaDonDTO objDTO)
{
ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaChiTietHoaDon, bool XoaKhoaNgoai=false)
{
ChiTietHoaDonRepository Repo = new ChiTietHoaDonRepository();
return Repo.Xoa(MaChiTietHoaDon,XoaKhoaNgoai);
}
public static void CapNhat(ChiTietHoaDonDTO objDTO)
{
try
{
ChiTietHoaDonRepository Repo = new ChiTietHoaDonRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<ChiTietHoaDonDTO> LayDanhSach()
{
List<ChiTietHoaDonDTO> lst = new List<ChiTietHoaDonDTO>();
try
{
ChiTietHoaDonRepository obj = new ChiTietHoaDonRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<ChiTietHoaDonDTO> LayDanhSach(int Start, int Record)
{
Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
return repo.LayDanhSach(Start, Record);
}
public static ChiTietHoaDonDTO LayTheoMa(int MaChiTietHoaDon)
{
ChiTietHoaDonDTO objDTO = new ChiTietHoaDonDTO();
try
{
ChiTietHoaDonRepository Repo = new ChiTietHoaDonRepository();
objDTO = Repo.LayTheoMa(MaChiTietHoaDon);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai HoaDon
//
static public List<ChiTietHoaDonDTO> LayDanhSachTheoMaHoaDon( int MaHoaDon)
{
Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
return repo.LayDanhSachTheoMaHoaDon( MaHoaDon);
}
static public void XoaTheoMaHoaDon( int MaHoaDon, bool XoaKhoaNgoai=false)
{
Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
repo.XoaTheoMaHoaDon( MaHoaDon,XoaKhoaNgoai);
}
//
//Khoa ngoai PhieuThue
//
static public List<ChiTietHoaDonDTO> LayDanhSachTheoMaPhieuThue( int MaPhieuThue)
{
Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
return repo.LayDanhSachTheoMaPhieuThue( MaPhieuThue);
}
static public void XoaTheoMaPhieuThue( int MaPhieuThue, bool XoaKhoaNgoai=false)
{
Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
repo.XoaTheoMaPhieuThue( MaPhieuThue,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.ChiTietHoaDon.cs
|
C#
|
asf20
| 4,484
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class NhanVienService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListNhanVienDTOToDataTable( List<NhanVienDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaNhanVien");
dt.Columns.Add( "HoTen");
dt.Columns.Add( "MaChucVu");
dt.Columns.Add( "UserName");
dt.Columns.Add( "Pass");
dt.Columns.Add( "CMDN");
dt.Columns.Add( "DiaChi");
dt.Columns.Add( "SoDienThoai");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaNhanVien,
lst[i].HoTen,
lst[i].MaChucVu,
lst[i].UserName,
lst[i].Pass,
lst[i].CMDN,
lst[i].DiaChi,
lst[i].SoDienThoai
);
}
return dt;
}
static public int GetIdentity()
{
Data.NhanVienRepository repo = new NhanVienRepository();
return repo.GetIdentity();
}
static public int Count()
{
return NhanVienRepository.Count();
}
public static bool Them(NhanVienDTO objDTO)
{
NhanVienRepository repo = new NhanVienRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaNhanVien, bool XoaKhoaNgoai=false)
{
NhanVienRepository Repo = new NhanVienRepository();
return Repo.Xoa(MaNhanVien,XoaKhoaNgoai);
}
public static void CapNhat(NhanVienDTO objDTO)
{
try
{
NhanVienRepository Repo = new NhanVienRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<NhanVienDTO> LayDanhSach()
{
List<NhanVienDTO> lst = new List<NhanVienDTO>();
try
{
NhanVienRepository obj = new NhanVienRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<NhanVienDTO> LayDanhSach(int Start, int Record)
{
Data.NhanVienRepository repo = new NhanVienRepository();
return repo.LayDanhSach(Start, Record);
}
public static NhanVienDTO LayTheoMa(int MaNhanVien)
{
NhanVienDTO objDTO = new NhanVienDTO();
try
{
NhanVienRepository Repo = new NhanVienRepository();
objDTO = Repo.LayTheoMa(MaNhanVien);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai ChucVu
//
static public List<NhanVienDTO> LayDanhSachTheoMaChucVu( int MaChucVu)
{
Data.NhanVienRepository repo = new NhanVienRepository();
return repo.LayDanhSachTheoMaChucVu( MaChucVu);
}
static public void XoaTheoMaChucVu( int MaChucVu, bool XoaKhoaNgoai=false)
{
Data.NhanVienRepository repo = new NhanVienRepository();
repo.XoaTheoMaChucVu( MaChucVu,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.NhanVien.cs
|
C#
|
asf20
| 4,061
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
namespace Business
{
public class spt_valuesService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public int GetIdentity()
{
Data.spt_valuesRepository repo = new spt_valuesRepository();
return repo.GetIdentity();
}
static public int Count()
{
return spt_valuesRepository.Count();
}
public static void Them(spt_valuesDTO objDTO)
{
try
{
spt_valuesRepository repo = new spt_valuesRepository();
repo.Them(objDTO);
}
catch (System.Exception )
{
}
}
public static void Xoa(int Maspt_values)
{
try
{
spt_valuesRepository Repo = new spt_valuesRepository();
Repo.Xoa(Maspt_values);
}
catch (System.Exception )
{
}
}
public static void CapNhat(spt_valuesDTO objDTO)
{
try
{
spt_valuesRepository Repo = new spt_valuesRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<spt_valuesDTO> LayDanhSach()
{
List<spt_valuesDTO> lst = new List<spt_valuesDTO>();
try
{
spt_valuesRepository obj = new spt_valuesRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<spt_valuesDTO> LayDanhSach(int Start, int Record)
{
Data.spt_valuesRepository repo = new spt_valuesRepository();
return repo.LayDanhSach(Start, Record);
}
public static spt_valuesDTO LayTheoMa(int Maspt_values)
{
spt_valuesDTO objDTO = new spt_valuesDTO();
try
{
spt_valuesRepository Repo = new spt_valuesRepository();
objDTO = Repo.LayTheoMa(Maspt_values);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.spt_values.cs
|
C#
|
asf20
| 2,775
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class MatDoSuDungPhongService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListMatDoSuDungPhongDTOToDataTable( List<MatDoSuDungPhongDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaMatDoPhong");
dt.Columns.Add( "Thang");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaMatDoPhong,
lst[i].Thang
);
}
return dt;
}
static public int GetIdentity()
{
Data.MatDoSuDungPhongRepository repo = new MatDoSuDungPhongRepository();
return repo.GetIdentity();
}
static public int Count()
{
return MatDoSuDungPhongRepository.Count();
}
public static bool Them(MatDoSuDungPhongDTO objDTO)
{
MatDoSuDungPhongRepository repo = new MatDoSuDungPhongRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaMatDoSuDungPhong, bool XoaKhoaNgoai=false)
{
MatDoSuDungPhongRepository Repo = new MatDoSuDungPhongRepository();
return Repo.Xoa(MaMatDoSuDungPhong,XoaKhoaNgoai);
}
public static void CapNhat(MatDoSuDungPhongDTO objDTO)
{
try
{
MatDoSuDungPhongRepository Repo = new MatDoSuDungPhongRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<MatDoSuDungPhongDTO> LayDanhSach()
{
List<MatDoSuDungPhongDTO> lst = new List<MatDoSuDungPhongDTO>();
try
{
MatDoSuDungPhongRepository obj = new MatDoSuDungPhongRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<MatDoSuDungPhongDTO> LayDanhSach(int Start, int Record)
{
Data.MatDoSuDungPhongRepository repo = new MatDoSuDungPhongRepository();
return repo.LayDanhSach(Start, Record);
}
public static MatDoSuDungPhongDTO LayTheoMa(int MaMatDoSuDungPhong)
{
MatDoSuDungPhongDTO objDTO = new MatDoSuDungPhongDTO();
try
{
MatDoSuDungPhongRepository Repo = new MatDoSuDungPhongRepository();
objDTO = Repo.LayTheoMa(MaMatDoSuDungPhong);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.MatDoSuDungPhong.cs
|
C#
|
asf20
| 3,294
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class DoanhThuTheoLoaiPhongService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListDoanhThuTheoLoaiPhongDTOToDataTable( List<DoanhThuTheoLoaiPhongDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaDoanhThu");
dt.Columns.Add( "Thang");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaDoanhThu,
lst[i].Thang
);
}
return dt;
}
static public int GetIdentity()
{
Data.DoanhThuTheoLoaiPhongRepository repo = new DoanhThuTheoLoaiPhongRepository();
return repo.GetIdentity();
}
static public int Count()
{
return DoanhThuTheoLoaiPhongRepository.Count();
}
public static bool Them(DoanhThuTheoLoaiPhongDTO objDTO)
{
DoanhThuTheoLoaiPhongRepository repo = new DoanhThuTheoLoaiPhongRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaDoanhThuTheoLoaiPhong, bool XoaKhoaNgoai=false)
{
DoanhThuTheoLoaiPhongRepository Repo = new DoanhThuTheoLoaiPhongRepository();
return Repo.Xoa(MaDoanhThuTheoLoaiPhong,XoaKhoaNgoai);
}
public static void CapNhat(DoanhThuTheoLoaiPhongDTO objDTO)
{
try
{
DoanhThuTheoLoaiPhongRepository Repo = new DoanhThuTheoLoaiPhongRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<DoanhThuTheoLoaiPhongDTO> LayDanhSach()
{
List<DoanhThuTheoLoaiPhongDTO> lst = new List<DoanhThuTheoLoaiPhongDTO>();
try
{
DoanhThuTheoLoaiPhongRepository obj = new DoanhThuTheoLoaiPhongRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<DoanhThuTheoLoaiPhongDTO> LayDanhSach(int Start, int Record)
{
Data.DoanhThuTheoLoaiPhongRepository repo = new DoanhThuTheoLoaiPhongRepository();
return repo.LayDanhSach(Start, Record);
}
public static DoanhThuTheoLoaiPhongDTO LayTheoMa(int MaDoanhThuTheoLoaiPhong)
{
DoanhThuTheoLoaiPhongDTO objDTO = new DoanhThuTheoLoaiPhongDTO();
try
{
DoanhThuTheoLoaiPhongRepository Repo = new DoanhThuTheoLoaiPhongRepository();
objDTO = Repo.LayTheoMa(MaDoanhThuTheoLoaiPhong);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.DoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 3,445
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class TinhTrangService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListTinhTrangDTOToDataTable( List<TinhTrangDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaTinhTrang");
dt.Columns.Add( "TenTinhTrang");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaTinhTrang,
lst[i].TenTinhTrang
);
}
return dt;
}
static public int GetIdentity()
{
Data.TinhTrangRepository repo = new TinhTrangRepository();
return repo.GetIdentity();
}
static public int Count()
{
return TinhTrangRepository.Count();
}
public static bool Them(TinhTrangDTO objDTO)
{
TinhTrangRepository repo = new TinhTrangRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaTinhTrang, bool XoaKhoaNgoai=false)
{
TinhTrangRepository Repo = new TinhTrangRepository();
return Repo.Xoa(MaTinhTrang,XoaKhoaNgoai);
}
public static void CapNhat(TinhTrangDTO objDTO)
{
try
{
TinhTrangRepository Repo = new TinhTrangRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<TinhTrangDTO> LayDanhSach()
{
List<TinhTrangDTO> lst = new List<TinhTrangDTO>();
try
{
TinhTrangRepository obj = new TinhTrangRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<TinhTrangDTO> LayDanhSach(int Start, int Record)
{
Data.TinhTrangRepository repo = new TinhTrangRepository();
return repo.LayDanhSach(Start, Record);
}
public static TinhTrangDTO LayTheoMa(int MaTinhTrang)
{
TinhTrangDTO objDTO = new TinhTrangDTO();
try
{
TinhTrangRepository Repo = new TinhTrangRepository();
objDTO = Repo.LayTheoMa(MaTinhTrang);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.TinhTrang.cs
|
C#
|
asf20
| 3,089
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class ChiTietDoanhThuTheoLoaiPhongService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListChiTietDoanhThuTheoLoaiPhongDTOToDataTable( List<ChiTietDoanhThuTheoLoaiPhongDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaChiTietDoanhThu");
dt.Columns.Add( "MaDoanhThu");
dt.Columns.Add( "MaLoaiPhong");
dt.Columns.Add( "DoanhThu");
dt.Columns.Add( "TyLe");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaChiTietDoanhThu,
lst[i].MaDoanhThu,
lst[i].MaLoaiPhong,
lst[i].DoanhThu,
lst[i].TyLe
);
}
return dt;
}
static public int GetIdentity()
{
Data.ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
return repo.GetIdentity();
}
static public int Count()
{
return ChiTietDoanhThuTheoLoaiPhongRepository.Count();
}
public static bool Them(ChiTietDoanhThuTheoLoaiPhongDTO objDTO)
{
ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaChiTietDoanhThuTheoLoaiPhong, bool XoaKhoaNgoai=false)
{
ChiTietDoanhThuTheoLoaiPhongRepository Repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
return Repo.Xoa(MaChiTietDoanhThuTheoLoaiPhong,XoaKhoaNgoai);
}
public static void CapNhat(ChiTietDoanhThuTheoLoaiPhongDTO objDTO)
{
try
{
ChiTietDoanhThuTheoLoaiPhongRepository Repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSach()
{
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = new List<ChiTietDoanhThuTheoLoaiPhongDTO>();
try
{
ChiTietDoanhThuTheoLoaiPhongRepository obj = new ChiTietDoanhThuTheoLoaiPhongRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSach(int Start, int Record)
{
Data.ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
return repo.LayDanhSach(Start, Record);
}
public static ChiTietDoanhThuTheoLoaiPhongDTO LayTheoMa(int MaChiTietDoanhThuTheoLoaiPhong)
{
ChiTietDoanhThuTheoLoaiPhongDTO objDTO = new ChiTietDoanhThuTheoLoaiPhongDTO();
try
{
ChiTietDoanhThuTheoLoaiPhongRepository Repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
objDTO = Repo.LayTheoMa(MaChiTietDoanhThuTheoLoaiPhong);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai DoanhThuTheoLoaiPhong
//
static public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSachTheoMaDoanhThuTheoLoaiPhong( int MaDoanhThuTheoLoaiPhong)
{
Data.ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
return repo.LayDanhSachTheoMaDoanhThuTheoLoaiPhong( MaDoanhThuTheoLoaiPhong);
}
static public void XoaTheoMaDoanhThuTheoLoaiPhong( int MaDoanhThuTheoLoaiPhong, bool XoaKhoaNgoai=false)
{
Data.ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
repo.XoaTheoMaDoanhThuTheoLoaiPhong( MaDoanhThuTheoLoaiPhong,XoaKhoaNgoai);
}
//
//Khoa ngoai LoaiPhong
//
static public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSachTheoMaLoaiPhong( int MaLoaiPhong)
{
Data.ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
return repo.LayDanhSachTheoMaLoaiPhong( MaLoaiPhong);
}
static public void XoaTheoMaLoaiPhong( int MaLoaiPhong, bool XoaKhoaNgoai=false)
{
Data.ChiTietDoanhThuTheoLoaiPhongRepository repo = new ChiTietDoanhThuTheoLoaiPhongRepository();
repo.XoaTheoMaLoaiPhong( MaLoaiPhong,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.ChiTietDoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 5,320
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
namespace Business
{
public class spt_monitorService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public int GetIdentity()
{
Data.spt_monitorRepository repo = new spt_monitorRepository();
return repo.GetIdentity();
}
static public int Count()
{
return spt_monitorRepository.Count();
}
public static void Them(spt_monitorDTO objDTO)
{
try
{
spt_monitorRepository repo = new spt_monitorRepository();
repo.Them(objDTO);
}
catch (System.Exception )
{
}
}
public static void Xoa(int Maspt_monitor)
{
try
{
spt_monitorRepository Repo = new spt_monitorRepository();
Repo.Xoa(Maspt_monitor);
}
catch (System.Exception )
{
}
}
public static void CapNhat(spt_monitorDTO objDTO)
{
try
{
spt_monitorRepository Repo = new spt_monitorRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<spt_monitorDTO> LayDanhSach()
{
List<spt_monitorDTO> lst = new List<spt_monitorDTO>();
try
{
spt_monitorRepository obj = new spt_monitorRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<spt_monitorDTO> LayDanhSach(int Start, int Record)
{
Data.spt_monitorRepository repo = new spt_monitorRepository();
return repo.LayDanhSach(Start, Record);
}
public static spt_monitorDTO LayTheoMa(int Maspt_monitor)
{
spt_monitorDTO objDTO = new spt_monitorDTO();
try
{
spt_monitorRepository Repo = new spt_monitorRepository();
objDTO = Repo.LayTheoMa(Maspt_monitor);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.spt_monitor.cs
|
C#
|
asf20
| 2,804
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class PhongService
{
//////////////////////////////////////////////////////////
// Enter code your here //
public static PhongDTO LayPhongTheoTen(string TenPhong)
{
PhongRepository Repo = new PhongRepository();
return Repo.LayPhongTheoTen(TenPhong);
}
public static bool KiemTraTenTrung(int MaPhong, string TenPhong)
{
PhongRepository Repo = new PhongRepository();
return Repo.KiemTraTenTrung(MaPhong, TenPhong);
}
public static List<PhongDTO> LayDanhSachPhongDaThue()
{
List<PhongDTO> lst = new List<PhongDTO>();
try
{
PhongRepository obj = new PhongRepository();
lst = obj.LayDanhSachPhongDaThue();
}
catch (System.Exception)
{
}
return lst;
}
public static List<PhongDTO> LayDanhSachPhongDaThueTuList(List<PhongDTO> Lst)
{
int MaDaThue = TinhTrangDTO.MaDaThue;
//tu 1 danh sach cac phong, ham se loc ra nhung phong chua duoc thue va tra ve dang list
List<PhongDTO> newList = new List<PhongDTO>();
for (int i = 0; i < Lst.Count; i++)
{
if (Lst[i].MaTinhTrang == MaDaThue)
{
newList.Add(Lst[i]);
}
}
return newList;
}
public static List<PhongDTO> LayDanhSachPhongDaThueTuList(List<PhongDTO> Lst, int MaLoaiPhong)
{
//tu 1 danh sach cac phong, ham se loc ra nhung phong chua duoc thue cua loai phong va tra ve dang list
List<PhongDTO> NewList = new List<PhongDTO>();
for (int i = 0; i < Lst.Count; i++)
{
if (Lst[i].MaLoaiPhong == MaLoaiPhong)
{
NewList.Add(Lst[i]);
}
}
return Business.PhongService.LayDanhSachPhongDaThueTuList(NewList);
}
public static List<PhongDTO> LayDanhSachPhongChuaThueTuList(List<PhongDTO> Lst)
{
//tu 1 danh sach cac phong, ham se loc ra nhung phong chua duoc thue va tra ve dang list
List<PhongDTO> newList = new List<PhongDTO>();
int MaChuaThue = TinhTrangDTO.MaChuaThue;
for (int i = 0; i < Lst.Count; i++)
{
if (Lst[i].MaTinhTrang == MaChuaThue)
{
newList.Add(Lst[i]);
}
}
return newList;
}
public static List<PhongDTO> LayDanhSachPhongChuaThueTuList(List<PhongDTO> Lst, int MaLoaiPhong)
{
//tu 1 danh sach cac phong, ham se loc ra nhung phong chua duoc thue cua loai phong va tra ve dang list
List<PhongDTO> NewList = new List<PhongDTO>();
for (int i = 0; i < Lst.Count; i++)
{
if (Lst[i].MaLoaiPhong == MaLoaiPhong)
{
NewList.Add(Lst[i]);
}
}
return Business.PhongService.LayDanhSachPhongChuaThueTuList(NewList);
}
public static List<PhongDTO> LayDanhSachPhongTheoLoai(int iMaLoaiPhong)
{
Data.PhongRepository Repo = new PhongRepository();
return Repo.LayDanhSachPhongTheoLoai(iMaLoaiPhong);
}
public static int KiemTraMaPhongTrongListPhong(int MaPhong, List<PhongDTO> Lst)
{
//tra ve -1 neu khong tim thay, tra ve vi tri phong neu tim thay
for (int i = 0; i < Lst.Count; i++)
{
if (MaPhong == Lst[i].MaPhong)
{
return i;
}
}
return -1;
}
public static int TimViTriPhongTrongListPhong(int MaPhong, List<PhongDTO> Lst)
{
for (int i = 0; i < Lst.Count; i++)
{
if (MaPhong == Lst[i].MaPhong)
{
return i;
}
}
return -1;//khong tim thay
}
//////////////////////////////////////////////////////////
static public DataTable ConvertListPhongDTOToDataTable( List<PhongDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaPhong");
dt.Columns.Add( "TenPhong");
dt.Columns.Add( "MaLoaiPhong");
dt.Columns.Add( "GhiChu");
dt.Columns.Add( "MaTinhTrang");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaPhong,
lst[i].TenPhong,
lst[i].MaLoaiPhong,
lst[i].GhiChu,
lst[i].MaTinhTrang
);
}
return dt;
}
static public int GetIdentity()
{
Data.PhongRepository repo = new PhongRepository();
return repo.GetIdentity();
}
static public int Count()
{
return PhongRepository.Count();
}
public static bool Them(PhongDTO objDTO)
{
PhongRepository repo = new PhongRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaPhong, bool XoaKhoaNgoai=false)
{
PhongRepository Repo = new PhongRepository();
return Repo.Xoa(MaPhong,XoaKhoaNgoai);
}
public static void CapNhat(PhongDTO objDTO)
{
try
{
PhongRepository Repo = new PhongRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<PhongDTO> LayDanhSach()
{
List<PhongDTO> lst = new List<PhongDTO>();
try
{
PhongRepository obj = new PhongRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<PhongDTO> LayDanhSach(int Start, int Record)
{
Data.PhongRepository repo = new PhongRepository();
return repo.LayDanhSach(Start, Record);
}
public static PhongDTO LayTheoMa(int MaPhong)
{
PhongDTO objDTO = new PhongDTO();
try
{
PhongRepository Repo = new PhongRepository();
objDTO = Repo.LayTheoMa(MaPhong);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai TinhTrang
//
static public List<PhongDTO> LayDanhSachTheoMaTinhTrang( int MaTinhTrang)
{
Data.PhongRepository repo = new PhongRepository();
return repo.LayDanhSachTheoMaTinhTrang( MaTinhTrang);
}
static public void XoaTheoMaTinhTrang( int MaTinhTrang, bool XoaKhoaNgoai=false)
{
Data.PhongRepository repo = new PhongRepository();
repo.XoaTheoMaTinhTrang( MaTinhTrang,XoaKhoaNgoai);
}
//
//Khoa ngoai LoaiPhong
//
static public List<PhongDTO> LayDanhSachTheoMaLoaiPhong( int MaLoaiPhong)
{
Data.PhongRepository repo = new PhongRepository();
return repo.LayDanhSachTheoMaLoaiPhong( MaLoaiPhong);
}
static public void XoaTheoMaLoaiPhong( int MaLoaiPhong, bool XoaKhoaNgoai=false)
{
Data.PhongRepository repo = new PhongRepository();
repo.XoaTheoMaLoaiPhong( MaLoaiPhong,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.Phong.cs
|
C#
|
asf20
| 8,446
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class ThamSoService
{
//////////////////////////////////////////////////////////
// Enter code your here //
public static int SoLoaiPhongToiDa()
{
ThamSoRepository repo = new ThamSoRepository();
return repo.SoLoaiPhongToiDa();
}
public static int SoKhachToiDa()
{
ThamSoRepository repo = new ThamSoRepository();
return repo.SokhachToiDa();
}
public static double PhuThuSoLuongKhach(List<KhachHangDTO> lst)
{
ThamSoRepository repo = new ThamSoRepository();
return repo.PhuThuSoLuongKhach(lst);
}
public static double PhuThuKhachNuocNgoai(List<KhachHangDTO> lst)
{
ThamSoRepository repo = new ThamSoRepository();
return repo.PhuThuKhachNuocNgoai(lst);
}
//////////////////////////////////////////////////////////
static public DataTable ConvertListThamSoDTOToDataTable( List<ThamSoDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaThamSo");
dt.Columns.Add( "TenThamSo");
dt.Columns.Add( "GiaTri");
dt.Columns.Add( "GhiChu");
dt.Columns.Add( "SuDung");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaThamSo,
lst[i].TenThamSo,
lst[i].GiaTri,
lst[i].GhiChu,
lst[i].SuDung
);
}
return dt;
}
static public int GetIdentity()
{
Data.ThamSoRepository repo = new ThamSoRepository();
return repo.GetIdentity();
}
static public int Count()
{
return ThamSoRepository.Count();
}
public static bool Them(ThamSoDTO objDTO)
{
ThamSoRepository repo = new ThamSoRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaThamSo, bool XoaKhoaNgoai=false)
{
ThamSoRepository Repo = new ThamSoRepository();
return Repo.Xoa(MaThamSo,XoaKhoaNgoai);
}
public static void CapNhat(ThamSoDTO objDTO)
{
try
{
ThamSoRepository Repo = new ThamSoRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<ThamSoDTO> LayDanhSach()
{
List<ThamSoDTO> lst = new List<ThamSoDTO>();
try
{
ThamSoRepository obj = new ThamSoRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<ThamSoDTO> LayDanhSach(int Start, int Record)
{
Data.ThamSoRepository repo = new ThamSoRepository();
return repo.LayDanhSach(Start, Record);
}
public static ThamSoDTO LayTheoMa(int MaThamSo)
{
ThamSoDTO objDTO = new ThamSoDTO();
try
{
ThamSoRepository Repo = new ThamSoRepository();
objDTO = Repo.LayTheoMa(MaThamSo);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.ThamSo.cs
|
C#
|
asf20
| 4,002
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class ChiTietMatDoSuDungPhongService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListChiTietMatDoSuDungPhongDTOToDataTable( List<ChiTietMatDoSuDungPhongDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaChiTietMatDoPhong");
dt.Columns.Add( "MaPhong");
dt.Columns.Add( "MaMatDoPhong");
dt.Columns.Add( "SoNgayThue");
dt.Columns.Add( "TyLe");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaChiTietMatDoPhong,
lst[i].MaPhong,
lst[i].MaMatDoPhong,
lst[i].SoNgayThue,
lst[i].TyLe
);
}
return dt;
}
static public int GetIdentity()
{
Data.ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
return repo.GetIdentity();
}
static public int Count()
{
return ChiTietMatDoSuDungPhongRepository.Count();
}
public static bool Them(ChiTietMatDoSuDungPhongDTO objDTO)
{
ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaChiTietMatDoSuDungPhong, bool XoaKhoaNgoai=false)
{
ChiTietMatDoSuDungPhongRepository Repo = new ChiTietMatDoSuDungPhongRepository();
return Repo.Xoa(MaChiTietMatDoSuDungPhong,XoaKhoaNgoai);
}
public static void CapNhat(ChiTietMatDoSuDungPhongDTO objDTO)
{
try
{
ChiTietMatDoSuDungPhongRepository Repo = new ChiTietMatDoSuDungPhongRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<ChiTietMatDoSuDungPhongDTO> LayDanhSach()
{
List<ChiTietMatDoSuDungPhongDTO> lst = new List<ChiTietMatDoSuDungPhongDTO>();
try
{
ChiTietMatDoSuDungPhongRepository obj = new ChiTietMatDoSuDungPhongRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<ChiTietMatDoSuDungPhongDTO> LayDanhSach(int Start, int Record)
{
Data.ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
return repo.LayDanhSach(Start, Record);
}
public static ChiTietMatDoSuDungPhongDTO LayTheoMa(int MaChiTietMatDoSuDungPhong)
{
ChiTietMatDoSuDungPhongDTO objDTO = new ChiTietMatDoSuDungPhongDTO();
try
{
ChiTietMatDoSuDungPhongRepository Repo = new ChiTietMatDoSuDungPhongRepository();
objDTO = Repo.LayTheoMa(MaChiTietMatDoSuDungPhong);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai MatDoSuDungPhong
//
static public List<ChiTietMatDoSuDungPhongDTO> LayDanhSachTheoMaMatDoSuDungPhong( int MaMatDoSuDungPhong)
{
Data.ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
return repo.LayDanhSachTheoMaMatDoSuDungPhong( MaMatDoSuDungPhong);
}
static public void XoaTheoMaMatDoSuDungPhong( int MaMatDoSuDungPhong, bool XoaKhoaNgoai=false)
{
Data.ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
repo.XoaTheoMaMatDoSuDungPhong( MaMatDoSuDungPhong,XoaKhoaNgoai);
}
//
//Khoa ngoai Phong
//
static public List<ChiTietMatDoSuDungPhongDTO> LayDanhSachTheoMaPhong( int MaPhong)
{
Data.ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
return repo.LayDanhSachTheoMaPhong( MaPhong);
}
static public void XoaTheoMaPhong( int MaPhong, bool XoaKhoaNgoai=false)
{
Data.ChiTietMatDoSuDungPhongRepository repo = new ChiTietMatDoSuDungPhongRepository();
repo.XoaTheoMaPhong( MaPhong,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.ChiTietMatDoSuDungPhong.cs
|
C#
|
asf20
| 5,038
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
namespace Business
{
public class spt_fallback_dbService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public int GetIdentity()
{
Data.spt_fallback_dbRepository repo = new spt_fallback_dbRepository();
return repo.GetIdentity();
}
static public int Count()
{
return spt_fallback_dbRepository.Count();
}
public static void Them(spt_fallback_dbDTO objDTO)
{
try
{
spt_fallback_dbRepository repo = new spt_fallback_dbRepository();
repo.Them(objDTO);
}
catch (System.Exception )
{
}
}
public static void Xoa(int Maspt_fallback_db)
{
try
{
spt_fallback_dbRepository Repo = new spt_fallback_dbRepository();
Repo.Xoa(Maspt_fallback_db);
}
catch (System.Exception )
{
}
}
public static void CapNhat(spt_fallback_dbDTO objDTO)
{
try
{
spt_fallback_dbRepository Repo = new spt_fallback_dbRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<spt_fallback_dbDTO> LayDanhSach()
{
List<spt_fallback_dbDTO> lst = new List<spt_fallback_dbDTO>();
try
{
spt_fallback_dbRepository obj = new spt_fallback_dbRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<spt_fallback_dbDTO> LayDanhSach(int Start, int Record)
{
Data.spt_fallback_dbRepository repo = new spt_fallback_dbRepository();
return repo.LayDanhSach(Start, Record);
}
public static spt_fallback_dbDTO LayTheoMa(int Maspt_fallback_db)
{
spt_fallback_dbDTO objDTO = new spt_fallback_dbDTO();
try
{
spt_fallback_dbRepository Repo = new spt_fallback_dbRepository();
objDTO = Repo.LayTheoMa(Maspt_fallback_db);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.spt_fallback_db.cs
|
C#
|
asf20
| 2,920
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class PhieuThueService
{
//////////////////////////////////////////////////////////
// Enter code your here //
static public PhieuThueDTO LayPhieuThueHienTaiCuaPhong(int MaPhong)
{
PhieuThueRepository Repo = new PhieuThueRepository();
return Repo.LayPhieuThueHienTaiCuaPhong(MaPhong);
}
//////////////////////////////////////////////////////////
static public DataTable ConvertListPhieuThueDTOToDataTable( List<PhieuThueDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaPhieuThue");
dt.Columns.Add( "NgayBatDauThue");
dt.Columns.Add( "MaPhong");
dt.Columns.Add( "NgayKetThuc");
dt.Columns.Add( "DonGia");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaPhieuThue,
lst[i].NgayBatDauThue,
lst[i].MaPhong,
lst[i].NgayKetThuc,
lst[i].DonGia
);
}
return dt;
}
static public int GetIdentity()
{
Data.PhieuThueRepository repo = new PhieuThueRepository();
return repo.GetIdentity();
}
static public int Count()
{
return PhieuThueRepository.Count();
}
public static bool Them(PhieuThueDTO objDTO)
{
PhieuThueRepository repo = new PhieuThueRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaPhieuThue, bool XoaKhoaNgoai=false)
{
PhieuThueRepository Repo = new PhieuThueRepository();
return Repo.Xoa(MaPhieuThue,XoaKhoaNgoai);
}
public static void CapNhat(PhieuThueDTO objDTO)
{
try
{
PhieuThueRepository Repo = new PhieuThueRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<PhieuThueDTO> LayDanhSach()
{
List<PhieuThueDTO> lst = new List<PhieuThueDTO>();
try
{
PhieuThueRepository obj = new PhieuThueRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<PhieuThueDTO> LayDanhSach(int Start, int Record)
{
Data.PhieuThueRepository repo = new PhieuThueRepository();
return repo.LayDanhSach(Start, Record);
}
public static PhieuThueDTO LayTheoMa(int MaPhieuThue)
{
PhieuThueDTO objDTO = new PhieuThueDTO();
try
{
PhieuThueRepository Repo = new PhieuThueRepository();
objDTO = Repo.LayTheoMa(MaPhieuThue);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai Phong
//
static public List<PhieuThueDTO> LayDanhSachTheoMaPhong( int MaPhong)
{
Data.PhieuThueRepository repo = new PhieuThueRepository();
return repo.LayDanhSachTheoMaPhong( MaPhong);
}
static public void XoaTheoMaPhong( int MaPhong, bool XoaKhoaNgoai=false)
{
Data.PhieuThueRepository repo = new PhieuThueRepository();
repo.XoaTheoMaPhong( MaPhong,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.PhieuThue.cs
|
C#
|
asf20
| 4,052
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
namespace Business
{
public class spt_fallback_devService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public int GetIdentity()
{
Data.spt_fallback_devRepository repo = new spt_fallback_devRepository();
return repo.GetIdentity();
}
static public int Count()
{
return spt_fallback_devRepository.Count();
}
public static void Them(spt_fallback_devDTO objDTO)
{
try
{
spt_fallback_devRepository repo = new spt_fallback_devRepository();
repo.Them(objDTO);
}
catch (System.Exception )
{
}
}
public static void Xoa(int Maspt_fallback_dev)
{
try
{
spt_fallback_devRepository Repo = new spt_fallback_devRepository();
Repo.Xoa(Maspt_fallback_dev);
}
catch (System.Exception )
{
}
}
public static void CapNhat(spt_fallback_devDTO objDTO)
{
try
{
spt_fallback_devRepository Repo = new spt_fallback_devRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<spt_fallback_devDTO> LayDanhSach()
{
List<spt_fallback_devDTO> lst = new List<spt_fallback_devDTO>();
try
{
spt_fallback_devRepository obj = new spt_fallback_devRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<spt_fallback_devDTO> LayDanhSach(int Start, int Record)
{
Data.spt_fallback_devRepository repo = new spt_fallback_devRepository();
return repo.LayDanhSach(Start, Record);
}
public static spt_fallback_devDTO LayTheoMa(int Maspt_fallback_dev)
{
spt_fallback_devDTO objDTO = new spt_fallback_devDTO();
try
{
spt_fallback_devRepository Repo = new spt_fallback_devRepository();
objDTO = Repo.LayTheoMa(Maspt_fallback_dev);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.spt_fallback_dev.cs
|
C#
|
asf20
| 2,949
|
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Business")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Business")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("764a55ff-af0c-476d-bd35-37522ab7c925")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Properties/AssemblyInfo.cs
|
C#
|
asf20
| 1,428
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class ChucVuService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListChucVuDTOToDataTable( List<ChucVuDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaChucVu");
dt.Columns.Add( "TenChucVu");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaChucVu,
lst[i].TenChucVu
);
}
return dt;
}
static public int GetIdentity()
{
Data.ChucVuRepository repo = new ChucVuRepository();
return repo.GetIdentity();
}
static public int Count()
{
return ChucVuRepository.Count();
}
public static bool Them(ChucVuDTO objDTO)
{
ChucVuRepository repo = new ChucVuRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaChucVu, bool XoaKhoaNgoai=false)
{
ChucVuRepository Repo = new ChucVuRepository();
return Repo.Xoa(MaChucVu,XoaKhoaNgoai);
}
public static void CapNhat(ChucVuDTO objDTO)
{
try
{
ChucVuRepository Repo = new ChucVuRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<ChucVuDTO> LayDanhSach()
{
List<ChucVuDTO> lst = new List<ChucVuDTO>();
try
{
ChucVuRepository obj = new ChucVuRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<ChucVuDTO> LayDanhSach(int Start, int Record)
{
Data.ChucVuRepository repo = new ChucVuRepository();
return repo.LayDanhSach(Start, Record);
}
public static ChucVuDTO LayTheoMa(int MaChucVu)
{
ChucVuDTO objDTO = new ChucVuDTO();
try
{
ChucVuRepository Repo = new ChucVuRepository();
objDTO = Repo.LayTheoMa(MaChucVu);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.ChucVu.cs
|
C#
|
asf20
| 2,984
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class HoaDonService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListHoaDonDTOToDataTable( List<HoaDonDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaHoaDon");
dt.Columns.Add( "TriGia");
dt.Columns.Add( "MaKhachHang");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaHoaDon,
lst[i].TriGia,
lst[i].MaKhachHang
);
}
return dt;
}
static public int GetIdentity()
{
Data.HoaDonRepository repo = new HoaDonRepository();
return repo.GetIdentity();
}
static public int Count()
{
return HoaDonRepository.Count();
}
public static bool Them(HoaDonDTO objDTO)
{
HoaDonRepository repo = new HoaDonRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaHoaDon, bool XoaKhoaNgoai=false)
{
HoaDonRepository Repo = new HoaDonRepository();
return Repo.Xoa(MaHoaDon,XoaKhoaNgoai);
}
public static void CapNhat(HoaDonDTO objDTO)
{
try
{
HoaDonRepository Repo = new HoaDonRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<HoaDonDTO> LayDanhSach()
{
List<HoaDonDTO> lst = new List<HoaDonDTO>();
try
{
HoaDonRepository obj = new HoaDonRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<HoaDonDTO> LayDanhSach(int Start, int Record)
{
Data.HoaDonRepository repo = new HoaDonRepository();
return repo.LayDanhSach(Start, Record);
}
public static HoaDonDTO LayTheoMa(int MaHoaDon)
{
HoaDonDTO objDTO = new HoaDonDTO();
try
{
HoaDonRepository Repo = new HoaDonRepository();
objDTO = Repo.LayTheoMa(MaHoaDon);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai KhachHang
//
static public List<HoaDonDTO> LayDanhSachTheoMaKhachHang( int MaKhachHang)
{
Data.HoaDonRepository repo = new HoaDonRepository();
return repo.LayDanhSachTheoMaKhachHang( MaKhachHang);
}
static public void XoaTheoMaKhachHang( int MaKhachHang, bool XoaKhoaNgoai=false)
{
Data.HoaDonRepository repo = new HoaDonRepository();
repo.XoaTheoMaKhachHang( MaKhachHang,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.HoaDon.cs
|
C#
|
asf20
| 3,594
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class LoaiPhongService
{
//////////////////////////////////////////////////////////
// Enter code your here //
public static int KiemTraMaLoaiPhongTrongListLoaiPhong(int MaLoaiPhong, List<LoaiPhongDTO> Lst)
{
//tra ve -1 neu khong tim thay, tra ve vi tri phong neu tim thay
for (int i = 0; i < Lst.Count; i++)
{
if (MaLoaiPhong == Lst[i].MaLoaiPhong)
{
return i;
}
}
return -1;
}
public static int TimViTriLoaiPhongTrongList(int MaLoaiPhong, List<LoaiPhongDTO> Lst)
{
for (int i = 0; i < Lst.Count; i++)
{
if (MaLoaiPhong == Lst[i].MaLoaiPhong)
{
return i;
}
}
return -1;
}
public static bool KiemTraTenTrung(int MaLoaiPhong, string TenLoaiPhong)
{
LoaiPhongRepository Repo = new LoaiPhongRepository();
return Repo.KiemTraTenTrung(MaLoaiPhong, TenLoaiPhong);
}
public static LoaiPhongDTO LayTheoTen(string TenLoaiPhong)
{
LoaiPhongDTO objDTO = null;
try
{
LoaiPhongRepository Repo = new LoaiPhongRepository();
objDTO = Repo.LayTheoTen(TenLoaiPhong);
}
catch (System.Exception)
{
}
return objDTO;
}
//////////////////////////////////////////////////////////
static public DataTable ConvertListLoaiPhongDTOToDataTable( List<LoaiPhongDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaLoaiPhong");
dt.Columns.Add( "TenLoaiPhong");
dt.Columns.Add( "DonGia");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaLoaiPhong,
lst[i].TenLoaiPhong,
lst[i].DonGia
);
}
return dt;
}
static public int GetIdentity()
{
Data.LoaiPhongRepository repo = new LoaiPhongRepository();
return repo.GetIdentity();
}
static public int Count()
{
return LoaiPhongRepository.Count();
}
public static bool Them(LoaiPhongDTO objDTO)
{
LoaiPhongRepository repo = new LoaiPhongRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaLoaiPhong, bool XoaKhoaNgoai=false)
{
LoaiPhongRepository Repo = new LoaiPhongRepository();
return Repo.Xoa(MaLoaiPhong,XoaKhoaNgoai);
}
public static void CapNhat(LoaiPhongDTO objDTO)
{
try
{
LoaiPhongRepository Repo = new LoaiPhongRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<LoaiPhongDTO> LayDanhSach()
{
List<LoaiPhongDTO> lst = new List<LoaiPhongDTO>();
try
{
LoaiPhongRepository obj = new LoaiPhongRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<LoaiPhongDTO> LayDanhSach(int Start, int Record)
{
Data.LoaiPhongRepository repo = new LoaiPhongRepository();
return repo.LayDanhSach(Start, Record);
}
public static LoaiPhongDTO LayTheoMa(int MaLoaiPhong)
{
LoaiPhongDTO objDTO = new LoaiPhongDTO();
try
{
LoaiPhongRepository Repo = new LoaiPhongRepository();
objDTO = Repo.LayTheoMa(MaLoaiPhong);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.LoaiPhong.cs
|
C#
|
asf20
| 4,583
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class KhachHangService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListKhachHangDTOToDataTable( List<KhachHangDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaKhachHang");
dt.Columns.Add( "HoTen");
dt.Columns.Add( "MaLoaiKhachHang");
dt.Columns.Add( "CMND");
dt.Columns.Add( "DiaChi");
dt.Columns.Add( "DanhNghia");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaKhachHang,
lst[i].HoTen,
lst[i].MaLoaiKhachHang,
lst[i].CMND,
lst[i].DiaChi,
lst[i].DanhNghia
);
}
return dt;
}
static public int GetIdentity()
{
Data.KhachHangRepository repo = new KhachHangRepository();
return repo.GetIdentity();
}
static public int Count()
{
return KhachHangRepository.Count();
}
public static bool Them(KhachHangDTO objDTO)
{
KhachHangRepository repo = new KhachHangRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaKhachHang, bool XoaKhoaNgoai=false)
{
KhachHangRepository Repo = new KhachHangRepository();
return Repo.Xoa(MaKhachHang,XoaKhoaNgoai);
}
public static void CapNhat(KhachHangDTO objDTO)
{
try
{
KhachHangRepository Repo = new KhachHangRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<KhachHangDTO> LayDanhSach()
{
List<KhachHangDTO> lst = new List<KhachHangDTO>();
try
{
KhachHangRepository obj = new KhachHangRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<KhachHangDTO> LayDanhSach(int Start, int Record)
{
Data.KhachHangRepository repo = new KhachHangRepository();
return repo.LayDanhSach(Start, Record);
}
public static KhachHangDTO LayTheoMa(int MaKhachHang)
{
KhachHangDTO objDTO = new KhachHangDTO();
try
{
KhachHangRepository Repo = new KhachHangRepository();
objDTO = Repo.LayTheoMa(MaKhachHang);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai LoaiKhachHang
//
static public List<KhachHangDTO> LayDanhSachTheoMaLoaiKhachHang( int MaLoaiKhachHang)
{
Data.KhachHangRepository repo = new KhachHangRepository();
return repo.LayDanhSachTheoMaLoaiKhachHang( MaLoaiKhachHang);
}
static public void XoaTheoMaLoaiKhachHang( int MaLoaiKhachHang, bool XoaKhoaNgoai=false)
{
Data.KhachHangRepository repo = new KhachHangRepository();
repo.XoaTheoMaLoaiKhachHang( MaLoaiKhachHang,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.KhachHang.cs
|
C#
|
asf20
| 4,004
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
namespace Business
{
public class spt_fallback_usgService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public int GetIdentity()
{
Data.spt_fallback_usgRepository repo = new spt_fallback_usgRepository();
return repo.GetIdentity();
}
static public int Count()
{
return spt_fallback_usgRepository.Count();
}
public static void Them(spt_fallback_usgDTO objDTO)
{
try
{
spt_fallback_usgRepository repo = new spt_fallback_usgRepository();
repo.Them(objDTO);
}
catch (System.Exception )
{
}
}
public static void Xoa(int Maspt_fallback_usg)
{
try
{
spt_fallback_usgRepository Repo = new spt_fallback_usgRepository();
Repo.Xoa(Maspt_fallback_usg);
}
catch (System.Exception )
{
}
}
public static void CapNhat(spt_fallback_usgDTO objDTO)
{
try
{
spt_fallback_usgRepository Repo = new spt_fallback_usgRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<spt_fallback_usgDTO> LayDanhSach()
{
List<spt_fallback_usgDTO> lst = new List<spt_fallback_usgDTO>();
try
{
spt_fallback_usgRepository obj = new spt_fallback_usgRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<spt_fallback_usgDTO> LayDanhSach(int Start, int Record)
{
Data.spt_fallback_usgRepository repo = new spt_fallback_usgRepository();
return repo.LayDanhSach(Start, Record);
}
public static spt_fallback_usgDTO LayTheoMa(int Maspt_fallback_usg)
{
spt_fallback_usgDTO objDTO = new spt_fallback_usgDTO();
try
{
spt_fallback_usgRepository Repo = new spt_fallback_usgRepository();
objDTO = Repo.LayTheoMa(Maspt_fallback_usg);
}
catch (System.Exception )
{
}
return objDTO;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.spt_fallback_usg.cs
|
C#
|
asf20
| 2,949
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;
using System.Data;
namespace Business
{
public class ChiTietPhieuThueService
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
static public DataTable ConvertListChiTietPhieuThueDTOToDataTable( List<ChiTietPhieuThueDTO> lst)
{
DataTable dt = new DataTable();
dt.Columns.Add( "MaChiTietPhieuThue");
dt.Columns.Add( "MaKhachHang");
dt.Columns.Add( "MaPhieuThue");
for( int i = 0; i < lst.Count; i ++)
{
dt.Rows.Add(
lst[i].MaChiTietPhieuThue,
lst[i].MaKhachHang,
lst[i].MaPhieuThue
);
}
return dt;
}
static public int GetIdentity()
{
Data.ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
return repo.GetIdentity();
}
static public int Count()
{
return ChiTietPhieuThueRepository.Count();
}
public static bool Them(ChiTietPhieuThueDTO objDTO)
{
ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
return repo.Them(objDTO);
}
public static bool Xoa(int MaChiTietPhieuThue, bool XoaKhoaNgoai=false)
{
ChiTietPhieuThueRepository Repo = new ChiTietPhieuThueRepository();
return Repo.Xoa(MaChiTietPhieuThue,XoaKhoaNgoai);
}
public static void CapNhat(ChiTietPhieuThueDTO objDTO)
{
try
{
ChiTietPhieuThueRepository Repo = new ChiTietPhieuThueRepository();
Repo.CapNhat(objDTO);
}
catch (System.Exception )
{
}
}
public static List<ChiTietPhieuThueDTO> LayDanhSach()
{
List<ChiTietPhieuThueDTO> lst = new List<ChiTietPhieuThueDTO>();
try
{
ChiTietPhieuThueRepository obj = new ChiTietPhieuThueRepository();
lst = obj.LayDanhSach();
}
catch (System.Exception )
{
}
return lst;
}
static public List<ChiTietPhieuThueDTO> LayDanhSach(int Start, int Record)
{
Data.ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
return repo.LayDanhSach(Start, Record);
}
public static ChiTietPhieuThueDTO LayTheoMa(int MaChiTietPhieuThue)
{
ChiTietPhieuThueDTO objDTO = new ChiTietPhieuThueDTO();
try
{
ChiTietPhieuThueRepository Repo = new ChiTietPhieuThueRepository();
objDTO = Repo.LayTheoMa(MaChiTietPhieuThue);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai PhieuThue
//
static public List<ChiTietPhieuThueDTO> LayDanhSachTheoMaPhieuThue( int MaPhieuThue)
{
Data.ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
return repo.LayDanhSachTheoMaPhieuThue( MaPhieuThue);
}
static public void XoaTheoMaPhieuThue( int MaPhieuThue, bool XoaKhoaNgoai=false)
{
Data.ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
repo.XoaTheoMaPhieuThue( MaPhieuThue,XoaKhoaNgoai);
}
//
//Khoa ngoai KhachHang
//
static public List<ChiTietPhieuThueDTO> LayDanhSachTheoMaKhachHang( int MaKhachHang)
{
Data.ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
return repo.LayDanhSachTheoMaKhachHang( MaKhachHang);
}
static public void XoaTheoMaKhachHang( int MaKhachHang, bool XoaKhoaNgoai=false)
{
Data.ChiTietPhieuThueRepository repo = new ChiTietPhieuThueRepository();
repo.XoaTheoMaKhachHang( MaKhachHang,XoaKhoaNgoai);
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Business/Service.ChiTietPhieuThue.cs
|
C#
|
asf20
| 4,556
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class NhanVienRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static NhanVienDTO CreateNhanVienDTOFromNhanVienEF(NhanVien objEf) // EF -> DTO
{
NhanVienDTO objDTO = new NhanVienDTO();
Mapper.CreateMap<NhanVien, NhanVienDTO>();
objDTO = Mapper.Map<NhanVien, NhanVienDTO>(objEf);
return objDTO;
}
public static NhanVien CreateNhanVienEFFromNhanVienDTO(NhanVienDTO objDTO) //DTO -> EF
{
NhanVien objEF = new NhanVien();
Mapper.CreateMap<NhanVienDTO, NhanVien>();
objEF = Mapper.Map<NhanVienDTO, NhanVien>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.NhanVienList
select x.MaNhanVien).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.NhanVienList
orderby x.MaNhanVien descending
select x.MaNhanVien;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(NhanVienDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
NhanVien objEF = CreateNhanVienEFFromNhanVienDTO(objDTO);
context.AddToNhanVienList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(NhanVienDTO objDTO)
{
try
{
NhanVien objEF = CreateNhanVienEFFromNhanVienDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.NhanVienList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<NhanVienDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.NhanVienList
orderby x.MaNhanVien
select x).Skip(Start - 1).Take(Record);
List<NhanVienDTO> lst = new List<NhanVienDTO>();
foreach (var obj in query)
{
NhanVienDTO lp = NhanVienRepository.CreateNhanVienDTOFromNhanVienEF(obj);
lst.Add(lp);
}
return lst;
}
public List<NhanVienDTO> LayDanhSach()//lay tat ca danh sach
{
List<NhanVienDTO> lst = new List<NhanVienDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from NhanVien in context.NhanVienList
select NhanVien;
foreach (var objEf in query)
{
NhanVienDTO objDTO = CreateNhanVienDTOFromNhanVienEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public NhanVienDTO LayTheoMa(int MaNhanVien)
{
NhanVienDTO objDTO = new NhanVienDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from NhanVien in context.NhanVienList
where NhanVien.MaNhanVien == MaNhanVien
select NhanVien;
NhanVien objEF = query.First();
objDTO = CreateNhanVienDTOFromNhanVienEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai ChucVu
//
public List<NhanVienDTO> LayDanhSachTheoMaChucVu( int MaChucVu)
{
List<NhanVienDTO> lst = new List<NhanVienDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from NhanVien in context.NhanVienList
where NhanVien.MaChucVu == MaChucVu
select NhanVien;
foreach (var objEf in query)
{
NhanVienDTO objDTO = CreateNhanVienDTOFromNhanVienEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaChucVu( int MaChucVu, bool XoaKhoaNgoai=false)
{
List<NhanVienDTO> lst = this.LayDanhSachTheoMaChucVu( MaChucVu);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaNhanVien;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaNhanVien, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.NhanVienList
where x.MaNhanVien == MaNhanVien
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.NhanVien.cs
|
C#
|
asf20
| 6,838
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class KhachHangRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
// kiem tra khach nuopc ngoai //
public bool KiemTraKhachNuocNgoai(KhachHangDTO obj)
{
if (obj.MaLoaiKhachHang == LoaiKhachHangDTO.MaKhachNuocNgoai)
return true;
return false;
}
public bool KiemTraKhachNuocNgoai(List<KhachHangDTO> lst)
{
for (int i = 0; i < lst.Count; i++)
{
if (this.KiemTraKhachNuocNgoai(lst[i]) == true)
return true;
}
return false;
}
//////////////////////////////////////////////////////////
public static KhachHangDTO CreateKhachHangDTOFromKhachHangEF(KhachHang objEf) // EF -> DTO
{
KhachHangDTO objDTO = new KhachHangDTO();
Mapper.CreateMap<KhachHang, KhachHangDTO>();
objDTO = Mapper.Map<KhachHang, KhachHangDTO>(objEf);
return objDTO;
}
public static KhachHang CreateKhachHangEFFromKhachHangDTO(KhachHangDTO objDTO) //DTO -> EF
{
KhachHang objEF = new KhachHang();
Mapper.CreateMap<KhachHangDTO, KhachHang>();
objEF = Mapper.Map<KhachHangDTO, KhachHang>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.KhachHangList
select x.MaKhachHang).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.KhachHangList
orderby x.MaKhachHang descending
select x.MaKhachHang;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(KhachHangDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
KhachHang objEF = CreateKhachHangEFFromKhachHangDTO(objDTO);
context.AddToKhachHangList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(KhachHangDTO objDTO)
{
try
{
KhachHang objEF = CreateKhachHangEFFromKhachHangDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.KhachHangList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<KhachHangDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.KhachHangList
orderby x.MaKhachHang
select x).Skip(Start - 1).Take(Record);
List<KhachHangDTO> lst = new List<KhachHangDTO>();
foreach (var obj in query)
{
KhachHangDTO lp = KhachHangRepository.CreateKhachHangDTOFromKhachHangEF(obj);
lst.Add(lp);
}
return lst;
}
public List<KhachHangDTO> LayDanhSach()//lay tat ca danh sach
{
List<KhachHangDTO> lst = new List<KhachHangDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from KhachHang in context.KhachHangList
select KhachHang;
foreach (var objEf in query)
{
KhachHangDTO objDTO = CreateKhachHangDTOFromKhachHangEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public KhachHangDTO LayTheoMa(int MaKhachHang)
{
KhachHangDTO objDTO = new KhachHangDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from KhachHang in context.KhachHangList
where KhachHang.MaKhachHang == MaKhachHang
select KhachHang;
KhachHang objEF = query.First();
objDTO = CreateKhachHangDTOFromKhachHangEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai LoaiKhachHang
//
public List<KhachHangDTO> LayDanhSachTheoMaLoaiKhachHang( int MaLoaiKhachHang)
{
List<KhachHangDTO> lst = new List<KhachHangDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from KhachHang in context.KhachHangList
where KhachHang.MaLoaiKhachHang == MaLoaiKhachHang
select KhachHang;
foreach (var objEf in query)
{
KhachHangDTO objDTO = CreateKhachHangDTOFromKhachHangEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaLoaiKhachHang( int MaLoaiKhachHang, bool XoaKhoaNgoai=false)
{
List<KhachHangDTO> lst = this.LayDanhSachTheoMaLoaiKhachHang( MaLoaiKhachHang);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaKhachHang;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaKhachHang, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
ChiTietPhieuThueRepository ChiTietPhieuThueRepo = new ChiTietPhieuThueRepository();
ChiTietPhieuThueRepo.XoaTheoMaKhachHang(MaKhachHang, XoaKhoaNgoai);
HoaDonRepository HoaDonRepo = new HoaDonRepository();
HoaDonRepo.XoaTheoMaKhachHang(MaKhachHang, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.KhachHangList
where x.MaKhachHang == MaKhachHang
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.KhachHang.cs
|
C#
|
asf20
| 8,012
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class PhieuThueRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
public PhieuThueDTO LayPhieuThueHienTaiCuaPhong(int MaPhong)
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.PhieuThueList
orderby x.MaPhieuThue descending
select x).First();
PhieuThueDTO pt = new PhieuThueDTO();
if (query != null)
{
pt = PhieuThueRepository.CreatePhieuThueDTOFromPhieuThueEF(query);
}
return pt;
}
//////////////////////////////////////////////////////////
public static PhieuThueDTO CreatePhieuThueDTOFromPhieuThueEF(PhieuThue objEf) // EF -> DTO
{
PhieuThueDTO objDTO = new PhieuThueDTO();
Mapper.CreateMap<PhieuThue, PhieuThueDTO>();
objDTO = Mapper.Map<PhieuThue, PhieuThueDTO>(objEf);
return objDTO;
}
public static PhieuThue CreatePhieuThueEFFromPhieuThueDTO(PhieuThueDTO objDTO) //DTO -> EF
{
PhieuThue objEF = new PhieuThue();
Mapper.CreateMap<PhieuThueDTO, PhieuThue>();
objEF = Mapper.Map<PhieuThueDTO, PhieuThue>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.PhieuThueList
select x.MaPhieuThue).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.PhieuThueList
orderby x.MaPhieuThue descending
select x.MaPhieuThue;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(PhieuThueDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
PhieuThue objEF = CreatePhieuThueEFFromPhieuThueDTO(objDTO);
context.AddToPhieuThueList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(PhieuThueDTO objDTO)
{
try
{
PhieuThue objEF = CreatePhieuThueEFFromPhieuThueDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.PhieuThueList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<PhieuThueDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.PhieuThueList
orderby x.MaPhieuThue
select x).Skip(Start - 1).Take(Record);
List<PhieuThueDTO> lst = new List<PhieuThueDTO>();
foreach (var obj in query)
{
PhieuThueDTO lp = PhieuThueRepository.CreatePhieuThueDTOFromPhieuThueEF(obj);
lst.Add(lp);
}
return lst;
}
public List<PhieuThueDTO> LayDanhSach()//lay tat ca danh sach
{
List<PhieuThueDTO> lst = new List<PhieuThueDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from PhieuThue in context.PhieuThueList
select PhieuThue;
foreach (var objEf in query)
{
PhieuThueDTO objDTO = CreatePhieuThueDTOFromPhieuThueEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public PhieuThueDTO LayTheoMa(int MaPhieuThue)
{
PhieuThueDTO objDTO = new PhieuThueDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from PhieuThue in context.PhieuThueList
where PhieuThue.MaPhieuThue == MaPhieuThue
select PhieuThue;
PhieuThue objEF = query.First();
objDTO = CreatePhieuThueDTOFromPhieuThueEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai Phong
//
public List<PhieuThueDTO> LayDanhSachTheoMaPhong( int MaPhong)
{
List<PhieuThueDTO> lst = new List<PhieuThueDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from PhieuThue in context.PhieuThueList
where PhieuThue.MaPhong == MaPhong
select PhieuThue;
foreach (var objEf in query)
{
PhieuThueDTO objDTO = CreatePhieuThueDTOFromPhieuThueEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaPhong( int MaPhong, bool XoaKhoaNgoai=false)
{
List<PhieuThueDTO> lst = this.LayDanhSachTheoMaPhong( MaPhong);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaPhieuThue;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaPhieuThue, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
ChiTietHoaDonRepository ChiTietHoaDonRepo = new ChiTietHoaDonRepository();
ChiTietHoaDonRepo.XoaTheoMaPhieuThue(MaPhieuThue, XoaKhoaNgoai);
ChiTietPhieuThueRepository ChiTietPhieuThueRepo = new ChiTietPhieuThueRepository();
ChiTietPhieuThueRepo.XoaTheoMaPhieuThue(MaPhieuThue, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.PhieuThueList
where x.MaPhieuThue == MaPhieuThue
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.PhieuThue.cs
|
C#
|
asf20
| 7,863
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Data
{
public class ContextFactory
{
protected static QuanLyKhachSanEntities context = null;
private ContextFactory()
{
}
public static QuanLyKhachSanEntities GetInstance()
{
if(context == null)
{
context = new QuanLyKhachSanEntities();
}
return context;
}
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/ContextFactory.cs
|
C#
|
asf20
| 510
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class ChucVuRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static ChucVuDTO CreateChucVuDTOFromChucVuEF(ChucVu objEf) // EF -> DTO
{
ChucVuDTO objDTO = new ChucVuDTO();
Mapper.CreateMap<ChucVu, ChucVuDTO>();
objDTO = Mapper.Map<ChucVu, ChucVuDTO>(objEf);
return objDTO;
}
public static ChucVu CreateChucVuEFFromChucVuDTO(ChucVuDTO objDTO) //DTO -> EF
{
ChucVu objEF = new ChucVu();
Mapper.CreateMap<ChucVuDTO, ChucVu>();
objEF = Mapper.Map<ChucVuDTO, ChucVu>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.ChucVuList
select x.MaChucVu).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.ChucVuList
orderby x.MaChucVu descending
select x.MaChucVu;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(ChucVuDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
ChucVu objEF = CreateChucVuEFFromChucVuDTO(objDTO);
context.AddToChucVuList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(ChucVuDTO objDTO)
{
try
{
ChucVu objEF = CreateChucVuEFFromChucVuDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.ChucVuList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<ChucVuDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.ChucVuList
orderby x.MaChucVu
select x).Skip(Start - 1).Take(Record);
List<ChucVuDTO> lst = new List<ChucVuDTO>();
foreach (var obj in query)
{
ChucVuDTO lp = ChucVuRepository.CreateChucVuDTOFromChucVuEF(obj);
lst.Add(lp);
}
return lst;
}
public List<ChucVuDTO> LayDanhSach()//lay tat ca danh sach
{
List<ChucVuDTO> lst = new List<ChucVuDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChucVu in context.ChucVuList
select ChucVu;
foreach (var objEf in query)
{
ChucVuDTO objDTO = CreateChucVuDTOFromChucVuEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public ChucVuDTO LayTheoMa(int MaChucVu)
{
ChucVuDTO objDTO = new ChucVuDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChucVu in context.ChucVuList
where ChucVu.MaChucVu == MaChucVu
select ChucVu;
ChucVu objEF = query.First();
objDTO = CreateChucVuDTOFromChucVuEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaChucVu, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
NhanVienRepository NhanVienRepo = new NhanVienRepository();
NhanVienRepo.XoaTheoMaChucVu(MaChucVu, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.ChucVuList
where x.MaChucVu == MaChucVu
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.ChucVu.cs
|
C#
|
asf20
| 5,739
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class TinhTrangRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static TinhTrangDTO CreateTinhTrangDTOFromTinhTrangEF(TinhTrang objEf) // EF -> DTO
{
TinhTrangDTO objDTO = new TinhTrangDTO();
Mapper.CreateMap<TinhTrang, TinhTrangDTO>();
objDTO = Mapper.Map<TinhTrang, TinhTrangDTO>(objEf);
return objDTO;
}
public static TinhTrang CreateTinhTrangEFFromTinhTrangDTO(TinhTrangDTO objDTO) //DTO -> EF
{
TinhTrang objEF = new TinhTrang();
Mapper.CreateMap<TinhTrangDTO, TinhTrang>();
objEF = Mapper.Map<TinhTrangDTO, TinhTrang>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.TinhTrangList
select x.MaTinhTrang).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.TinhTrangList
orderby x.MaTinhTrang descending
select x.MaTinhTrang;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(TinhTrangDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
TinhTrang objEF = CreateTinhTrangEFFromTinhTrangDTO(objDTO);
context.AddToTinhTrangList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(TinhTrangDTO objDTO)
{
try
{
TinhTrang objEF = CreateTinhTrangEFFromTinhTrangDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.TinhTrangList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<TinhTrangDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.TinhTrangList
orderby x.MaTinhTrang
select x).Skip(Start - 1).Take(Record);
List<TinhTrangDTO> lst = new List<TinhTrangDTO>();
foreach (var obj in query)
{
TinhTrangDTO lp = TinhTrangRepository.CreateTinhTrangDTOFromTinhTrangEF(obj);
lst.Add(lp);
}
return lst;
}
public List<TinhTrangDTO> LayDanhSach()//lay tat ca danh sach
{
List<TinhTrangDTO> lst = new List<TinhTrangDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from TinhTrang in context.TinhTrangList
select TinhTrang;
foreach (var objEf in query)
{
TinhTrangDTO objDTO = CreateTinhTrangDTOFromTinhTrangEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public TinhTrangDTO LayTheoMa(int MaTinhTrang)
{
TinhTrangDTO objDTO = new TinhTrangDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from TinhTrang in context.TinhTrangList
where TinhTrang.MaTinhTrang == MaTinhTrang
select TinhTrang;
TinhTrang objEF = query.First();
objDTO = CreateTinhTrangDTOFromTinhTrangEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaTinhTrang, bool XoaKhoaNgoai = false)
{
try
{
if (XoaKhoaNgoai == true)
{
PhongRepository PhongRepo = new PhongRepository();
PhongRepo.XoaTheoMaTinhTrang(MaTinhTrang, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.TinhTrangList
where x.MaTinhTrang == MaTinhTrang
select x;
if (query.First() != null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception)
{
return false;
}
}
//public bool Xoa(int MaTinhTrang, bool XoaKhoaNgoai=false)
//{
// try
// {
// if( XoaKhoaNgoai == true)
// {
// PhongRepository PhongRepo = new PhongRepository();
// PhongRepo.XoaTheoMaTinhTrang(MaTinhTrang, XoaKhoaNgoai);
// }
// QuanLyKhachSanEntities context = ContextFactory.GetInstance();
// var query = from x in context.TinhTrangList
// where x.MaTinhTrang == MaTinhTrang
// select x;
// if(query.First()!= null)
// {
// context.DeleteObject(query.First());
// context.SaveChanges();
// }
// return true;
// }
// catch (System.Exception )
// {
// return false;
// }
//}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.TinhTrang.cs
|
C#
|
asf20
| 6,924
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class PhongRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
public PhongDTO LayPhongTheoTen(string TenPhong)
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var qr = from ph in Context.PhongList
where ph.TenPhong == TenPhong
select ph;
PhongDTO p = null;
try
{
if (qr.First() != null)
{
p = PhongRepository.CreatePhongDTOFromPhongEF(qr.First());
}
}
catch { }
return p;
}
public bool KiemTraTenTrung(int MaPhong, string TenPhong)
{
PhongDTO lp = this.LayPhongTheoTen(TenPhong);
if (lp == null)
return false;
if (lp.MaPhong == MaPhong)
return false;
return true;
}
public List<PhongDTO> LayDanhSachPhongDaThue()
{
int MaTinhTrangDaThue = 1;
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.PhongList
orderby x.TenPhong
where x.MaTinhTrang == MaTinhTrangDaThue
select x);
List<PhongDTO> lst = new List<PhongDTO>();
foreach (var obj in query)
{
PhongDTO lp = PhongRepository.CreatePhongDTOFromPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<PhongDTO> LayDanhSachPhongTheoLoai(int MaLoaiPhong)
{
List<PhongDTO> lst = new List<PhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from Phong in context.PhongList
where Phong.MaLoaiPhong == MaLoaiPhong
select Phong;
foreach (var objEf in query)
{
PhongDTO objDTO = CreatePhongDTOFromPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{ }
return lst;
}
//////////////////////////////////////////////////////////
public static PhongDTO CreatePhongDTOFromPhongEF(Phong objEf) // EF -> DTO
{
PhongDTO objDTO = new PhongDTO();
Mapper.CreateMap<Phong, PhongDTO>();
objDTO = Mapper.Map<Phong, PhongDTO>(objEf);
return objDTO;
}
public static Phong CreatePhongEFFromPhongDTO(PhongDTO objDTO) //DTO -> EF
{
Phong objEF = new Phong();
Mapper.CreateMap<PhongDTO, Phong>();
objEF = Mapper.Map<PhongDTO, Phong>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int Count = (from x in Context.PhongList
select x.MaPhong).Count();
return Count;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.PhongList
orderby x.MaPhong descending
select x.MaPhong;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(PhongDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
Phong objEF = CreatePhongEFFromPhongDTO(objDTO);
context.AddToPhongList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(PhongDTO objDTO)
{
try
{
Phong objEF = CreatePhongEFFromPhongDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.PhongList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<PhongDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.PhongList
orderby x.MaPhong
select x).Skip(Start - 1).Take(Record);
List<PhongDTO> lst = new List<PhongDTO>();
foreach (var obj in query)
{
PhongDTO lp = PhongRepository.CreatePhongDTOFromPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<PhongDTO> LayDanhSach()//lay tat ca danh sach
{
List<PhongDTO> lst = new List<PhongDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from Phong in context.PhongList
select Phong;
foreach (var objEf in query)
{
PhongDTO objDTO = CreatePhongDTOFromPhongEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public PhongDTO LayTheoMa(int MaPhong)
{
PhongDTO objDTO = new PhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from Phong in context.PhongList
where Phong.MaPhong == MaPhong
select Phong;
Phong objEF = query.First();
objDTO = CreatePhongDTOFromPhongEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai TinhTrang
//
public List<PhongDTO> LayDanhSachTheoMaTinhTrang( int MaTinhTrang)
{
List<PhongDTO> lst = new List<PhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from Phong in context.PhongList
where Phong.MaTinhTrang == MaTinhTrang
select Phong;
foreach (var objEf in query)
{
PhongDTO objDTO = CreatePhongDTOFromPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaTinhTrang( int MaTinhTrang, bool XoaKhoaNgoai=false)
{
List<PhongDTO> lst = this.LayDanhSachTheoMaTinhTrang( MaTinhTrang);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaPhong;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
//
//Khoa ngoai LoaiPhong
//
public List<PhongDTO> LayDanhSachTheoMaLoaiPhong( int MaLoaiPhong)
{
List<PhongDTO> lst = new List<PhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from Phong in context.PhongList
where Phong.MaLoaiPhong == MaLoaiPhong
select Phong;
foreach (var objEf in query)
{
PhongDTO objDTO = CreatePhongDTOFromPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaLoaiPhong( int MaLoaiPhong, bool XoaKhoaNgoai=false)
{
List<PhongDTO> lst = this.LayDanhSachTheoMaLoaiPhong( MaLoaiPhong);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaPhong;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaPhong, bool XoaKhoaNgoai=false)
{
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();// ContextFactory.GetInstance();
try
{
if( XoaKhoaNgoai == true)
{
ChiTietMatDoSuDungPhongRepository ChiTietMatDoSuDungPhongRepo = new ChiTietMatDoSuDungPhongRepository();
ChiTietMatDoSuDungPhongRepo.XoaTheoMaPhong(MaPhong, XoaKhoaNgoai);
PhieuThueRepository PhieuThueRepo = new PhieuThueRepository();
PhieuThueRepo.XoaTheoMaPhong(MaPhong, XoaKhoaNgoai);
}
var query = from x in context.PhongList
where x.MaPhong == MaPhong
select x;
if(query.First()!= null)
{
Phong ef = (Phong)query.First();
context.DeleteObject(ef);
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.Phong.cs
|
C#
|
asf20
| 10,512
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class ThamSoRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//lay so luong khach toi da trong moi phong
int iMax = 99999999;
public int SokhachToiDa()
{
ThamSoDTO ts = this.LayTheoMa(1);
if (ts == null)
return iMax;
if (ts.SuDung == true)
{
return int.Parse(ts.GiaTri.ToString());
}
return iMax;
}
public int SoLoaiPhongToiDa()
{
ThamSoDTO ts = this.LayTheoMa(ThamSoDTO.MaThamSoSoLoaiPhongToiDa);
if (ts.SuDung == true)
{
int val = int.Parse(ts.GiaTri.ToString());
return val;
}
return iMax;
}
//tinh ti le phu thu so luong khach
public double PhuThuSoLuongKhach(List<KhachHangDTO> lst)
{
int iSoKhachToiDa = this.SokhachToiDa();
if (iSoKhachToiDa <= 0 || iSoKhachToiDa > lst.Count)
{
return 0;
}
ThamSoDTO ts = this.LayTheoMa(ThamSoDTO.MaThamSoPhuThuSoLuongKhach);
if (ts == null)
return 0;
if (ts.SuDung == true)
{
return ts.GiaTri;
}
return 0;
}
//tinh phu thu khach nuoc ngoai
public double PhuThuKhachNuocNgoai(List<KhachHangDTO> lst)
{
KhachHangRepository repo = new KhachHangRepository();
if (repo.KiemTraKhachNuocNgoai(lst) == false)
return 1;
ThamSoDTO ts = this.LayTheoMa(ThamSoDTO.MaThamSoPhuThuKhachNuocNgoai);
if (ts == null || ts.SuDung == false)
return 1;
if (ts.SuDung == true)
{
return ts.GiaTri;
}
return 1;
}
//////////////////////////////////////////////////////////
public static ThamSoDTO CreateThamSoDTOFromThamSoEF(ThamSo objEf) // EF -> DTO
{
ThamSoDTO objDTO = new ThamSoDTO();
Mapper.CreateMap<ThamSo, ThamSoDTO>();
objDTO = Mapper.Map<ThamSo, ThamSoDTO>(objEf);
return objDTO;
}
public static ThamSo CreateThamSoEFFromThamSoDTO(ThamSoDTO objDTO) //DTO -> EF
{
ThamSo objEF = new ThamSo();
Mapper.CreateMap<ThamSoDTO, ThamSo>();
objEF = Mapper.Map<ThamSoDTO, ThamSo>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.ThamSoList
select x.MaThamSo).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.ThamSoList
orderby x.MaThamSo descending
select x.MaThamSo;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(ThamSoDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
ThamSo objEF = CreateThamSoEFFromThamSoDTO(objDTO);
context.AddToThamSoList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(ThamSoDTO objDTO)
{
try
{
ThamSo objEF = CreateThamSoEFFromThamSoDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.ThamSoList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<ThamSoDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.ThamSoList
orderby x.MaThamSo
select x).Skip(Start - 1).Take(Record);
List<ThamSoDTO> lst = new List<ThamSoDTO>();
foreach (var obj in query)
{
ThamSoDTO lp = ThamSoRepository.CreateThamSoDTOFromThamSoEF(obj);
lst.Add(lp);
}
return lst;
}
public List<ThamSoDTO> LayDanhSach()//lay tat ca danh sach
{
List<ThamSoDTO> lst = new List<ThamSoDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ThamSo in context.ThamSoList
select ThamSo;
foreach (var objEf in query)
{
ThamSoDTO objDTO = CreateThamSoDTOFromThamSoEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public ThamSoDTO LayTheoMa(int MaThamSo)
{
ThamSoDTO objDTO = new ThamSoDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ThamSo in context.ThamSoList
where ThamSo.MaThamSo == MaThamSo
select ThamSo;
ThamSo objEF = query.First();
objDTO = CreateThamSoDTOFromThamSoEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaThamSo, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.ThamSoList
where x.MaThamSo == MaThamSo
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.ThamSo.cs
|
C#
|
asf20
| 7,413
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class ChiTietHoaDonRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static ChiTietHoaDonDTO CreateChiTietHoaDonDTOFromChiTietHoaDonEF(ChiTietHoaDon objEf) // EF -> DTO
{
ChiTietHoaDonDTO objDTO = new ChiTietHoaDonDTO();
Mapper.CreateMap<ChiTietHoaDon, ChiTietHoaDonDTO>();
objDTO = Mapper.Map<ChiTietHoaDon, ChiTietHoaDonDTO>(objEf);
return objDTO;
}
public static ChiTietHoaDon CreateChiTietHoaDonEFFromChiTietHoaDonDTO(ChiTietHoaDonDTO objDTO) //DTO -> EF
{
ChiTietHoaDon objEF = new ChiTietHoaDon();
Mapper.CreateMap<ChiTietHoaDonDTO, ChiTietHoaDon>();
objEF = Mapper.Map<ChiTietHoaDonDTO, ChiTietHoaDon>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.ChiTietHoaDonList
select x.MaChiTietHoaDon).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.ChiTietHoaDonList
orderby x.MaChiTietHoaDon descending
select x.MaChiTietHoaDon;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(ChiTietHoaDonDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
ChiTietHoaDon objEF = CreateChiTietHoaDonEFFromChiTietHoaDonDTO(objDTO);
context.AddToChiTietHoaDonList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(ChiTietHoaDonDTO objDTO)
{
try
{
ChiTietHoaDon objEF = CreateChiTietHoaDonEFFromChiTietHoaDonDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.ChiTietHoaDonList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<ChiTietHoaDonDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.ChiTietHoaDonList
orderby x.MaChiTietHoaDon
select x).Skip(Start - 1).Take(Record);
List<ChiTietHoaDonDTO> lst = new List<ChiTietHoaDonDTO>();
foreach (var obj in query)
{
ChiTietHoaDonDTO lp = ChiTietHoaDonRepository.CreateChiTietHoaDonDTOFromChiTietHoaDonEF(obj);
lst.Add(lp);
}
return lst;
}
public List<ChiTietHoaDonDTO> LayDanhSach()//lay tat ca danh sach
{
List<ChiTietHoaDonDTO> lst = new List<ChiTietHoaDonDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietHoaDon in context.ChiTietHoaDonList
select ChiTietHoaDon;
foreach (var objEf in query)
{
ChiTietHoaDonDTO objDTO = CreateChiTietHoaDonDTOFromChiTietHoaDonEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public ChiTietHoaDonDTO LayTheoMa(int MaChiTietHoaDon)
{
ChiTietHoaDonDTO objDTO = new ChiTietHoaDonDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietHoaDon in context.ChiTietHoaDonList
where ChiTietHoaDon.MaChiTietHoaDon == MaChiTietHoaDon
select ChiTietHoaDon;
ChiTietHoaDon objEF = query.First();
objDTO = CreateChiTietHoaDonDTOFromChiTietHoaDonEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai HoaDon
//
public List<ChiTietHoaDonDTO> LayDanhSachTheoMaHoaDon( int MaHoaDon)
{
List<ChiTietHoaDonDTO> lst = new List<ChiTietHoaDonDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietHoaDon in context.ChiTietHoaDonList
where ChiTietHoaDon.MaHoaDon == MaHoaDon
select ChiTietHoaDon;
foreach (var objEf in query)
{
ChiTietHoaDonDTO objDTO = CreateChiTietHoaDonDTOFromChiTietHoaDonEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaHoaDon( int MaHoaDon, bool XoaKhoaNgoai=false)
{
List<ChiTietHoaDonDTO> lst = this.LayDanhSachTheoMaHoaDon( MaHoaDon);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietHoaDon;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
//
//Khoa ngoai PhieuThue
//
public List<ChiTietHoaDonDTO> LayDanhSachTheoMaPhieuThue( int MaPhieuThue)
{
List<ChiTietHoaDonDTO> lst = new List<ChiTietHoaDonDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietHoaDon in context.ChiTietHoaDonList
where ChiTietHoaDon.MaPhieuThue == MaPhieuThue
select ChiTietHoaDon;
foreach (var objEf in query)
{
ChiTietHoaDonDTO objDTO = CreateChiTietHoaDonDTOFromChiTietHoaDonEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaPhieuThue( int MaPhieuThue, bool XoaKhoaNgoai=false)
{
List<ChiTietHoaDonDTO> lst = this.LayDanhSachTheoMaPhieuThue( MaPhieuThue);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietHoaDon;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaChiTietHoaDon, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.ChiTietHoaDonList
where x.MaChiTietHoaDon == MaChiTietHoaDon
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.ChiTietHoaDon.cs
|
C#
|
asf20
| 8,461
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class HoaDonRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static HoaDonDTO CreateHoaDonDTOFromHoaDonEF(HoaDon objEf) // EF -> DTO
{
HoaDonDTO objDTO = new HoaDonDTO();
Mapper.CreateMap<HoaDon, HoaDonDTO>();
objDTO = Mapper.Map<HoaDon, HoaDonDTO>(objEf);
return objDTO;
}
public static HoaDon CreateHoaDonEFFromHoaDonDTO(HoaDonDTO objDTO) //DTO -> EF
{
HoaDon objEF = new HoaDon();
Mapper.CreateMap<HoaDonDTO, HoaDon>();
objEF = Mapper.Map<HoaDonDTO, HoaDon>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.HoaDonList
select x.MaHoaDon).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.HoaDonList
orderby x.MaHoaDon descending
select x.MaHoaDon;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(HoaDonDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
HoaDon objEF = CreateHoaDonEFFromHoaDonDTO(objDTO);
context.AddToHoaDonList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(HoaDonDTO objDTO)
{
try
{
HoaDon objEF = CreateHoaDonEFFromHoaDonDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.HoaDonList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<HoaDonDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.HoaDonList
orderby x.MaHoaDon
select x).Skip(Start - 1).Take(Record);
List<HoaDonDTO> lst = new List<HoaDonDTO>();
foreach (var obj in query)
{
HoaDonDTO lp = HoaDonRepository.CreateHoaDonDTOFromHoaDonEF(obj);
lst.Add(lp);
}
return lst;
}
public List<HoaDonDTO> LayDanhSach()//lay tat ca danh sach
{
List<HoaDonDTO> lst = new List<HoaDonDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from HoaDon in context.HoaDonList
select HoaDon;
foreach (var objEf in query)
{
HoaDonDTO objDTO = CreateHoaDonDTOFromHoaDonEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public HoaDonDTO LayTheoMa(int MaHoaDon)
{
HoaDonDTO objDTO = new HoaDonDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from HoaDon in context.HoaDonList
where HoaDon.MaHoaDon == MaHoaDon
select HoaDon;
HoaDon objEF = query.First();
objDTO = CreateHoaDonDTOFromHoaDonEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai KhachHang
//
public List<HoaDonDTO> LayDanhSachTheoMaKhachHang( int MaKhachHang)
{
List<HoaDonDTO> lst = new List<HoaDonDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from HoaDon in context.HoaDonList
where HoaDon.MaKhachHang == MaKhachHang
select HoaDon;
foreach (var objEf in query)
{
HoaDonDTO objDTO = CreateHoaDonDTOFromHoaDonEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaKhachHang( int MaKhachHang, bool XoaKhoaNgoai=false)
{
List<HoaDonDTO> lst = this.LayDanhSachTheoMaKhachHang( MaKhachHang);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaHoaDon;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaHoaDon, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
ChiTietHoaDonRepository ChiTietHoaDonRepo = new ChiTietHoaDonRepository();
ChiTietHoaDonRepo.XoaTheoMaHoaDon(MaHoaDon, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.HoaDonList
where x.MaHoaDon == MaHoaDon
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.HoaDon.cs
|
C#
|
asf20
| 6,883
|
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Data")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Data")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bc14d924-8e94-44c7-87ef-2a57544aef7a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Properties/AssemblyInfo.cs
|
C#
|
asf20
| 1,420
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class LoaiPhongRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
public LoaiPhongDTO LayTheoTen(string TenLoaiPhong)
{
LoaiPhongDTO objDTO = new LoaiPhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from LoaiPhong in context.LoaiPhongList
where LoaiPhong.TenLoaiPhong == TenLoaiPhong
select LoaiPhong;
LoaiPhong objEF = query.First();
objDTO = CreateLoaiPhongDTOFromLoaiPhongEF(objEF);
}
catch (System.Exception)
{
objDTO = null;
}
return objDTO;
}
public bool KiemTraTenTrung(int MaLoaiPhong, string TenLoaiPhong)
{
LoaiPhongDTO lp = this.LayTheoTen(TenLoaiPhong);
if (lp == null)
return false;
if (lp.MaLoaiPhong == MaLoaiPhong)
return false;
return true;
}
//////////////////////////////////////////////////////////
public static LoaiPhongDTO CreateLoaiPhongDTOFromLoaiPhongEF(LoaiPhong objEf) // EF -> DTO
{
LoaiPhongDTO objDTO = new LoaiPhongDTO();
Mapper.CreateMap<LoaiPhong, LoaiPhongDTO>();
objDTO = Mapper.Map<LoaiPhong, LoaiPhongDTO>(objEf);
return objDTO;
}
public static LoaiPhong CreateLoaiPhongEFFromLoaiPhongDTO(LoaiPhongDTO objDTO) //DTO -> EF
{
LoaiPhong objEF = new LoaiPhong();
Mapper.CreateMap<LoaiPhongDTO, LoaiPhong>();
objEF = Mapper.Map<LoaiPhongDTO, LoaiPhong>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.LoaiPhongList
select x.MaLoaiPhong).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.LoaiPhongList
orderby x.MaLoaiPhong descending
select x.MaLoaiPhong;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(LoaiPhongDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
LoaiPhong objEF = CreateLoaiPhongEFFromLoaiPhongDTO(objDTO);
context.AddToLoaiPhongList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(LoaiPhongDTO objDTO)
{
try
{
LoaiPhong objEF = CreateLoaiPhongEFFromLoaiPhongDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.LoaiPhongList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<LoaiPhongDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.LoaiPhongList
orderby x.MaLoaiPhong
select x).Skip(Start - 1).Take(Record);
List<LoaiPhongDTO> lst = new List<LoaiPhongDTO>();
foreach (var obj in query)
{
LoaiPhongDTO lp = LoaiPhongRepository.CreateLoaiPhongDTOFromLoaiPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<LoaiPhongDTO> LayDanhSach()//lay tat ca danh sach
{
List<LoaiPhongDTO> lst = new List<LoaiPhongDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from LoaiPhong in context.LoaiPhongList
select LoaiPhong;
foreach (var objEf in query)
{
LoaiPhongDTO objDTO = CreateLoaiPhongDTOFromLoaiPhongEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public LoaiPhongDTO LayTheoMa(int MaLoaiPhong)
{
LoaiPhongDTO objDTO = new LoaiPhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from LoaiPhong in context.LoaiPhongList
where LoaiPhong.MaLoaiPhong == MaLoaiPhong
select LoaiPhong;
LoaiPhong objEF = query.First();
objDTO = CreateLoaiPhongDTOFromLoaiPhongEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaLoaiPhong, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
ChiTietDoanhThuTheoLoaiPhongRepository ChiTietDoanhThuTheoLoaiPhongRepo = new ChiTietDoanhThuTheoLoaiPhongRepository();
ChiTietDoanhThuTheoLoaiPhongRepo.XoaTheoMaLoaiPhong(MaLoaiPhong, XoaKhoaNgoai);
PhongRepository PhongRepo = new PhongRepository();
PhongRepo.XoaTheoMaLoaiPhong(MaLoaiPhong, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.LoaiPhongList
where x.MaLoaiPhong == MaLoaiPhong
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.LoaiPhong.cs
|
C#
|
asf20
| 7,161
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class LoaiKhachHangRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static LoaiKhachHangDTO CreateLoaiKhachHangDTOFromLoaiKhachHangEF(LoaiKhachHang objEf) // EF -> DTO
{
LoaiKhachHangDTO objDTO = new LoaiKhachHangDTO();
Mapper.CreateMap<LoaiKhachHang, LoaiKhachHangDTO>();
objDTO = Mapper.Map<LoaiKhachHang, LoaiKhachHangDTO>(objEf);
return objDTO;
}
public static LoaiKhachHang CreateLoaiKhachHangEFFromLoaiKhachHangDTO(LoaiKhachHangDTO objDTO) //DTO -> EF
{
LoaiKhachHang objEF = new LoaiKhachHang();
Mapper.CreateMap<LoaiKhachHangDTO, LoaiKhachHang>();
objEF = Mapper.Map<LoaiKhachHangDTO, LoaiKhachHang>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.LoaiKhachHangList
select x.MaLoaiKhachHang).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.LoaiKhachHangList
orderby x.MaLoaiKhachHang descending
select x.MaLoaiKhachHang;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(LoaiKhachHangDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
LoaiKhachHang objEF = CreateLoaiKhachHangEFFromLoaiKhachHangDTO(objDTO);
context.AddToLoaiKhachHangList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(LoaiKhachHangDTO objDTO)
{
try
{
LoaiKhachHang objEF = CreateLoaiKhachHangEFFromLoaiKhachHangDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.LoaiKhachHangList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<LoaiKhachHangDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.LoaiKhachHangList
orderby x.MaLoaiKhachHang
select x).Skip(Start - 1).Take(Record);
List<LoaiKhachHangDTO> lst = new List<LoaiKhachHangDTO>();
foreach (var obj in query)
{
LoaiKhachHangDTO lp = LoaiKhachHangRepository.CreateLoaiKhachHangDTOFromLoaiKhachHangEF(obj);
lst.Add(lp);
}
return lst;
}
public List<LoaiKhachHangDTO> LayDanhSach()//lay tat ca danh sach
{
List<LoaiKhachHangDTO> lst = new List<LoaiKhachHangDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from LoaiKhachHang in context.LoaiKhachHangList
select LoaiKhachHang;
foreach (var objEf in query)
{
LoaiKhachHangDTO objDTO = CreateLoaiKhachHangDTOFromLoaiKhachHangEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public LoaiKhachHangDTO LayTheoMa(int MaLoaiKhachHang)
{
LoaiKhachHangDTO objDTO = new LoaiKhachHangDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from LoaiKhachHang in context.LoaiKhachHangList
where LoaiKhachHang.MaLoaiKhachHang == MaLoaiKhachHang
select LoaiKhachHang;
LoaiKhachHang objEF = query.First();
objDTO = CreateLoaiKhachHangDTOFromLoaiKhachHangEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaLoaiKhachHang, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
KhachHangRepository KhachHangRepo = new KhachHangRepository();
KhachHangRepo.XoaTheoMaLoaiKhachHang(MaLoaiKhachHang, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.LoaiKhachHangList
where x.MaLoaiKhachHang == MaLoaiKhachHang
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.LoaiKhachHang.cs
|
C#
|
asf20
| 6,254
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class MatDoSuDungPhongRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static MatDoSuDungPhongDTO CreateMatDoSuDungPhongDTOFromMatDoSuDungPhongEF(MatDoSuDungPhong objEf) // EF -> DTO
{
MatDoSuDungPhongDTO objDTO = new MatDoSuDungPhongDTO();
Mapper.CreateMap<MatDoSuDungPhong, MatDoSuDungPhongDTO>();
objDTO = Mapper.Map<MatDoSuDungPhong, MatDoSuDungPhongDTO>(objEf);
return objDTO;
}
public static MatDoSuDungPhong CreateMatDoSuDungPhongEFFromMatDoSuDungPhongDTO(MatDoSuDungPhongDTO objDTO) //DTO -> EF
{
MatDoSuDungPhong objEF = new MatDoSuDungPhong();
Mapper.CreateMap<MatDoSuDungPhongDTO, MatDoSuDungPhong>();
objEF = Mapper.Map<MatDoSuDungPhongDTO, MatDoSuDungPhong>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.MatDoSuDungPhongList
select x.MaMatDoPhong).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.MatDoSuDungPhongList
orderby x.MaMatDoPhong descending
select x.MaMatDoPhong;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(MatDoSuDungPhongDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
MatDoSuDungPhong objEF = CreateMatDoSuDungPhongEFFromMatDoSuDungPhongDTO(objDTO);
context.AddToMatDoSuDungPhongList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(MatDoSuDungPhongDTO objDTO)
{
try
{
MatDoSuDungPhong objEF = CreateMatDoSuDungPhongEFFromMatDoSuDungPhongDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.MatDoSuDungPhongList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<MatDoSuDungPhongDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.MatDoSuDungPhongList
orderby x.MaMatDoPhong
select x).Skip(Start - 1).Take(Record);
List<MatDoSuDungPhongDTO> lst = new List<MatDoSuDungPhongDTO>();
foreach (var obj in query)
{
MatDoSuDungPhongDTO lp = MatDoSuDungPhongRepository.CreateMatDoSuDungPhongDTOFromMatDoSuDungPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<MatDoSuDungPhongDTO> LayDanhSach()//lay tat ca danh sach
{
List<MatDoSuDungPhongDTO> lst = new List<MatDoSuDungPhongDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from MatDoSuDungPhong in context.MatDoSuDungPhongList
select MatDoSuDungPhong;
foreach (var objEf in query)
{
MatDoSuDungPhongDTO objDTO = CreateMatDoSuDungPhongDTOFromMatDoSuDungPhongEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public MatDoSuDungPhongDTO LayTheoMa(int MaMatDoSuDungPhong)
{
MatDoSuDungPhongDTO objDTO = new MatDoSuDungPhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from MatDoSuDungPhong in context.MatDoSuDungPhongList
where MatDoSuDungPhong.MaMatDoPhong == MaMatDoSuDungPhong
select MatDoSuDungPhong;
MatDoSuDungPhong objEF = query.First();
objDTO = CreateMatDoSuDungPhongDTOFromMatDoSuDungPhongEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaMatDoSuDungPhong, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
ChiTietMatDoSuDungPhongRepository ChiTietMatDoSuDungPhongRepo = new ChiTietMatDoSuDungPhongRepository();
ChiTietMatDoSuDungPhongRepo.XoaTheoMaMatDoSuDungPhong(MaMatDoSuDungPhong, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.MatDoSuDungPhongList
where x.MaMatDoPhong == MaMatDoSuDungPhong
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.MatDoSuDungPhong.cs
|
C#
|
asf20
| 6,493
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class ChiTietPhieuThueRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static ChiTietPhieuThueDTO CreateChiTietPhieuThueDTOFromChiTietPhieuThueEF(ChiTietPhieuThue objEf) // EF -> DTO
{
ChiTietPhieuThueDTO objDTO = new ChiTietPhieuThueDTO();
Mapper.CreateMap<ChiTietPhieuThue, ChiTietPhieuThueDTO>();
objDTO = Mapper.Map<ChiTietPhieuThue, ChiTietPhieuThueDTO>(objEf);
return objDTO;
}
public static ChiTietPhieuThue CreateChiTietPhieuThueEFFromChiTietPhieuThueDTO(ChiTietPhieuThueDTO objDTO) //DTO -> EF
{
ChiTietPhieuThue objEF = new ChiTietPhieuThue();
Mapper.CreateMap<ChiTietPhieuThueDTO, ChiTietPhieuThue>();
objEF = Mapper.Map<ChiTietPhieuThueDTO, ChiTietPhieuThue>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.ChiTietPhieuThueList
select x.MaChiTietPhieuThue).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.ChiTietPhieuThueList
orderby x.MaChiTietPhieuThue descending
select x.MaChiTietPhieuThue;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(ChiTietPhieuThueDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
ChiTietPhieuThue objEF = CreateChiTietPhieuThueEFFromChiTietPhieuThueDTO(objDTO);
context.AddToChiTietPhieuThueList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(ChiTietPhieuThueDTO objDTO)
{
try
{
ChiTietPhieuThue objEF = CreateChiTietPhieuThueEFFromChiTietPhieuThueDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.ChiTietPhieuThueList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<ChiTietPhieuThueDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.ChiTietPhieuThueList
orderby x.MaChiTietPhieuThue
select x).Skip(Start - 1).Take(Record);
List<ChiTietPhieuThueDTO> lst = new List<ChiTietPhieuThueDTO>();
foreach (var obj in query)
{
ChiTietPhieuThueDTO lp = ChiTietPhieuThueRepository.CreateChiTietPhieuThueDTOFromChiTietPhieuThueEF(obj);
lst.Add(lp);
}
return lst;
}
public List<ChiTietPhieuThueDTO> LayDanhSach()//lay tat ca danh sach
{
List<ChiTietPhieuThueDTO> lst = new List<ChiTietPhieuThueDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietPhieuThue in context.ChiTietPhieuThueList
select ChiTietPhieuThue;
foreach (var objEf in query)
{
ChiTietPhieuThueDTO objDTO = CreateChiTietPhieuThueDTOFromChiTietPhieuThueEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public ChiTietPhieuThueDTO LayTheoMa(int MaChiTietPhieuThue)
{
ChiTietPhieuThueDTO objDTO = new ChiTietPhieuThueDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietPhieuThue in context.ChiTietPhieuThueList
where ChiTietPhieuThue.MaChiTietPhieuThue == MaChiTietPhieuThue
select ChiTietPhieuThue;
ChiTietPhieuThue objEF = query.First();
objDTO = CreateChiTietPhieuThueDTOFromChiTietPhieuThueEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai PhieuThue
//
public List<ChiTietPhieuThueDTO> LayDanhSachTheoMaPhieuThue( int MaPhieuThue)
{
List<ChiTietPhieuThueDTO> lst = new List<ChiTietPhieuThueDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietPhieuThue in context.ChiTietPhieuThueList
where ChiTietPhieuThue.MaPhieuThue == MaPhieuThue
select ChiTietPhieuThue;
foreach (var objEf in query)
{
ChiTietPhieuThueDTO objDTO = CreateChiTietPhieuThueDTOFromChiTietPhieuThueEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaPhieuThue( int MaPhieuThue, bool XoaKhoaNgoai=false)
{
List<ChiTietPhieuThueDTO> lst = this.LayDanhSachTheoMaPhieuThue( MaPhieuThue);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietPhieuThue;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
//
//Khoa ngoai KhachHang
//
public List<ChiTietPhieuThueDTO> LayDanhSachTheoMaKhachHang( int MaKhachHang)
{
List<ChiTietPhieuThueDTO> lst = new List<ChiTietPhieuThueDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietPhieuThue in context.ChiTietPhieuThueList
where ChiTietPhieuThue.MaKhachHang == MaKhachHang
select ChiTietPhieuThue;
foreach (var objEf in query)
{
ChiTietPhieuThueDTO objDTO = CreateChiTietPhieuThueDTOFromChiTietPhieuThueEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaKhachHang( int MaKhachHang, bool XoaKhoaNgoai=false)
{
List<ChiTietPhieuThueDTO> lst = this.LayDanhSachTheoMaKhachHang( MaKhachHang);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietPhieuThue;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaChiTietPhieuThue, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.ChiTietPhieuThueList
where x.MaChiTietPhieuThue == MaChiTietPhieuThue
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.ChiTietPhieuThue.cs
|
C#
|
asf20
| 8,773
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class ChiTietDoanhThuTheoLoaiPhongRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static ChiTietDoanhThuTheoLoaiPhongDTO CreateChiTietDoanhThuTheoLoaiPhongDTOFromChiTietDoanhThuTheoLoaiPhongEF(ChiTietDoanhThuTheoLoaiPhong objEf) // EF -> DTO
{
ChiTietDoanhThuTheoLoaiPhongDTO objDTO = new ChiTietDoanhThuTheoLoaiPhongDTO();
Mapper.CreateMap<ChiTietDoanhThuTheoLoaiPhong, ChiTietDoanhThuTheoLoaiPhongDTO>();
objDTO = Mapper.Map<ChiTietDoanhThuTheoLoaiPhong, ChiTietDoanhThuTheoLoaiPhongDTO>(objEf);
return objDTO;
}
public static ChiTietDoanhThuTheoLoaiPhong CreateChiTietDoanhThuTheoLoaiPhongEFFromChiTietDoanhThuTheoLoaiPhongDTO(ChiTietDoanhThuTheoLoaiPhongDTO objDTO) //DTO -> EF
{
ChiTietDoanhThuTheoLoaiPhong objEF = new ChiTietDoanhThuTheoLoaiPhong();
Mapper.CreateMap<ChiTietDoanhThuTheoLoaiPhongDTO, ChiTietDoanhThuTheoLoaiPhong>();
objEF = Mapper.Map<ChiTietDoanhThuTheoLoaiPhongDTO, ChiTietDoanhThuTheoLoaiPhong>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.ChiTietDoanhThuTheoLoaiPhongList
select x.MaChiTietDoanhThu).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.ChiTietDoanhThuTheoLoaiPhongList
orderby x.MaChiTietDoanhThu descending
select x.MaChiTietDoanhThu;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(ChiTietDoanhThuTheoLoaiPhongDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
ChiTietDoanhThuTheoLoaiPhong objEF = CreateChiTietDoanhThuTheoLoaiPhongEFFromChiTietDoanhThuTheoLoaiPhongDTO(objDTO);
context.AddToChiTietDoanhThuTheoLoaiPhongList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(ChiTietDoanhThuTheoLoaiPhongDTO objDTO)
{
try
{
ChiTietDoanhThuTheoLoaiPhong objEF = CreateChiTietDoanhThuTheoLoaiPhongEFFromChiTietDoanhThuTheoLoaiPhongDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.ChiTietDoanhThuTheoLoaiPhongList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.ChiTietDoanhThuTheoLoaiPhongList
orderby x.MaChiTietDoanhThu
select x).Skip(Start - 1).Take(Record);
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = new List<ChiTietDoanhThuTheoLoaiPhongDTO>();
foreach (var obj in query)
{
ChiTietDoanhThuTheoLoaiPhongDTO lp = ChiTietDoanhThuTheoLoaiPhongRepository.CreateChiTietDoanhThuTheoLoaiPhongDTOFromChiTietDoanhThuTheoLoaiPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSach()//lay tat ca danh sach
{
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = new List<ChiTietDoanhThuTheoLoaiPhongDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietDoanhThuTheoLoaiPhong in context.ChiTietDoanhThuTheoLoaiPhongList
select ChiTietDoanhThuTheoLoaiPhong;
foreach (var objEf in query)
{
ChiTietDoanhThuTheoLoaiPhongDTO objDTO = CreateChiTietDoanhThuTheoLoaiPhongDTOFromChiTietDoanhThuTheoLoaiPhongEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public ChiTietDoanhThuTheoLoaiPhongDTO LayTheoMa(int MaChiTietDoanhThuTheoLoaiPhong)
{
ChiTietDoanhThuTheoLoaiPhongDTO objDTO = new ChiTietDoanhThuTheoLoaiPhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietDoanhThuTheoLoaiPhong in context.ChiTietDoanhThuTheoLoaiPhongList
where ChiTietDoanhThuTheoLoaiPhong.MaChiTietDoanhThu == MaChiTietDoanhThuTheoLoaiPhong
select ChiTietDoanhThuTheoLoaiPhong;
ChiTietDoanhThuTheoLoaiPhong objEF = query.First();
objDTO = CreateChiTietDoanhThuTheoLoaiPhongDTOFromChiTietDoanhThuTheoLoaiPhongEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai DoanhThuTheoLoaiPhong
//
public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSachTheoMaDoanhThuTheoLoaiPhong( int MaDoanhThuTheoLoaiPhong)
{
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = new List<ChiTietDoanhThuTheoLoaiPhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietDoanhThuTheoLoaiPhong in context.ChiTietDoanhThuTheoLoaiPhongList
where ChiTietDoanhThuTheoLoaiPhong.MaDoanhThu == MaDoanhThuTheoLoaiPhong
select ChiTietDoanhThuTheoLoaiPhong;
foreach (var objEf in query)
{
ChiTietDoanhThuTheoLoaiPhongDTO objDTO = CreateChiTietDoanhThuTheoLoaiPhongDTOFromChiTietDoanhThuTheoLoaiPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaDoanhThuTheoLoaiPhong( int MaDoanhThuTheoLoaiPhong, bool XoaKhoaNgoai=false)
{
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = this.LayDanhSachTheoMaDoanhThuTheoLoaiPhong( MaDoanhThuTheoLoaiPhong);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietDoanhThu;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
//
//Khoa ngoai LoaiPhong
//
public List<ChiTietDoanhThuTheoLoaiPhongDTO> LayDanhSachTheoMaLoaiPhong( int MaLoaiPhong)
{
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = new List<ChiTietDoanhThuTheoLoaiPhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietDoanhThuTheoLoaiPhong in context.ChiTietDoanhThuTheoLoaiPhongList
where ChiTietDoanhThuTheoLoaiPhong.MaLoaiPhong == MaLoaiPhong
select ChiTietDoanhThuTheoLoaiPhong;
foreach (var objEf in query)
{
ChiTietDoanhThuTheoLoaiPhongDTO objDTO = CreateChiTietDoanhThuTheoLoaiPhongDTOFromChiTietDoanhThuTheoLoaiPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaLoaiPhong( int MaLoaiPhong, bool XoaKhoaNgoai=false)
{
List<ChiTietDoanhThuTheoLoaiPhongDTO> lst = this.LayDanhSachTheoMaLoaiPhong( MaLoaiPhong);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietDoanhThu;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaChiTietDoanhThuTheoLoaiPhong, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.ChiTietDoanhThuTheoLoaiPhongList
where x.MaChiTietDoanhThu == MaChiTietDoanhThuTheoLoaiPhong
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.ChiTietDoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 9,900
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class DoanhThuTheoLoaiPhongRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static DoanhThuTheoLoaiPhongDTO CreateDoanhThuTheoLoaiPhongDTOFromDoanhThuTheoLoaiPhongEF(DoanhThuTheoLoaiPhong objEf) // EF -> DTO
{
DoanhThuTheoLoaiPhongDTO objDTO = new DoanhThuTheoLoaiPhongDTO();
Mapper.CreateMap<DoanhThuTheoLoaiPhong, DoanhThuTheoLoaiPhongDTO>();
objDTO = Mapper.Map<DoanhThuTheoLoaiPhong, DoanhThuTheoLoaiPhongDTO>(objEf);
return objDTO;
}
public static DoanhThuTheoLoaiPhong CreateDoanhThuTheoLoaiPhongEFFromDoanhThuTheoLoaiPhongDTO(DoanhThuTheoLoaiPhongDTO objDTO) //DTO -> EF
{
DoanhThuTheoLoaiPhong objEF = new DoanhThuTheoLoaiPhong();
Mapper.CreateMap<DoanhThuTheoLoaiPhongDTO, DoanhThuTheoLoaiPhong>();
objEF = Mapper.Map<DoanhThuTheoLoaiPhongDTO, DoanhThuTheoLoaiPhong>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.DoanhThuTheoLoaiPhongList
select x.MaDoanhThu).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.DoanhThuTheoLoaiPhongList
orderby x.MaDoanhThu descending
select x.MaDoanhThu;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(DoanhThuTheoLoaiPhongDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
DoanhThuTheoLoaiPhong objEF = CreateDoanhThuTheoLoaiPhongEFFromDoanhThuTheoLoaiPhongDTO(objDTO);
context.AddToDoanhThuTheoLoaiPhongList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(DoanhThuTheoLoaiPhongDTO objDTO)
{
try
{
DoanhThuTheoLoaiPhong objEF = CreateDoanhThuTheoLoaiPhongEFFromDoanhThuTheoLoaiPhongDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.DoanhThuTheoLoaiPhongList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<DoanhThuTheoLoaiPhongDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.DoanhThuTheoLoaiPhongList
orderby x.MaDoanhThu
select x).Skip(Start - 1).Take(Record);
List<DoanhThuTheoLoaiPhongDTO> lst = new List<DoanhThuTheoLoaiPhongDTO>();
foreach (var obj in query)
{
DoanhThuTheoLoaiPhongDTO lp = DoanhThuTheoLoaiPhongRepository.CreateDoanhThuTheoLoaiPhongDTOFromDoanhThuTheoLoaiPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<DoanhThuTheoLoaiPhongDTO> LayDanhSach()//lay tat ca danh sach
{
List<DoanhThuTheoLoaiPhongDTO> lst = new List<DoanhThuTheoLoaiPhongDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from DoanhThuTheoLoaiPhong in context.DoanhThuTheoLoaiPhongList
select DoanhThuTheoLoaiPhong;
foreach (var objEf in query)
{
DoanhThuTheoLoaiPhongDTO objDTO = CreateDoanhThuTheoLoaiPhongDTOFromDoanhThuTheoLoaiPhongEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public DoanhThuTheoLoaiPhongDTO LayTheoMa(int MaDoanhThuTheoLoaiPhong)
{
DoanhThuTheoLoaiPhongDTO objDTO = new DoanhThuTheoLoaiPhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from DoanhThuTheoLoaiPhong in context.DoanhThuTheoLoaiPhongList
where DoanhThuTheoLoaiPhong.MaDoanhThu == MaDoanhThuTheoLoaiPhong
select DoanhThuTheoLoaiPhong;
DoanhThuTheoLoaiPhong objEF = query.First();
objDTO = CreateDoanhThuTheoLoaiPhongDTOFromDoanhThuTheoLoaiPhongEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
public bool Xoa(int MaDoanhThuTheoLoaiPhong, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
ChiTietDoanhThuTheoLoaiPhongRepository ChiTietDoanhThuTheoLoaiPhongRepo = new ChiTietDoanhThuTheoLoaiPhongRepository();
ChiTietDoanhThuTheoLoaiPhongRepo.XoaTheoMaDoanhThuTheoLoaiPhong(MaDoanhThuTheoLoaiPhong, XoaKhoaNgoai);
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.DoanhThuTheoLoaiPhongList
where x.MaDoanhThu == MaDoanhThuTheoLoaiPhong
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.DoanhThuTheoLoaiPhong.cs
|
C#
|
asf20
| 6,836
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;
namespace Data
{
public class ChiTietMatDoSuDungPhongRepository
{
//////////////////////////////////////////////////////////
// Enter code your here //
//////////////////////////////////////////////////////////
public static ChiTietMatDoSuDungPhongDTO CreateChiTietMatDoSuDungPhongDTOFromChiTietMatDoSuDungPhongEF(ChiTietMatDoSuDungPhong objEf) // EF -> DTO
{
ChiTietMatDoSuDungPhongDTO objDTO = new ChiTietMatDoSuDungPhongDTO();
Mapper.CreateMap<ChiTietMatDoSuDungPhong, ChiTietMatDoSuDungPhongDTO>();
objDTO = Mapper.Map<ChiTietMatDoSuDungPhong, ChiTietMatDoSuDungPhongDTO>(objEf);
return objDTO;
}
public static ChiTietMatDoSuDungPhong CreateChiTietMatDoSuDungPhongEFFromChiTietMatDoSuDungPhongDTO(ChiTietMatDoSuDungPhongDTO objDTO) //DTO -> EF
{
ChiTietMatDoSuDungPhong objEF = new ChiTietMatDoSuDungPhong();
Mapper.CreateMap<ChiTietMatDoSuDungPhongDTO, ChiTietMatDoSuDungPhong>();
objEF = Mapper.Map<ChiTietMatDoSuDungPhongDTO, ChiTietMatDoSuDungPhong>(objDTO);
return objEF;
}
public static int Count() //Dem so luong cac bo du lieu trong bang
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
int qr = (from x in Context.ChiTietMatDoSuDungPhongList
select x.MaChiTietMatDoPhong).Count();
return qr;
}
public int GetIdentity() // tra ve gia tri ma moi them vo( gia tri Ma lon nhat trong Bang).
{
try
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = from x in Context.ChiTietMatDoSuDungPhongList
orderby x.MaChiTietMatDoPhong descending
select x.MaChiTietMatDoPhong;
var Ma = query.First();
return int.Parse(Ma.ToString());
}
catch
{
return 0;
}
}
public bool Them(ChiTietMatDoSuDungPhongDTO objDTO)
{
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
ChiTietMatDoSuDungPhong objEF = CreateChiTietMatDoSuDungPhongEFFromChiTietMatDoSuDungPhongDTO(objDTO);
context.AddToChiTietMatDoSuDungPhongList(objEF);
context.SaveChanges();
return true;
}
catch (System.Exception )
{
return false;
}
}
public void CapNhat(ChiTietMatDoSuDungPhongDTO objDTO)
{
try
{
ChiTietMatDoSuDungPhong objEF = CreateChiTietMatDoSuDungPhongEFFromChiTietMatDoSuDungPhongDTO(objDTO);
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
context.ChiTietMatDoSuDungPhongList.ApplyCurrentValues(objEF);
context.SaveChanges();
}
catch (System.Exception )
{
}
}
public List<ChiTietMatDoSuDungPhongDTO> LayDanhSach(int Start, int Record)//lay Record bo du lieu tu vi tri Start
{
QuanLyKhachSanEntities Context = ContextFactory.GetInstance();
var query = (from x in Context.ChiTietMatDoSuDungPhongList
orderby x.MaChiTietMatDoPhong
select x).Skip(Start - 1).Take(Record);
List<ChiTietMatDoSuDungPhongDTO> lst = new List<ChiTietMatDoSuDungPhongDTO>();
foreach (var obj in query)
{
ChiTietMatDoSuDungPhongDTO lp = ChiTietMatDoSuDungPhongRepository.CreateChiTietMatDoSuDungPhongDTOFromChiTietMatDoSuDungPhongEF(obj);
lst.Add(lp);
}
return lst;
}
public List<ChiTietMatDoSuDungPhongDTO> LayDanhSach()//lay tat ca danh sach
{
List<ChiTietMatDoSuDungPhongDTO> lst = new List<ChiTietMatDoSuDungPhongDTO>();
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietMatDoSuDungPhong in context.ChiTietMatDoSuDungPhongList
select ChiTietMatDoSuDungPhong;
foreach (var objEf in query)
{
ChiTietMatDoSuDungPhongDTO objDTO = CreateChiTietMatDoSuDungPhongDTOFromChiTietMatDoSuDungPhongEF(objEf);
lst.Add(objDTO);
}
return lst;
}
public ChiTietMatDoSuDungPhongDTO LayTheoMa(int MaChiTietMatDoSuDungPhong)
{
ChiTietMatDoSuDungPhongDTO objDTO = new ChiTietMatDoSuDungPhongDTO();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietMatDoSuDungPhong in context.ChiTietMatDoSuDungPhongList
where ChiTietMatDoSuDungPhong.MaChiTietMatDoPhong == MaChiTietMatDoSuDungPhong
select ChiTietMatDoSuDungPhong;
ChiTietMatDoSuDungPhong objEF = query.First();
objDTO = CreateChiTietMatDoSuDungPhongDTOFromChiTietMatDoSuDungPhongEF(objEF);
}
catch (System.Exception )
{
}
return objDTO;
}
//
//Khoa ngoai MatDoSuDungPhong
//
public List<ChiTietMatDoSuDungPhongDTO> LayDanhSachTheoMaMatDoSuDungPhong( int MaMatDoSuDungPhong)
{
List<ChiTietMatDoSuDungPhongDTO> lst = new List<ChiTietMatDoSuDungPhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietMatDoSuDungPhong in context.ChiTietMatDoSuDungPhongList
where ChiTietMatDoSuDungPhong.MaMatDoPhong == MaMatDoSuDungPhong
select ChiTietMatDoSuDungPhong;
foreach (var objEf in query)
{
ChiTietMatDoSuDungPhongDTO objDTO = CreateChiTietMatDoSuDungPhongDTOFromChiTietMatDoSuDungPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaMatDoSuDungPhong( int MaMatDoSuDungPhong, bool XoaKhoaNgoai=false)
{
List<ChiTietMatDoSuDungPhongDTO> lst = this.LayDanhSachTheoMaMatDoSuDungPhong( MaMatDoSuDungPhong);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietMatDoPhong;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
//
//Khoa ngoai Phong
//
public List<ChiTietMatDoSuDungPhongDTO> LayDanhSachTheoMaPhong( int MaPhong)
{
List<ChiTietMatDoSuDungPhongDTO> lst = new List<ChiTietMatDoSuDungPhongDTO>();
try
{
QuanLyKhachSanEntities context = ContextFactory.GetInstance();
var query = from ChiTietMatDoSuDungPhong in context.ChiTietMatDoSuDungPhongList
where ChiTietMatDoSuDungPhong.MaPhong == MaPhong
select ChiTietMatDoSuDungPhong;
foreach (var objEf in query)
{
ChiTietMatDoSuDungPhongDTO objDTO = CreateChiTietMatDoSuDungPhongDTOFromChiTietMatDoSuDungPhongEF(objEf);
lst.Add(objDTO);
}
}
catch
{}
return lst;
}
public void XoaTheoMaPhong( int MaPhong, bool XoaKhoaNgoai=false)
{
List<ChiTietMatDoSuDungPhongDTO> lst = this.LayDanhSachTheoMaPhong( MaPhong);
for( int i = 0; i < lst.Count; i++ )
{
int iMa = lst[i].MaChiTietMatDoPhong;
this.Xoa(iMa, XoaKhoaNgoai);
}
}
public bool Xoa(int MaChiTietMatDoSuDungPhong, bool XoaKhoaNgoai=false)
{
try
{
if( XoaKhoaNgoai == true)
{
}
QuanLyKhachSanEntities context = new QuanLyKhachSanEntities();
var query = from x in context.ChiTietMatDoSuDungPhongList
where x.MaChiTietMatDoPhong == MaChiTietMatDoSuDungPhong
select x;
if(query.First()!= null)
{
context.DeleteObject(query.First());
context.SaveChanges();
}
return true;
}
catch (System.Exception )
{
return false;
}
}
////////////////////////////////////////////////////////////////
}
}
|
1042034-tdhau-project1
|
trunk/src/1042009-1042034/Data/Repository.ChiTietMatDoSuDungPhong.cs
|
C#
|
asf20
| 9,405
|
public class fdf {
}
|
09accp2testcase
|
trunk/09accp2/src/fdf.java
|
Java
|
art
| 27
|
public @interface df {
}
|
09accp2testcase
|
trunk/09accp2/src/df.java
|
Java
|
art
| 31
|
public class fdfd {
}
|
09accp2testcase
|
trunk/09accp2/src/fdfd.java
|
Java
|
art
| 28
|
#!/bin/bash
#===============================================================================
# FILE: wrapper.sh
# USAGE: ./wrapper.sh executable [cmd-line-args]
# DESCRIPTION: Wraps the execution of a programm or script.
# Use with xterm: xterm -e wrapper.sh executable cmd-line-args
# This script is used by the plugin perl-support.vim.
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dr.-Ing. Fritz Mehner (Mn), mehner@fh-swf.de
# COMPANY: Fachhochschule Südwestfalen, Iserlohn
# CREATED: 23.11.2004 18:04:01 CET
# REVISION: $Id: wrapper.sh,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
#===============================================================================
perlexe="${0}" # the perl executable
returncode=0 # default return code
if [ ${#} -ge 2 ] && [ -x "$perlexe" ]
then
"${@}"
returncode=$?
[ $returncode -ne 0 ] && printf "'${@}' returned ${returncode}\n"
else
printf "\n!! ${0} : too few argument(s) !!\n"
fi
read -p "... press return key ... " dummy
exit $returncode
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/scripts/wrapper.sh
|
Shell
|
gpl3
| 1,194
|
#!/usr/bin/perl
#===============================================================================
#
# FILE: csv2err.pl
#
# USAGE: ./csv2err.pl [-hH] -i CSV-file -n source-file [ -o outfile ][ -s criterion ]
#
# DESCRIPTION: Generate a Vim-quickfix compatible errorfile from a CSV-file
# produced by Devel::NYTProf.
# Specify CSV-file with full path.
# Specify source-file with full path.
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dr. Fritz Mehner (fgm), mehner@fh-swf.de
# COMPANY: FH Südwestfalen, Iserlohn
# VERSION: 2.0
# CREATED: 13.02.2009 17:04:00
# REVISION: $Id: csv2err.pl,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
#===============================================================================
use strict;
use warnings;
use Getopt::Std;
use File::Basename;
our( $opt_H, $opt_h, $opt_i, $opt_o, $opt_s, $opt_n );
getopts('hHi:o:s:n:'); # process command line arguments
#-------------------------------------------------------------------------------
# check for parameters
#-------------------------------------------------------------------------------
if ( defined $opt_h || !defined $opt_i ) { # process option -h
usage();
}
my $criterion = 'file line time calls time_per_call';
my $sortcriterion = 'none';
if ( defined $opt_s ) {
$sortcriterion = $opt_s;
usage() until $criterion =~ m/\b$opt_s\b/;
}
my $csv_file_name = $opt_i; # input file name
#-------------------------------------------------------------------------------
# output file
#-------------------------------------------------------------------------------
if ( defined $opt_o ) {
open FILE, "> $opt_o" or do {
warn "Couldn't open $opt_o: $!. Using STDOUT instead.\n";
undef $opt_o;
};
}
my $handle = ( defined $opt_o ? \*FILE : \*STDOUT );
if ( defined $opt_o ) {
close FILE
or warn "$0 : failed to close output file '$opt_o' : $!\n";
unlink $opt_o;
}
#-------------------------------------------------------------------------------
# prepare file names
# The quickfix format needs the absolute file name of the source file.
# This file name is constructed from the mame of the csv-file, e.g.
# PATH/nytprof/test-pl-line.csv
# gives
# PATH/test.pl
# The name of the output file is also constructed:
# PATH/nytprof/test.pl.err
#-------------------------------------------------------------------------------
my $src_filename = $opt_n;
#-------------------------------------------------------------------------------
# read the CSV-file
#-------------------------------------------------------------------------------
open my $csv, '<', $csv_file_name
or die "$0 : failed to open input file '$csv_file_name' : $!\n";
my $line;
foreach my $i ( 1..3 ) { # read the header
$line = <$csv>;
print $line;
}
$line = <$csv>; # skip NYTProf format line
print "#\n# sort criterion: $sortcriterion\n";
print "# FORMAT: filename : line number : time : calls : time/call : code\n#\n";
my @rawline= <$csv>; # rest of the CSV-file
chomp @rawline;
close $csv
or warn "$0 : failed to close input file '$csv_file_name' : $!\n";
#---------------------------------------------------------------------------
# filter lines
# input format: <time>,<calls>,<time/call>,<source line>
# output format: <filename>:<line>:<time>:<calls>:<time/call>: <source line>
#---------------------------------------------------------------------------
my $sourcelinenumber = 0;
my $sourceline;
my $cookedline;
my @linepart;
my @line;
my $delim = ':';
foreach my $n ( 0..$#rawline ) {
$sourcelinenumber++;
@linepart = split ( /,/, $rawline[$n] );
$sourceline = join( ',', @linepart[3..$#linepart] );
$cookedline = $src_filename.$delim.$sourcelinenumber.$delim;
$cookedline .= join( $delim, @linepart[0..2] ).$delim.' ';
$cookedline .= $sourceline;
unless ( defined $opt_H && ( $linepart[0]+$linepart[1]+$linepart[2] == 0 ) ) {
push @line, $cookedline;
}
}
#-------------------------------------------------------------------------------
# sort file names (field index 0)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'file' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 0 : 1;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$a[$ind] cmp $b[$ind]; # ascending
} @line;
}
#-------------------------------------------------------------------------------
# sort line numbers (field index 1)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'line' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 1 : 2;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$a[$ind] <=> $b[$ind]; # ascending
} @line;
}
#-------------------------------------------------------------------------------
# sort time (index 2)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'time' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 2 : 3;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$b[$ind] <=> $a[$ind]; # descending
} @line;
}
#-------------------------------------------------------------------------------
# sort calls (index 3)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'calls' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 3 : 4;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$b[$ind] <=> $a[$ind]; # descending
} @line;
}
#-------------------------------------------------------------------------------
# sort time_per_call (index 4)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'time_per_call' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 4 : 5;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$b[$ind] <=> $a[$ind]; # descending
} @line;
}
#-------------------------------------------------------------------------------
# write result
#-------------------------------------------------------------------------------
foreach my $line ( @line ) {
print $line, "\n";
}
#-------------------------------------------------------------------------------
# subroutine usage()
#-------------------------------------------------------------------------------
sub usage {
print <<EOF;
usage: $0 [-hH] -i CSV-file -n source-file [ -o outfile ][ -s criterion ]
-h this message
-H hot spots only ( time, calls, and time/call are zero)
-i input file (CSV)
-n source file (*.pl or *.pm)
-s sort criterion (file, line, time, calls, time_per_call)
EOF
exit 0;
} # ---------- end of subroutine usage ----------
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/scripts/.svn/text-base/csv2err.pl.svn-base
|
Perl
|
gpl3
| 7,139
|
#!/usr/bin/perl
#===================================================================================
#
# FILE: pmdesc3
#
# SYNOPSIS: Find versions and descriptions of installed perl Modules and PODs
#
# DESCRIPTION: See POD below.
#
# CREATED: 15.06.2004 22:12:41 CEST
# REVISION: $Id: pmdesc3.pl,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
# TODO: Replace UNIX sort pipe.
#
#===================================================================================
package pmdesc3;
require 5.6.1;
use strict;
use warnings;
use Carp;
use ExtUtils::MakeMaker;
use File::Find qw(find);
use Getopt::Std qw(getopts);
#use version;
our $VERSION = qw(1.2.3); # update POD at the end of this file
my $MaxDescLength = 150; # Maximum length for the description field:
# prevents slurping in big amount of faulty docs.
my $rgx_version = q/\Av?\d+(\.\w+)*\Z/; # regex for module versions
#=== FUNCTION ====================================================================
# NAME: usage
#===================================================================================
sub usage {
my $searchdirs = " "x12;
$searchdirs .= join( "\n"." "x12, sort { length $b <=> length $a } @INC ) . "\n";
print <<EOT;
Usage: pmdesc3.pl [-h] [-s] [-t ddd] [-v dd] [--] [dir [dir [dir [...]]]]
Options: -h print this message
-s sort output (not under Windows)
-t ddd name column has width ddd (1-3 digits); default 36
-v dd version column has width ddd (1-3 digits); default 10
If no directories given, searches:
$searchdirs
EOT
exit;
}
#=== FUNCTION ====================================================================
# NAME: get_module_name
#===================================================================================
sub get_module_name {
my ($path, $relative_to) = @_;
local $_ = $path;
s!\A\Q$relative_to\E/?!!;
s! \.p(?:m|od) \z!!x;
s!/!::!g;
return $_;
}
#=== FUNCTION ====================================================================
# NAME: get_module_description
#===================================================================================
sub get_module_description
{
my $desc;
my ($INFILE_file_name) = @_; # input file name
undef $/; # undefine input record separator
open my $INFILE, '<', $INFILE_file_name
or die "$0 : failed to open input file '$INFILE_file_name' : $!\n";
my $file = <$INFILE>; # slurp mode
close $INFILE
or warn "$0 : failed to close input file '$INFILE_file_name' : $!\n";
$file =~ s/\cM\cJ/\cJ/g; # remove DOS line ends
$file =~ m/\A=head1\s+NAME(.*?)\n=\w+/s; # file starts with '=head1' (PODs)
$desc = $1;
if ( ! defined $desc )
{
$file =~ m/\n=head1\s+NAME(.*?)\n=\w+/s; # '=head1' is embedded
$desc = $1;
}
if ( ! defined $desc )
{
$file =~ m/\n=head1\s+DESCRIPTION(.*?)\n=\w+/s; # '=head1' is embedded
$desc = $1;
}
if ( defined $desc )
{
$desc =~ s/B<([^>]+)>/$1/gs; # remove bold markup
$desc =~ s/C<([^>]+)>/'$1'/gs; # single quotes to indicate literal
$desc =~ s/E<lt>/</gs; # replace markup for <
$desc =~ s/E<gt>/>/gs; # replace markup for >
$desc =~ s/F<([^>]+)>/$1/gs; # remove filename markup
$desc =~ s/I<([^>]+)>/$1/gs; # remove italic markup
$desc =~ s/L<([^>]+)>/$1/gs; # remove link markup
$desc =~ s/X<([^>]+)>//gs; # remove index markup
$desc =~ s/Z<>//gs; # remove zero-width character
$desc =~ s/S<([^>]+)>/$1/gs; # remove markup for nonbreaking spaces
$desc =~ s/\A[ \t\n]*//s; # remove leading whitespaces
$desc =~ s/\n\s+\n/\n\n/sg; # make true empty lines
$desc =~ s/\n\n.*$//s; # discard all trailing paragraphs
$desc =~ s/\A.*?\s+-+\s+//s; # discard leading module name
$desc =~ s/\n/ /sg; # join lines
$desc =~ s/\s+/ /g; # squeeze whitespaces
$desc =~ s/\s*$//g; # remove trailing whitespaces
$desc = substr $desc, 0, $MaxDescLength; # limited length
}
return $desc;
}
#=== FUNCTION ====================================================================
# NAME: get_module_version
#===================================================================================
sub get_module_version {
local $_; # MM->parse_version is naughty
my $vers_code = MM->parse_version($File::Find::name) || '';
$vers_code = undef unless $vers_code =~ /$rgx_version/;
return $vers_code;
}
#=== FUNCTION ====================================================================
# NAME: MAIN
#===================================================================================
my %visited;
$|++;
#---------------------------------------------------------------------------
# process options and command line arguments
#---------------------------------------------------------------------------
my %options;
getopts("hst:v:", \%options) or $options{h}=1;
my @args = @ARGV;
@ARGV = @INC unless @ARGV;
usage() if $options{h}; # option -h : usage
#---------------------------------------------------------------------------
# option -t : width of the module name column
#---------------------------------------------------------------------------
usage() if $options{t} && $options{t}!~/^\d{1,3}$/; # width 1-3 digits
$options{t} = "36" unless $options{t};
#---------------------------------------------------------------------------
# option -v : width of the version column
#---------------------------------------------------------------------------
usage() if $options{v} && $options{v}!~/^\d{1,2}$/; # width 1-2 digits
$options{v} = "10" unless $options{v};
#---------------------------------------------------------------------------
# option -s : install an output filter to sort the module list
#---------------------------------------------------------------------------
if ($options{s}) {
usage() if $^O eq "MSWin32";
if ( open(ME, "-|") ) {
$/ = "";
while ( <ME> ) {
chomp;
print join("\n", sort split /\n/), "\n";
}
exit;
}
}
#---------------------------------------------------------------------------
# process
#---------------------------------------------------------------------------
#
# :WARNING:15.04.2005:Mn: under Windows descending into subdirs will be
# suppressed by the the preprocessing part of the following call to find
# :TODO:16.04.2005:Mn: remove code doubling
#
if ( $^O ne "MSWin32" ) { # ----- UNIX, Linux, ...
for my $inc_dir (sort { length $b <=> length $a } @ARGV) {
find({
wanted => sub {
return unless /\.p(?:m|od)\z/ && -f;
#---------------------------------------------------------------------
# return from function if there exists a pod-file for this module
#---------------------------------------------------------------------
my $pod = $_;
my $pm = $_;
if ( m/\.pm\z/ )
{
$pod =~ s/\.pm\z/\.pod/;
return if -f $pod;
}
my $module = get_module_name($File::Find::name, $inc_dir);
my $version;
if ( /\.pod\z/ )
{
$pm =~ s/\.pod\z/\.pm/;
#-------------------------------------------------------------------
# try to find the version from the pm-file
#-------------------------------------------------------------------
if ( -f $pm )
{
local $_;
$version = MM->parse_version($pm) || "";
$version = undef unless $version =~ /$rgx_version/;
}
}
else
{
$version = get_module_version($_);
}
my $desc = get_module_description($_);
$version = defined $version ? " ($version)" : " (n/a)";
$desc = defined $desc ? " $desc" : " <description not available>";
printf("%-${options{t}}s%-${options{v}}s%-s\n", $module, $version, $desc );
},
preprocess => sub {
my ($dev, $inode) = stat $File::Find::dir or return;
$visited{"$dev:$inode"}++ ? () : @_;
},
},
$inc_dir);
}
}
else { # ----- MS Windows
for my $inc_dir (sort { length $b <=> length $a } @ARGV) {
find({
wanted => sub {
return unless /\.p(?:m|od)\z/ && -f;
#---------------------------------------------------------------------
# return from function if there exists a pod-file for this module
#---------------------------------------------------------------------
my $pod = $_;
my $pm = $_;
if ( m/\.pm\z/ )
{
$pod =~ s/\.pm\z/\.pod/;
return if -f $pod;
}
my $module = get_module_name($File::Find::name, $inc_dir);
my $version;
if ( /\.pod\z/ )
{
$pm =~ s/\.pod\z/\.pm/;
#-------------------------------------------------------------------
# try to find the version from the pm-file
#-------------------------------------------------------------------
if ( -f $pm )
{
local $_;
$version = MM->parse_version($pm) || "";
$version = undef unless $version =~ /$rgx_version/;
}
}
else
{
$version = get_module_version($_);
}
my $desc = get_module_description($_);
$version = defined $version ? " ($version)" : " (n/a)";
$desc = defined $desc ? " $desc" : " <description not available>";
printf("%-${options{t}}s%-${options{v}}s%-s\n", $module, $version, $desc );
},
},
$inc_dir);
}
}
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Modul Documentation
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=head1 NAME
pmdesc3 - List name, version, and description of all installed perl modules and PODs
=head1 SYNOPSIS
pmdesc3.pl
pmdesc3.pl ~/perllib
=head1 DESCRIPTION
pmdesc3.pl [-h] [-s] [-t ddd] [-v dd] [--] [dir [dir [dir [...]]]]
OPTIONS: -h : print help message; show search path
-s : sort output (not under Windows)
-t ddd : name column has width ddd (1-3 digits); default 36
-v dd : version column has width dd (1-2 digits); default 10
Find name, version and description of all installed Perl modules and PODs.
If no directories given, searches @INC .
The first column of the output (see below) can be used as module name or
FAQ-name for perldoc.
Some modules are split into a pm-file and an accompanying pod-file.
The version number is always taken from the pm-file.
The description found will be cut down to a length of at most
150 characters (prevents slurping in big amount of faulty docs).
=head2 Output
The output looks like this:
...
IO::Socket (1.28) Object interface to socket communications
IO::Socket::INET (1.27) Object interface for AF_INET domain sockets
IO::Socket::UNIX (1.21) Object interface for AF_UNIX domain sockets
IO::Stty (n/a) <description not available>
IO::Tty (1.02) Low-level allocate a pseudo-Tty, import constants.
IO::Tty::Constant (n/a) Terminal Constants (autogenerated)
...
The three parts module name, version and description are separated
by at least one blank.
=head1 REQUIREMENTS
ExtUtils::MakeMaker, File::Find, Getopt::Std
=head1 BUGS AND LIMITATIONS
The command line switch -s (sort) is not available under non-UNIX operating
systems. An additional shell sort command can be used.
There are no known bugs in this module.
Please report problems to Fritz Mehner, mehner@fh-swf.de .
=head1 AUTHORS
Tom Christiansen, tchrist@perl.com (pmdesc)
Aristotle, http://qs321.pair.com/~monkads/ (pmdesc2)
Fritz Mehner, mehner@fh-swf.de (pmdesc3.pl)
=head1 NOTES
pmdesc3.pl is based on pmdesc2 (Aristotle, http://qs321.pair.com/~monkads/).
pmdesc3.pl adds extensions and bugfixes.
pmdesc2 is based on pmdesc (Perl Cookbook, 1. Ed., recipe 12.19).
pmdesc2 is at least one magnitude faster than pmdesc.
=head1 VERSION
1.2.3
=cut
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/scripts/.svn/text-base/pmdesc3.pl.svn-base
|
Perl
|
gpl3
| 13,833
|
#!/bin/bash
#===============================================================================
# FILE: wrapper.sh
# USAGE: ./wrapper.sh executable [cmd-line-args]
# DESCRIPTION: Wraps the execution of a programm or script.
# Use with xterm: xterm -e wrapper.sh executable cmd-line-args
# This script is used by the plugin perl-support.vim.
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dr.-Ing. Fritz Mehner (Mn), mehner@fh-swf.de
# COMPANY: Fachhochschule Südwestfalen, Iserlohn
# CREATED: 23.11.2004 18:04:01 CET
# REVISION: $Id: wrapper.sh,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
#===============================================================================
perlexe="${0}" # the perl executable
returncode=0 # default return code
if [ ${#} -ge 2 ] && [ -x "$perlexe" ]
then
"${@}"
returncode=$?
[ $returncode -ne 0 ] && printf "'${@}' returned ${returncode}\n"
else
printf "\n!! ${0} : too few argument(s) !!\n"
fi
read -p "... press return key ... " dummy
exit $returncode
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/scripts/.svn/text-base/wrapper.sh.svn-base
|
Shell
|
gpl3
| 1,194
|
#!/usr/bin/perl
#===============================================================================
#
# FILE: csv2err.pl
#
# USAGE: ./csv2err.pl [-hH] -i CSV-file -n source-file [ -o outfile ][ -s criterion ]
#
# DESCRIPTION: Generate a Vim-quickfix compatible errorfile from a CSV-file
# produced by Devel::NYTProf.
# Specify CSV-file with full path.
# Specify source-file with full path.
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dr. Fritz Mehner (fgm), mehner@fh-swf.de
# COMPANY: FH Südwestfalen, Iserlohn
# VERSION: 2.0
# CREATED: 13.02.2009 17:04:00
# REVISION: $Id: csv2err.pl,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
#===============================================================================
use strict;
use warnings;
use Getopt::Std;
use File::Basename;
our( $opt_H, $opt_h, $opt_i, $opt_o, $opt_s, $opt_n );
getopts('hHi:o:s:n:'); # process command line arguments
#-------------------------------------------------------------------------------
# check for parameters
#-------------------------------------------------------------------------------
if ( defined $opt_h || !defined $opt_i ) { # process option -h
usage();
}
my $criterion = 'file line time calls time_per_call';
my $sortcriterion = 'none';
if ( defined $opt_s ) {
$sortcriterion = $opt_s;
usage() until $criterion =~ m/\b$opt_s\b/;
}
my $csv_file_name = $opt_i; # input file name
#-------------------------------------------------------------------------------
# output file
#-------------------------------------------------------------------------------
if ( defined $opt_o ) {
open FILE, "> $opt_o" or do {
warn "Couldn't open $opt_o: $!. Using STDOUT instead.\n";
undef $opt_o;
};
}
my $handle = ( defined $opt_o ? \*FILE : \*STDOUT );
if ( defined $opt_o ) {
close FILE
or warn "$0 : failed to close output file '$opt_o' : $!\n";
unlink $opt_o;
}
#-------------------------------------------------------------------------------
# prepare file names
# The quickfix format needs the absolute file name of the source file.
# This file name is constructed from the mame of the csv-file, e.g.
# PATH/nytprof/test-pl-line.csv
# gives
# PATH/test.pl
# The name of the output file is also constructed:
# PATH/nytprof/test.pl.err
#-------------------------------------------------------------------------------
my $src_filename = $opt_n;
#-------------------------------------------------------------------------------
# read the CSV-file
#-------------------------------------------------------------------------------
open my $csv, '<', $csv_file_name
or die "$0 : failed to open input file '$csv_file_name' : $!\n";
my $line;
foreach my $i ( 1..3 ) { # read the header
$line = <$csv>;
print $line;
}
$line = <$csv>; # skip NYTProf format line
print "#\n# sort criterion: $sortcriterion\n";
print "# FORMAT: filename : line number : time : calls : time/call : code\n#\n";
my @rawline= <$csv>; # rest of the CSV-file
chomp @rawline;
close $csv
or warn "$0 : failed to close input file '$csv_file_name' : $!\n";
#---------------------------------------------------------------------------
# filter lines
# input format: <time>,<calls>,<time/call>,<source line>
# output format: <filename>:<line>:<time>:<calls>:<time/call>: <source line>
#---------------------------------------------------------------------------
my $sourcelinenumber = 0;
my $sourceline;
my $cookedline;
my @linepart;
my @line;
my $delim = ':';
foreach my $n ( 0..$#rawline ) {
$sourcelinenumber++;
@linepart = split ( /,/, $rawline[$n] );
$sourceline = join( ',', @linepart[3..$#linepart] );
$cookedline = $src_filename.$delim.$sourcelinenumber.$delim;
$cookedline .= join( $delim, @linepart[0..2] ).$delim.' ';
$cookedline .= $sourceline;
unless ( defined $opt_H && ( $linepart[0]+$linepart[1]+$linepart[2] == 0 ) ) {
push @line, $cookedline;
}
}
#-------------------------------------------------------------------------------
# sort file names (field index 0)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'file' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 0 : 1;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$a[$ind] cmp $b[$ind]; # ascending
} @line;
}
#-------------------------------------------------------------------------------
# sort line numbers (field index 1)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'line' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 1 : 2;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$a[$ind] <=> $b[$ind]; # ascending
} @line;
}
#-------------------------------------------------------------------------------
# sort time (index 2)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'time' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 2 : 3;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$b[$ind] <=> $a[$ind]; # descending
} @line;
}
#-------------------------------------------------------------------------------
# sort calls (index 3)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'calls' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 3 : 4;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$b[$ind] <=> $a[$ind]; # descending
} @line;
}
#-------------------------------------------------------------------------------
# sort time_per_call (index 4)
#-------------------------------------------------------------------------------
if ( $sortcriterion eq 'time_per_call' ) {
@line = sort {
my $ind = ( $a !~ m/^[[:alpha:]]$delim/ ) ? 4 : 5;
my @a = split /$delim/, $a;
my @b = split /$delim/, $b;
$b[$ind] <=> $a[$ind]; # descending
} @line;
}
#-------------------------------------------------------------------------------
# write result
#-------------------------------------------------------------------------------
foreach my $line ( @line ) {
print $line, "\n";
}
#-------------------------------------------------------------------------------
# subroutine usage()
#-------------------------------------------------------------------------------
sub usage {
print <<EOF;
usage: $0 [-hH] -i CSV-file -n source-file [ -o outfile ][ -s criterion ]
-h this message
-H hot spots only ( time, calls, and time/call are zero)
-i input file (CSV)
-n source file (*.pl or *.pm)
-s sort criterion (file, line, time, calls, time_per_call)
EOF
exit 0;
} # ---------- end of subroutine usage ----------
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/scripts/csv2err.pl
|
Perl
|
gpl3
| 7,139
|
#!/usr/bin/perl
#===================================================================================
#
# FILE: pmdesc3
#
# SYNOPSIS: Find versions and descriptions of installed perl Modules and PODs
#
# DESCRIPTION: See POD below.
#
# CREATED: 15.06.2004 22:12:41 CEST
# REVISION: $Id: pmdesc3.pl,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
# TODO: Replace UNIX sort pipe.
#
#===================================================================================
package pmdesc3;
require 5.6.1;
use strict;
use warnings;
use Carp;
use ExtUtils::MakeMaker;
use File::Find qw(find);
use Getopt::Std qw(getopts);
#use version;
our $VERSION = qw(1.2.3); # update POD at the end of this file
my $MaxDescLength = 150; # Maximum length for the description field:
# prevents slurping in big amount of faulty docs.
my $rgx_version = q/\Av?\d+(\.\w+)*\Z/; # regex for module versions
#=== FUNCTION ====================================================================
# NAME: usage
#===================================================================================
sub usage {
my $searchdirs = " "x12;
$searchdirs .= join( "\n"." "x12, sort { length $b <=> length $a } @INC ) . "\n";
print <<EOT;
Usage: pmdesc3.pl [-h] [-s] [-t ddd] [-v dd] [--] [dir [dir [dir [...]]]]
Options: -h print this message
-s sort output (not under Windows)
-t ddd name column has width ddd (1-3 digits); default 36
-v dd version column has width ddd (1-3 digits); default 10
If no directories given, searches:
$searchdirs
EOT
exit;
}
#=== FUNCTION ====================================================================
# NAME: get_module_name
#===================================================================================
sub get_module_name {
my ($path, $relative_to) = @_;
local $_ = $path;
s!\A\Q$relative_to\E/?!!;
s! \.p(?:m|od) \z!!x;
s!/!::!g;
return $_;
}
#=== FUNCTION ====================================================================
# NAME: get_module_description
#===================================================================================
sub get_module_description
{
my $desc;
my ($INFILE_file_name) = @_; # input file name
undef $/; # undefine input record separator
open my $INFILE, '<', $INFILE_file_name
or die "$0 : failed to open input file '$INFILE_file_name' : $!\n";
my $file = <$INFILE>; # slurp mode
close $INFILE
or warn "$0 : failed to close input file '$INFILE_file_name' : $!\n";
$file =~ s/\cM\cJ/\cJ/g; # remove DOS line ends
$file =~ m/\A=head1\s+NAME(.*?)\n=\w+/s; # file starts with '=head1' (PODs)
$desc = $1;
if ( ! defined $desc )
{
$file =~ m/\n=head1\s+NAME(.*?)\n=\w+/s; # '=head1' is embedded
$desc = $1;
}
if ( ! defined $desc )
{
$file =~ m/\n=head1\s+DESCRIPTION(.*?)\n=\w+/s; # '=head1' is embedded
$desc = $1;
}
if ( defined $desc )
{
$desc =~ s/B<([^>]+)>/$1/gs; # remove bold markup
$desc =~ s/C<([^>]+)>/'$1'/gs; # single quotes to indicate literal
$desc =~ s/E<lt>/</gs; # replace markup for <
$desc =~ s/E<gt>/>/gs; # replace markup for >
$desc =~ s/F<([^>]+)>/$1/gs; # remove filename markup
$desc =~ s/I<([^>]+)>/$1/gs; # remove italic markup
$desc =~ s/L<([^>]+)>/$1/gs; # remove link markup
$desc =~ s/X<([^>]+)>//gs; # remove index markup
$desc =~ s/Z<>//gs; # remove zero-width character
$desc =~ s/S<([^>]+)>/$1/gs; # remove markup for nonbreaking spaces
$desc =~ s/\A[ \t\n]*//s; # remove leading whitespaces
$desc =~ s/\n\s+\n/\n\n/sg; # make true empty lines
$desc =~ s/\n\n.*$//s; # discard all trailing paragraphs
$desc =~ s/\A.*?\s+-+\s+//s; # discard leading module name
$desc =~ s/\n/ /sg; # join lines
$desc =~ s/\s+/ /g; # squeeze whitespaces
$desc =~ s/\s*$//g; # remove trailing whitespaces
$desc = substr $desc, 0, $MaxDescLength; # limited length
}
return $desc;
}
#=== FUNCTION ====================================================================
# NAME: get_module_version
#===================================================================================
sub get_module_version {
local $_; # MM->parse_version is naughty
my $vers_code = MM->parse_version($File::Find::name) || '';
$vers_code = undef unless $vers_code =~ /$rgx_version/;
return $vers_code;
}
#=== FUNCTION ====================================================================
# NAME: MAIN
#===================================================================================
my %visited;
$|++;
#---------------------------------------------------------------------------
# process options and command line arguments
#---------------------------------------------------------------------------
my %options;
getopts("hst:v:", \%options) or $options{h}=1;
my @args = @ARGV;
@ARGV = @INC unless @ARGV;
usage() if $options{h}; # option -h : usage
#---------------------------------------------------------------------------
# option -t : width of the module name column
#---------------------------------------------------------------------------
usage() if $options{t} && $options{t}!~/^\d{1,3}$/; # width 1-3 digits
$options{t} = "36" unless $options{t};
#---------------------------------------------------------------------------
# option -v : width of the version column
#---------------------------------------------------------------------------
usage() if $options{v} && $options{v}!~/^\d{1,2}$/; # width 1-2 digits
$options{v} = "10" unless $options{v};
#---------------------------------------------------------------------------
# option -s : install an output filter to sort the module list
#---------------------------------------------------------------------------
if ($options{s}) {
usage() if $^O eq "MSWin32";
if ( open(ME, "-|") ) {
$/ = "";
while ( <ME> ) {
chomp;
print join("\n", sort split /\n/), "\n";
}
exit;
}
}
#---------------------------------------------------------------------------
# process
#---------------------------------------------------------------------------
#
# :WARNING:15.04.2005:Mn: under Windows descending into subdirs will be
# suppressed by the the preprocessing part of the following call to find
# :TODO:16.04.2005:Mn: remove code doubling
#
if ( $^O ne "MSWin32" ) { # ----- UNIX, Linux, ...
for my $inc_dir (sort { length $b <=> length $a } @ARGV) {
find({
wanted => sub {
return unless /\.p(?:m|od)\z/ && -f;
#---------------------------------------------------------------------
# return from function if there exists a pod-file for this module
#---------------------------------------------------------------------
my $pod = $_;
my $pm = $_;
if ( m/\.pm\z/ )
{
$pod =~ s/\.pm\z/\.pod/;
return if -f $pod;
}
my $module = get_module_name($File::Find::name, $inc_dir);
my $version;
if ( /\.pod\z/ )
{
$pm =~ s/\.pod\z/\.pm/;
#-------------------------------------------------------------------
# try to find the version from the pm-file
#-------------------------------------------------------------------
if ( -f $pm )
{
local $_;
$version = MM->parse_version($pm) || "";
$version = undef unless $version =~ /$rgx_version/;
}
}
else
{
$version = get_module_version($_);
}
my $desc = get_module_description($_);
$version = defined $version ? " ($version)" : " (n/a)";
$desc = defined $desc ? " $desc" : " <description not available>";
printf("%-${options{t}}s%-${options{v}}s%-s\n", $module, $version, $desc );
},
preprocess => sub {
my ($dev, $inode) = stat $File::Find::dir or return;
$visited{"$dev:$inode"}++ ? () : @_;
},
},
$inc_dir);
}
}
else { # ----- MS Windows
for my $inc_dir (sort { length $b <=> length $a } @ARGV) {
find({
wanted => sub {
return unless /\.p(?:m|od)\z/ && -f;
#---------------------------------------------------------------------
# return from function if there exists a pod-file for this module
#---------------------------------------------------------------------
my $pod = $_;
my $pm = $_;
if ( m/\.pm\z/ )
{
$pod =~ s/\.pm\z/\.pod/;
return if -f $pod;
}
my $module = get_module_name($File::Find::name, $inc_dir);
my $version;
if ( /\.pod\z/ )
{
$pm =~ s/\.pod\z/\.pm/;
#-------------------------------------------------------------------
# try to find the version from the pm-file
#-------------------------------------------------------------------
if ( -f $pm )
{
local $_;
$version = MM->parse_version($pm) || "";
$version = undef unless $version =~ /$rgx_version/;
}
}
else
{
$version = get_module_version($_);
}
my $desc = get_module_description($_);
$version = defined $version ? " ($version)" : " (n/a)";
$desc = defined $desc ? " $desc" : " <description not available>";
printf("%-${options{t}}s%-${options{v}}s%-s\n", $module, $version, $desc );
},
},
$inc_dir);
}
}
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Modul Documentation
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=head1 NAME
pmdesc3 - List name, version, and description of all installed perl modules and PODs
=head1 SYNOPSIS
pmdesc3.pl
pmdesc3.pl ~/perllib
=head1 DESCRIPTION
pmdesc3.pl [-h] [-s] [-t ddd] [-v dd] [--] [dir [dir [dir [...]]]]
OPTIONS: -h : print help message; show search path
-s : sort output (not under Windows)
-t ddd : name column has width ddd (1-3 digits); default 36
-v dd : version column has width dd (1-2 digits); default 10
Find name, version and description of all installed Perl modules and PODs.
If no directories given, searches @INC .
The first column of the output (see below) can be used as module name or
FAQ-name for perldoc.
Some modules are split into a pm-file and an accompanying pod-file.
The version number is always taken from the pm-file.
The description found will be cut down to a length of at most
150 characters (prevents slurping in big amount of faulty docs).
=head2 Output
The output looks like this:
...
IO::Socket (1.28) Object interface to socket communications
IO::Socket::INET (1.27) Object interface for AF_INET domain sockets
IO::Socket::UNIX (1.21) Object interface for AF_UNIX domain sockets
IO::Stty (n/a) <description not available>
IO::Tty (1.02) Low-level allocate a pseudo-Tty, import constants.
IO::Tty::Constant (n/a) Terminal Constants (autogenerated)
...
The three parts module name, version and description are separated
by at least one blank.
=head1 REQUIREMENTS
ExtUtils::MakeMaker, File::Find, Getopt::Std
=head1 BUGS AND LIMITATIONS
The command line switch -s (sort) is not available under non-UNIX operating
systems. An additional shell sort command can be used.
There are no known bugs in this module.
Please report problems to Fritz Mehner, mehner@fh-swf.de .
=head1 AUTHORS
Tom Christiansen, tchrist@perl.com (pmdesc)
Aristotle, http://qs321.pair.com/~monkads/ (pmdesc2)
Fritz Mehner, mehner@fh-swf.de (pmdesc3.pl)
=head1 NOTES
pmdesc3.pl is based on pmdesc2 (Aristotle, http://qs321.pair.com/~monkads/).
pmdesc3.pl adds extensions and bugfixes.
pmdesc2 is based on pmdesc (Perl Cookbook, 1. Ed., recipe 12.19).
pmdesc2 is at least one magnitude faster than pmdesc.
=head1 VERSION
1.2.3
=cut
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/scripts/pmdesc3.pl
|
Perl
|
gpl3
| 13,833
|
%%=====================================================================================
%%
%% File: perl-hot-keys.tex
%%
%% Description: perl-support.vim : Key mappings for Vim without GUI.
%%
%%
%% Author: Dr.-Ing. Fritz Mehner
%% Email: mehner@fh-swf.de
%% Copyright: Copyright (C) 2003-2010 Dr.-Ing. Fritz Mehner (mehner@fh-swf.de)
%% Version: see \Pluginversion
%% Created: 06.06.2003
%% Revision: $Id: perl-hot-keys.tex,v 1.8 2012/04/25 19:07:10 mehner Exp $
%%
%%=====================================================================================
\documentclass[oneside,10pt,landscape,DIV17]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lastpage}
\usepackage{multicol}
\usepackage{fancyhdr}
\setlength\parindent{0pt}
\newcommand{\Pluginversion}{5.1}
\newcommand{\ReleaseDate}{\today}
\newcommand{\Rep}{{\scriptsize{[n]}}}
%%----------------------------------------------------------------------
%% fancyhdr
%%----------------------------------------------------------------------
\pagestyle{fancyplain}
\fancyhf{}
\fancyfoot[L]{\small \ReleaseDate}
\fancyfoot[C]{\small perl-support.vim}
\fancyfoot[R]{\small \textbf{Page \thepage{} / \pageref{LastPage}}}
\renewcommand{\headrulewidth}{0.0pt}
%%----------------------------------------------------------------------
%% luximono : Type1-font
%% Makes keyword stand out by using semibold letters.
%%----------------------------------------------------------------------
\usepackage[scaled]{luximono}
%%----------------------------------------------------------------------
%% hyperref
%%----------------------------------------------------------------------
\usepackage[ps2pdf]{hyperref}
\hypersetup{pdfauthor={Dr.-Ing. Fritz Mehner, FH Südwestfalen, Iserlohn, Germany}}
\hypersetup{pdfkeywords={Vim, Perl}}
\hypersetup{pdfsubject={Vim-plug-in, perl-support.vim, hot keys}}
\hypersetup{pdftitle={Vim-plug-in, perl-support.vim, hot keys}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% START OF DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}%
\begin{multicols}{3}
%
\begin{center}
%
%%======================================================================
%% title
%%======================================================================
\textbf{\textsc{\small{Vim-Plug-in}}}\\
\textbf{\LARGE{perl-support.vim}}\\
\textbf{\textsc{\small{Version \Pluginversion}}}\\
\vspace{5mm}%
\textbf{\textsc{\Huge{Hot keys}}}\\
\vspace{5mm}%
Key mappings for Vim and gVim.\\
Plug-in: http://vim.sourceforge.net\\
Fritz Mehner (mehner.fritz@fh-swf.de)\\
\vspace{1.0mm}
{\normalsize (i)} insert mode, {\normalsize (n)} normal mode, {\normalsize (v)} visual mode\\
\vspace{4.0mm}
%%======================================================================
%% table, left part
%%======================================================================
%%~~~~~ TABULAR : begin ~~~~~~~~~~
\begin{tabular}[]{|p{11mm}|p{60mm}|}
%%----------------------------------------------------------------------
%% show plug-in help
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{H}elp}}\\[1.0ex]
\hline \verb'\h' & read perldoc for word under cursor \hfill (n,i)\\
\hline \verb'\hp' & help (plug-in) \hfill (n,i)\\
\hline
%%----------------------------------------------------------------------
%% menu comments
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{C}omments}} \\[1.0ex]
\hline \Rep\verb'\cl' & end-of-line comment \hfill (n, v, i)\\
\hline \Rep\verb'\cj' & adjust end-of-line comments \hfill (n, v, i)\\
\hline \verb'\cs' & set end-of-line comment col. \hfill (n) \\
%
\hline \Rep\verb'\cc' & code $\leftrightarrow$ comment \hfill (n, v) \\
\hline \verb'\cb' & code block $\rightarrow$ comment \hfill (n, v) \\
\hline \verb'\cub' & uncomment code block \hfill (n) \\
%
\hline \verb'\cfr' & frame comment \hfill (n, i) \\
\hline \verb'\cfu' & function description \hfill (n, i) \\
\hline \verb'\cme' & method description \hfill (n, i) \\
\hline \verb'\chpl' & file header (.pl) \hfill (n) \\
\hline \verb'\chpm' & file header (.pm) \hfill (n) \\
\hline \verb'\cht' & file header (.t) \hfill (n) \\
\hline \verb'\chpo' & file header (.pod) \hfill (n) \\
\hline \verb'\cd' & date \hfill (n, i) \\
\hline \verb'\ct' & date \& time \hfill (n, i) \\
\hline \verb'\ck' & keyword comments \hfill (n, i) \\
\hline \verb'\cma' & plug-in macros \hfill (n, i) \\
\hline
\end{tabular}\\
%%~~~~~ TABULAR : end ~~~~~~~~~~
%
%%======================================================================
%% table, middle part
%%======================================================================
%
%%~~~~~ TABULAR : begin ~~~~~~~~~~
\begin{tabular}[]{|p{11mm}|p{60mm}|}
%%----------------------------------------------------------------------
%% menu statements
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{S}tatements}} \\[1.0ex]
\hline \verb'\sd' & \verb'do { } while' \hfill (n, v, i)\\
\hline \verb'\sf' & \verb'for { }' \hfill (n, v, i)\\
\hline \verb'\sfe' & \verb'foreach { }' \hfill (n, v, i)\\
\hline \verb'\si' & \verb'if { }' \hfill (n, v, i)\\
\hline \verb'\sie' & \verb'if { } else { }' \hfill (n, v, i)\\
\hline \verb'\se' & \verb'else { }' \hfill (n, v, i)\\
\hline \verb'\sei' & \verb'elsif { }' \hfill (n, v, i)\\
\hline \verb'\su' & \verb'unless { }' \hfill (n, v, i)\\
\hline \verb'\sue' & \verb'unless { } else { }' \hfill (n, v, i)\\
\hline \verb'\st' & \verb'until { }' \hfill (n, v, i)\\
\hline \verb'\sw' & \verb'while { }' \hfill (n, v, i)\\
\hline \verb'\sg' & \verb'given { }' \hfill (n, v, i)\\
\hline \verb'\swh' & \verb'when { }' \hfill (n, v, i)\\
\hline
%%----------------------------------------------------------------------
%% menu idioms
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{I}dioms}} \\[1.0ex]
\hline \verb'\id ' & \verb'my $;' \hfill (n, i) \\
\hline \verb'\ida ' & \verb'my $ = ;' \hfill (n, i) \\
\hline \verb'\idd ' & \verb'my ( $, $ );' \hfill (n, i) \\
\hline \verb'\ia ' & \verb'my @;' \hfill (n, i) \\
\hline \verb'\iaa ' & \verb'my @ = (,,);' \hfill (n, i) \\
\hline \verb'\ih ' & \verb'my %;' \hfill (n, i) \\
\hline \verb'\iha ' & \verb'my % = (=>,=>,);' \hfill (n, i) \\
%
\hline \verb'\ir' & \verb'my $rgx_ = q//;' \hfill (n, i) \\
\hline \verb'\im' & \verb'$ =~ m//xm' \hfill (n, i) \\
\hline \verb'\is' & \verb'$ =~ s///xm' \hfill (n, i) \\
\hline \verb'\it' & \verb'$ =~ tr///xm' \hfill (n, i) \\
\hline \verb'\isu' & \verb'subroutine' \hfill (n, v, i)\\
\hline \verb'\ip' & \verb'print "...\n";' \hfill (n ,i) \\
\hline \verb'\ii' & open input file \hfill (n, v, i)\\
\hline \verb'\io' & open output file \hfill (n, v, i)\\
\hline \verb'\ipi' & open pipe \hfill (n, v, i)\\
\hline
%%----------------------------------------------------------------------
%% snippet menu
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{S\textbf{n}ippet}} \\[1.0ex]
\hline \verb'\nr' & read code snippet \hfill (n, i) \\
\hline \verb'\nv' & view code snippet \hfill (n, i) \\
\hline \verb'\nw' & write code snippet \hfill (n, v, i)\\
\hline \verb'\ne' & edit code snippet \hfill (n, i) \\
%
\hline \verb'\ntl' & edit local templates \hfill (n, i)\\
\hline \verb'\ntr' & reread the templates \hfill (n, i)\\
\hline \verb'\nts' & choose template style \hfill (n, i)\\
%
\hline \verb'\njt' & insert jump tag \hfill (n, i)\\
\hline \verb'\nxs' & regex snippet template \hfill (n, i)\\
\hline
\end{tabular}\\
%%~~~~~ TABULAR : end ~~~~~~~~~~
%
%%======================================================================
%% table, right part
%%======================================================================
%
%%~~~~~ TABULAR : begin ~~~~~~~~~~
\begin{tabular}[]{|p{11mm}|p{60mm}|}
%%----------------------------------------------------------------------
%% menu regex menu
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{Regular E\textbf{x}pressions}} \\[1.0ex]
\hline \verb'xpc' & POSIX classes \hfill (n, i)\\
\hline \verb'xup' & Unicode properties \hfill (n, i)\\
\hline \verb'xex' & extended Regex \hfill (n, i)\\
\hline \Rep\verb'\xr' & pick up Regex \hfill (n, v)\\
\hline \Rep\verb'\xs' & pick up string \hfill (n, v)\\
\hline \verb'\xf' & pick up flag(s) \hfill (n, v)\\
\hline \verb'\xm' & match \hfill (n) \\
\hline \verb'\xmm'& match multiple (Regex/target) \hfill (n) \\
\hline \verb'\xe' & explain Regex \hfill (n, v)\\
\hline
%%----------------------------------------------------------------------
%% menu Special variables
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{S}pecial Variables}} \\[1.0ex]
\hline \verb'\vb' & basics \hfill (n, i)\\
\hline \verb'\ve' & errors \hfill (n, i)\\
\hline \verb'\vf' & files \hfill (n, i)\\
\hline \verb'\vid' & IDs \hfill (n, i)\\
\hline \verb'\vio' & IO \hfill (n, i)\\
\hline \verb'\vr' & regexp \hfill (n, i)\\
\hline \verb'\vs' & POSIX signals \hfill (n, i)\\
\hline
%%----------------------------------------------------------------------
%% menu POD
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{P}OD}} \\[1.0ex]
\hline \verb'\pod' & run \verb'podchecker' \hfill (n, i)\\
\hline \verb'\podh' & convert POD data to .html file \hfill (n, i)\\
\hline \verb'\podm' & Convert POD data to *roff input \hfill (n, i)\\
\hline \verb'\podt' & Convert POD data to ASCII text \hfill (n, i)\\
\hline \verb'\pm' & markup sequences \hfill (n, i)\\
\hline
%%----------------------------------------------------------------------
%% menu Profiling
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{P}rofiling}} \\[1.0ex]
\hline \verb'\rps' & run \verb'SmallProf' \hfill (n, i)\\
\hline \verb'\rpss' & sort \verb'SmallProf' report \hfill (n, i)\\
\hline \verb'\rpso' & open existing \verb'SmallProf' results \hfill (n, i)\\
\hline
%
\hline \verb'\rpf' & run \verb'FastProf' \hfill (n, i)\\
\hline \verb'\rpfs' & sort \verb'FastProf' report \hfill (n, i)\\
\hline \verb'\rpfo' & open existing \verb'FastProf' results \hfill (n, i)\\
%
\hline
\hline \verb'\rpn' & run \verb'NYTProf' \hfill (n, i)\\
\hline \verb'\rpns' & sort \verb'NYTProf' report \hfill (n, i)\\
\hline \verb'\rpno' & open existing \verb'NYTProf' results \hfill (n, i)\\
\hline \verb'\rpnh' & browse HTML files (\verb'NYTProf')\hfill (n, i)\\
\hline
\end{tabular}\\
%%~~~~~ TABULAR : end ~~~~~~~~~~
%
%
\end{center}%
\end{multicols}%
%
\newpage
%%----------------------------------------------------------------------
%% PAGE 2
%%----------------------------------------------------------------------
%
%
\begin{multicols}{2}
%
%%~~~~~ TABULAR : begin ~~~~~~~~~~
\begin{tabular}[]{|p{11mm}|p{61mm}|}
%%----------------------------------------------------------------------
%% menu run
%%----------------------------------------------------------------------
\hline
\multicolumn{2}{|r|}{\textsl{\textbf{R}un}} \\[1.0ex]
\hline \verb'\rr' & update file, run script \hfill (n, i) \\
\hline \verb'\rs' & update file, check syntax \hfill (n, i) \\
\hline \verb'\ra' & set command line arguments \hfill (n, i) \\
\hline \verb'\rw' & set Perl cmd.\ line switches \hfill (n, i) \\
\hline \verb'\re' & make script executable \hfill (n, i) \\
\hline \verb'\rm' & run \texttt{make} \hfill (n, i) \\
\hline \verb'\rcm' & choose makefile \hfill (n, i) \\
\hline \verb'\rm' & \texttt{make clean} \hfill (n, i) \\
\hline \verb'\rma' & command line arguments for \texttt{make} \hfill (n, i) \\
\hline \verb'\rd' & start debugger \hfill (n, i) \\
\hline \verb'\ri' & show installed Perl modules \hfill (n, i) \\
\hline \verb'\rg' & generate Perl module list \hfill (n, i) \\
\hline \verb'\ry' & run \verb'perltidy' \hfill (n, v, i)\\
\hline \verb'\rpc' & run \verb'perlcritic' \hfill (n, i) \\
\hline \verb'\rpcs' & set \verb'perlcritic' severity \hfill (n, i) \\
\hline \verb'\rpcv' & set \verb'perlcritic' verbosity \hfill (n, i) \\
\hline \verb'\rpco' & set \verb'perlcritic' options \hfill (n, i) \\
\hline \verb'\rt' & save buffer with timestamp \hfill (n, i) \\
\hline \verb'\rh' & hardcopy buffer \hfill (n, v, i)\\
\hline \verb'\rk' & settings and hotkeys \hfill (n, i) \\
\hline \verb'\rx' & set xterm size \hfill (n, i {\tiny GUI only})\\
\hline \verb'\ro' & change output destination \hfill (n, i) \\
\hline
\end{tabular}%
%%~~~~~ TABULAR : end ~~~~~~~~~~
%
\parbox[t][70mm][t]{120mm}{%
%
\begin{tabbing}
\hspace{30mm} \= \hspace{50mm} \= \kill
%
%%----------------------------------------------------------------------
%% perlcritic
%%----------------------------------------------------------------------
\textbf{\texttt{perlcritic}}\\[1.0ex]
%
Ex commands for \texttt{perlcritic} (version 1.01+)\\
Use tab expansion to choose the severity or the verbosity.\\[2.0ex]
\texttt{ :CriticSeverity} \> \texttt{\ 1\ \ \ \ \ \ 2\ \ \ \ \ 3\ \ \ \ \ 4\ \ \ \ \ 5} \\
\> \texttt{\ brutal cruel harsh stern gentle} \\[1.0ex]
\texttt{ :CriticVerbosity} \> \texttt{\ 1} $\ldots$ \texttt{11}\\[1.0ex]
\texttt{ :CriticOptions} \> option(s), see \texttt{perlcritic(1)}\\[5.5ex]
%
\hspace{40mm} \= \hspace{50mm} \= \kill
%%----------------------------------------------------------------------
%% regex tester
%%----------------------------------------------------------------------
\textbf{\texttt{Regular Expression Tester}}\\[1.0ex]
%
Ex command for the regular expression tester. Set control character\\
replacements for newline and tabulator used to display the results\\
of a match, e.g.:\\[2.0ex]
\texttt{ :RegexSubstitutions} \> \texttt{'\$}\texttt{\~}\texttt{'} \\[5.5ex]
%
\hspace{30mm} \= \hspace{50mm} \= \kill
%
%%----------------------------------------------------------------------
%% Profiling
%%----------------------------------------------------------------------
\large{\textbf{Profiling}}\\[1.0ex]
%
The following ex commands can be used to sort a profiler report \\in the quickfix window.\\
Use tab expansion to choose the sort criterion or the file name.\\[2.0ex]
%
For \texttt{Devel::SmallProf}\\[1.0ex]
\texttt{ :SmallProfSort} \> \texttt{file-name|line-number|line-count|time|ctime}\\[3.0ex]
%
%
For \texttt{Devel::FastProf}\\[1.0ex]
\texttt{ :FastProfSort} \> \texttt{file-name|line-number|time|line-count}\\[3.0ex]
%
%
For \texttt{Devel::NYTProf}\\[1.0ex]
\texttt{ :NYTProfCSV} \> Read a CSV-file.\\[1.0ex]
%
\texttt{ :NYTProfHTML} \> Read the HTML-reports with an external viewer (GUI only).\\[1.0ex]
%
%
\texttt{ :NYTProfSort} \> \texttt{file-name|line-number|time|calls|time-call}\\
%
\end{tabbing}
}
\end{multicols}%
%
%%----- TABBING : end ----------
\end{document}
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/doc/perl-hot-keys.tex
|
TeX
|
gpl3
| 16,958
|
my $filecontent = do{
local $/ = undef; # input record separator undefined
<$INFILE>
};
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/slurp-file.pl
|
Perl
|
gpl3
| 109
|
use Data::Dumper;
print Dumper(\reference);
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/print-data-structure-with-Dumper.pl
|
Perl
|
gpl3
| 46
|
#----------------------------------------------------------------------
# subroutine : print_hash
#----------------------------------------------------------------------
sub print_hash {
my $hashref = shift; # 1. parameter : hash reference
print "\n";
while ( my ( $key, $value ) = each %$hashref ) {
print "'$key'\t=>\t'$value'\n";
} # ----- end while -----
} # ---------- end of subroutine print_hash ----------
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/print-hash.pl
|
Perl
|
gpl3
| 446
|
sub new {
my $class = shift;
my $self = {
_name1 => $_[0],
_name2 => $_[1],
};
bless( $self, $class );
return $self;
} # ---------- end of subroutine new ----------
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/new.pl
|
Perl
|
gpl3
| 213
|
use File::Find; # File::Find - Traverse a directory tree
my @directory_list = ( '.' ); # directory_list used by File::Find::find()
my $files_processed = 0; # counts the files processed by process_file()
#-----------------------------------------------------------------------
# Process a single file in a directory
#-----------------------------------------------------------------------
sub process_file {
my $filename = $_; # filename without directory
my $filename_full = $File::Find::name; # filename with directory
my $directory = $File::Find::dir; # directory only
# print "$directory : $filename : $filename_full\n";
$files_processed++;
return ;
} # ---------- end of subroutine process_file ----------
#-----------------------------------------------------------------------
# Process all files in a directory recursively
#-----------------------------------------------------------------------
find( \&process_file, @directory_list );
print "\nfiles processed : $files_processed\n";
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/process-all-files-in-a-directory-recursively.pl
|
Perl
|
gpl3
| 1,084
|
#----------------------------------------------------------------------
# subroutine : print_hash_sorted
#----------------------------------------------------------------------
sub print_hash_sorted {
my $hashref = shift; # 1. parameter : hash reference
print "\n";
foreach my $key ( sort keys %$hashref ) {
print "'$key'\t=>\t'$$hashref{$key}'\n";
} # ----- end foreach -----
} # ---------- end of subroutine print_hash_sorted ----------
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/print-hash-sorted.pl
|
Perl
|
gpl3
| 471
|
package PackageName;
use strict;
use warnings;
#=======================================================================
# MODULE INTERFACE
#=======================================================================
use version; our $VERSION = qv('0.2.0');
use base qw(Exporter);
# Symbols to be exported by default
our @EXPORT = qw();
# Symbols to be exported on request
our @EXPORT_OK = qw();
# Define names for sets of symbols
our %EXPORT_TAGS = (
TAG1 => [ qw() ],
TAG2 => [ qw() ],
);
#=======================================================================
# EXPORTED PACKAGE GLOBALS (listed in @EXPORT_OK)
#=======================================================================
#=======================================================================
# NON=EXPORTED PACKAGE GLOBALS
#=======================================================================
#=======================================================================
# MODULE IMPLEMENTATION
#=======================================================================
END { } # module clean-up code
1;
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/module-interface.pl
|
Perl
|
gpl3
| 1,158
|
#
# Devel::SmallProf : variables which can be used to affect what gets profiled.
#
use Devel::SmallProf;
$DB::drop_zeros = 0; # Do not show lines which were never called: 1
$DB::grep_format = 0; # Output on a format similar to grep : 1
$DB::profile = 1; # Turn off profiling for a time: 0
%DB::packages = ('main'=>1); # Only profile code in a certain package.
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/SmallProf-variables.pl
|
Raku
|
gpl3
| 404
|
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Module Documentation
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=head1 NAME
<Module::Name> - <One line description of module's purpose>
=head1 VERSION
The initial template usually just has:
This documentation refers to <Module::Name> version 0.0.1
=head1 SYNOPSIS
use <Module::Name>;
# Brief but working code example(s) here showing the most common usage(s)
# This section will be as far as many users bother reading
# so make it as educational and exemplary as possible.
=head1 DESCRIPTION
A full description of the module and its features.
May include numerous subsections (i.e. =head2, =head3, etc.)
=head1 SUBROUTINES/METHODS
A separate section listing the public components of the module's interface.
These normally consist of either subroutines that may be exported, or methods
that may be called on objects belonging to the classes that the module provides.
Name the section accordingly.
In an object-oriented module, this section should begin with a sentence of the
form "An object of this class represents...", to give the reader a high-level
context to help them understand the methods that are subsequently described.
=head1 DIAGNOSTICS
A list of every error and warning message that the module can generate
(even the ones that will "never happen"), with a full explanation of each
problem, one or more likely causes, and any suggested remedies.
=head1 CONFIGURATION AND ENVIRONMENT
A full explanation of any configuration system(s) used by the module,
including the names and locations of any configuration files, and the
meaning of any environment variables or properties that can be set. These
descriptions must also include details of any configuration language used.
=head1 DEPENDENCIES
A list of all the other modules that this module relies upon, including any
restrictions on versions, and an indication whether these required modules are
part of the standard Perl distribution, part of the module's distribution,
or must be installed separately.
=head1 INCOMPATIBILITIES
A list of any modules that this module cannot be used in conjunction with.
This may be due to name conflicts in the interface, or competition for
system or program resources, or due to internal limitations of Perl
(for example, many modules that use source code filters are mutually
incompatible).
=head1 BUGS AND LIMITATIONS
A list of known problems with the module, together with some indication
whether they are likely to be fixed in an upcoming release.
Also a list of restrictions on the features the module does provide:
data types that cannot be handled, performance issues and the circumstances
in which they may arise, practical limitations on the size of data sets,
special cases that are not (yet) handled, etc.
The initial template usually just has:
There are no known bugs in this module.
Please report problems to <Maintainer name(s)> (<contact address>)
Patches are welcome.
=head1 AUTHOR
<Author name(s)> (<contact address>)
=head1 LICENCE AND COPYRIGHT
Copyright (c) <year> <copyright holder> (<contact address>). All rights reserved.
Followed by whatever licence you wish to release it under.
For Perl code that is often just:
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See perldoc perlartistic.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/pod-template-module.pl
|
Perl
|
gpl3
| 3,640
|
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Application Documentation
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=head1 NAME
<application name> - <One line description of application's purpose>
=head1 VERSION
The initial template usually just has:
This documentation refers to <application name> version 0.0.1
=head1 USAGE
# Brief working invocation example(s) here showing the most common usage(s)
# This section will be as far as many users ever read
# so make it as educational and exemplary as possible.
=head1 REQUIRED ARGUMENTS
A complete list of every argument that must appear on the command line.
when the application is invoked, explaining what each of them does, any
restrictions on where each one may appear (i.e. flags that must appear
before or after filenames), and how the various arguments and options
may interact (e.g. mutual exclusions, required combinations, etc.)
If all of the application's arguments are optional this section
may be omitted entirely.
=head1 OPTIONS
A complete list of every available option with which the application
can be invoked, explaining what each does, and listing any restrictions,
or interactions.
If the application has no options this section may be omitted entirely.
=head1 DESCRIPTION
A full description of the application and its features.
May include numerous subsections (i.e. =head2, =head3, etc.)
=head1 DIAGNOSTICS
A list of every error and warning message that the application can generate
(even the ones that will "never happen"), with a full explanation of each
problem, one or more likely causes, and any suggested remedies. If the
application generates exit status codes (e.g. under Unix) then list the exit
status associated with each error.
=head1 CONFIGURATION AND ENVIRONMENT
A full explanation of any configuration system(s) used by the application,
including the names and locations of any configuration files, and the
meaning of any environment variables or properties that can be set. These
descriptions must also include details of any configuration language used
=head1 DEPENDENCIES
A list of all the other modules that this module relies upon, including any
restrictions on versions, and an indication whether these required modules are
part of the standard Perl distribution, part of the module's distribution,
or must be installed separately.
=head1 INCOMPATIBILITIES
A list of any modules that this module cannot be used in conjunction with.
This may be due to name conflicts in the interface, or competition for
system or program resources, or due to internal limitations of Perl
(for example, many modules that use source code filters are mutually
incompatible).
=head1 BUGS AND LIMITATIONS
A list of known problems with the module, together with some indication
whether they are likely to be fixed in an upcoming release.
Also a list of restrictions on the features the module does provide:
data types that cannot be handled, performance issues and the circumstances
in which they may arise, practical limitations on the size of data sets,
special cases that are not (yet) handled, etc.
The initial template usually just has:
There are no known bugs in this module.
Please report problems to <Maintainer name(s)> (<contact address>)
Patches are welcome.
=head1 AUTHOR
<Author name(s)> (<contact address>)
=head1 LICENCE AND COPYRIGHT
Copyright (c) <year> <copyright holder> (<contact address>). All rights reserved.
Followed by whatever licence you wish to release it under.
For Perl code that is often just:
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See perldoc perlartistic.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/codesnippets/pod-template-application.pl
|
Perl
|
gpl3
| 3,953
|
"===================================================================================
" FILE: .vimrc
" DESCRIPTION: suggestion for a personal configuration file ~/.vimrc
" AUTHOR: Dr.-Ing. Fritz Mehner
" VERSION: 1.0
" CREATED: 23.05.2008
" REVISION: $Id: customization.vimrc,v 1.1.1.1 2012/01/28 10:22:30 mehner Exp $
"===================================================================================
"
"===================================================================================
" GENERAL SETTINGS
"===================================================================================
"
"-------------------------------------------------------------------------------
" Use Vim settings, rather then Vi settings.
" This must be first, because it changes other options as a side effect.
"-------------------------------------------------------------------------------
set nocompatible
"
"-------------------------------------------------------------------------------
" Enable file type detection. Use the default filetype settings.
" Also load indent files, to automatically do language-dependent indenting.
"-------------------------------------------------------------------------------
filetype plugin on
filetype indent on
"
"-------------------------------------------------------------------------------
" Switch syntax highlighting on.
"-------------------------------------------------------------------------------
syntax on
"
" Platform specific items:
" - central backup directory (has to be created)
" - default dictionary
" Uncomment your choice.
if has("win16") || has("win32") || has("win64") || has("win95")
"
" runtime mswin.vim
" set backupdir =$VIM\vimfiles\backupdir
" set dictionary=$VIM\vimfiles\wordlists/german.list
else
set backupdir =$HOME/.vim.backupdir
set dictionary=$HOME/.vim/wordlists/german.list,$HOME/.vim/wordlists/english.list
endif
"
"-------------------------------------------------------------------------------
" Various settings
"-------------------------------------------------------------------------------
set autoindent " copy indent from current line
set autoread " read open files again when changed outside Vim
set autowrite " write a modified buffer on each :next , ...
set backspace=indent,eol,start " backspacing over everything in insert mode
set backup " keep a backup file
set browsedir=current " which directory to use for the file browser
set complete+=k " scan the files given with the 'dictionary' option
set history=50 " keep 50 lines of command line history
set hlsearch " highlightthe last used search pattern
set incsearch " do incremental searching
set listchars=tab:>.,eol:\$ " strings to use in 'list' mode
set mouse=a " enable the use of the mouse
set nowrap " do not wrap lines
set popt=left:8pc,right:3pc " print options
set ruler " show the cursor position all the time
set shiftwidth=2 " number of spaces to use for each step of indent
set showcmd " display incomplete commands
set smartindent " smart autoindenting when starting a new line
set tabstop=2 " number of spaces that a <Tab> counts for
set visualbell " visual bell instead of beeping
set wildignore=*.bak,*.o,*.e,*~ " wildmenu: ignore these extensions
set wildmenu " command-line completion in an enhanced mode
"
"-------------------------------------------------------------------------------
" highlight paired brackets
"-------------------------------------------------------------------------------
highlight MatchParen ctermbg=blue guibg=lightyellow
"
"-------------------------------------------------------------------------------
" some additional hot keys
"-------------------------------------------------------------------------------
" F2 - write file without confirmation
" F3 - call file explorer Ex
" F4 - show tag under curser in the preview window (tagfile must exist!)
" F6 - list all errors
" F7 - display previous error
" F8 - display next error
" F12 - list buffers and edit n-th buffer
"-------------------------------------------------------------------------------
noremap <silent> <F2> :write<CR>
noremap <silent> <F3> :Explore<CR>
noremap <silent> <F4> :execute ":ptag ".expand("<cword>")<CR>
noremap <silent> <F5> :copen<CR>
noremap <silent> <F6> :cclose<CR>
noremap <silent> <F7> :cprevious<CR>
noremap <silent> <F8> :cnext<CR>
noremap <F12> :ls<CR>:edit #
"
inoremap <silent> <F2> <C-C>:write<CR>
inoremap <silent> <F3> <C-C>:Explore<CR>
inoremap <silent> <F4> <C-C>:execute ":ptag ".expand("<cword>")<CR>
inoremap <silent> <F5> <C-C>:copen<CR>
inoremap <silent> <F6> <C-C>:cclose<CR>
inoremap <silent> <F7> <C-C>:cprevious<CR>
inoremap <silent> <F8> <C-C>:cnext<CR>
inoremap <F12> <C-C>:ls<CR>:edit #
"
"-------------------------------------------------------------------------------
" comma always followed by a space
"-------------------------------------------------------------------------------
inoremap , ,<Space>
"
"-------------------------------------------------------------------------------
" autocomplete parenthesis, (brackets) and braces
"-------------------------------------------------------------------------------
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap { {}<Left>
"
vnoremap ( s()<Esc>P<Right>%
vnoremap [ s[]<Esc>P<Right>%
vnoremap { s{}<Esc>P<Right>%
"
" surround content with additional spaces
"
vnoremap ) s( )<Esc><Left>P<Right><Right>%
vnoremap ] s[ ]<Esc><Left>P<Right><Right>%
vnoremap } s{ }<Esc><Left>P<Right><Right>%
"
"-------------------------------------------------------------------------------
" autocomplete quotes (visual and select mode)
"-------------------------------------------------------------------------------
xnoremap ' s''<Esc>P<Right>
xnoremap " s""<Esc>P<Right>
xnoremap ` s``<Esc>P<Right>
"
"-------------------------------------------------------------------------------
" The current directory is the directory of the file in the current window.
"-------------------------------------------------------------------------------
if has("autocmd")
autocmd BufEnter * :lchdir %:p:h
endif
"
"-------------------------------------------------------------------------------
" Fast switching between buffers
" The current buffer will be saved before switching to the next one.
" Choose :bprevious or :bnext
"-------------------------------------------------------------------------------
noremap <silent> <s-tab> :if &modifiable && !&readonly &&
\ &modified <CR> :write<CR> :endif<CR>:bprevious<CR>
inoremap <silent> <s-tab> <C-C>:if &modifiable && !&readonly &&
\ &modified <CR> :write<CR> :endif<CR>:bprevious<CR>
"
"-------------------------------------------------------------------------------
" Leave the editor with Ctrl-q (KDE): Write all changed buffers and exit Vim
"-------------------------------------------------------------------------------
nnoremap <C-q> :wqall<CR>
"
"
"===================================================================================
" VARIOUS PLUGIN CONFIGURATIONS
"===================================================================================
"
"-------------------------------------------------------------------------------
" perl-support.vim
"-------------------------------------------------------------------------------
"
" --empty --
"
"-------------------------------------------------------------------------------
" plugin taglist.vim : toggle the taglist window
" plugin taglist.vim : define the tag file entry for Perl
"-------------------------------------------------------------------------------
"-------------------------------------------------------------------------------
noremap <silent> <F11> :TlistToggle<CR>
inoremap <silent> <F11> <C-C>:TlistToggle<CR>
"
let tlist_perl_settings = 'perl;c:constants;f:formats;l:labels;p:packages;s:subroutines;d:subroutines;o:POD;k:comments'
"
|
00000svn-vim-cfg
|
trunk/vimfiles/perl-support/rc/customization.vimrc
|
Vim Script
|
gpl3
| 8,479
|
" ============================================================================
" File: exec_menuitem.vim
" Description: plugin for NERD Tree that provides an execute file menu item
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
" Last Change: 22 July, 2009
" License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
" ============================================================================
if exists("g:loaded_nerdtree_exec_menuitem")
finish
endif
let g:loaded_nerdtree_exec_menuitem = 1
call NERDTreeAddMenuItem({
\ 'text': '(!)Execute file',
\ 'shortcut': '!',
\ 'callback': 'NERDTreeExecFile',
\ 'isActiveCallback': 'NERDTreeExecFileActive' })
function! NERDTreeExecFileActive()
let node = g:NERDTreeFileNode.GetSelected()
return !node.path.isDirectory && node.path.isExecutable
endfunction
function! NERDTreeExecFile()
let treenode = g:NERDTreeFileNode.GetSelected()
echo "==========================================================\n"
echo "Complete the command to execute (add arguments etc):\n"
let cmd = treenode.path.str({'escape': 1})
let cmd = input(':!', cmd . ' ')
if cmd != ''
exec ':!' . cmd
else
echo "Aborted"
endif
endfunction
|
00000svn-vim-cfg
|
trunk/vimfiles/nerdtree_plugin/exec_menuitem.vim
|
Vim Script
|
gpl3
| 1,614
|
" ============================================================================
" File: fs_menu.vim
" Description: plugin for the NERD Tree that provides a file system menu
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
" Last Change: 17 July, 2009
" License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
" ============================================================================
if exists("g:loaded_nerdtree_fs_menu")
finish
endif
let g:loaded_nerdtree_fs_menu = 1
call NERDTreeAddMenuItem({'text': '(a)dd a childnode', 'shortcut': 'a', 'callback': 'NERDTreeAddNode'})
call NERDTreeAddMenuItem({'text': '(m)ove the current node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'})
call NERDTreeAddMenuItem({'text': '(d)elete the current node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'})
if has("gui_mac") || has("gui_macvim")
call NERDTreeAddMenuItem({'text': '(r)eveal in Finder the current node', 'shortcut': 'r', 'callback': 'NERDTreeRevealInFinder'})
call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFile'})
call NERDTreeAddMenuItem({'text': '(q)uicklook the current node', 'shortcut': 'q', 'callback': 'NERDTreeQuickLook'})
endif
if g:NERDTreePath.CopyingSupported()
call NERDTreeAddMenuItem({'text': '(c)copy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'})
endif
"FUNCTION: s:echo(msg){{{1
function! s:echo(msg)
redraw
echomsg "NERDTree: " . a:msg
endfunction
"FUNCTION: s:echoWarning(msg){{{1
function! s:echoWarning(msg)
echohl warningmsg
call s:echo(a:msg)
echohl normal
endfunction
"FUNCTION: s:promptToDelBuffer(bufnum, msg){{{1
"prints out the given msg and, if the user responds by pushing 'y' then the
"buffer with the given bufnum is deleted
"
"Args:
"bufnum: the buffer that may be deleted
"msg: a message that will be echoed to the user asking them if they wish to
" del the buffer
function! s:promptToDelBuffer(bufnum, msg)
echo a:msg
if nr2char(getchar()) ==# 'y'
exec "silent bdelete! " . a:bufnum
endif
endfunction
"FUNCTION: NERDTreeAddNode(){{{1
function! NERDTreeAddNode()
let curDirNode = g:NERDTreeDirNode.GetSelected()
let newNodeName = input("Add a childnode\n".
\ "==========================================================\n".
\ "Enter the dir/file name to be created. Dirs end with a '/'\n" .
\ "", curDirNode.path.str() . g:NERDTreePath.Slash(), "file")
if newNodeName ==# ''
call s:echo("Node Creation Aborted.")
return
endif
try
let newPath = g:NERDTreePath.Create(newNodeName)
let parentNode = b:NERDTreeRoot.findNode(newPath.getParent())
let newTreeNode = g:NERDTreeFileNode.New(newPath)
if parentNode.isOpen || !empty(parentNode.children)
call parentNode.addChild(newTreeNode, 1)
call NERDTreeRender()
call newTreeNode.putCursorHere(1, 0)
endif
catch /^NERDTree/
call s:echoWarning("Node Not Created.")
endtry
endfunction
"FUNCTION: NERDTreeMoveNode(){{{1
function! NERDTreeMoveNode()
let curNode = g:NERDTreeFileNode.GetSelected()
let newNodePath = input("Rename the current node\n" .
\ "==========================================================\n" .
\ "Enter the new path for the node: \n" .
\ "", curNode.path.str(), "file")
if newNodePath ==# ''
call s:echo("Node Renaming Aborted.")
return
endif
try
let bufnum = bufnr(curNode.path.str())
call curNode.rename(newNodePath)
call NERDTreeRender()
"if the node is open in a buffer, ask the user if they want to
"close that buffer
if bufnum != -1
let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
call s:promptToDelBuffer(bufnum, prompt)
endif
call curNode.putCursorHere(1, 0)
redraw
catch /^NERDTree/
call s:echoWarning("Node Not Renamed.")
endtry
endfunction
" FUNCTION: NERDTreeDeleteNode() {{{1
function! NERDTreeDeleteNode()
let currentNode = g:NERDTreeFileNode.GetSelected()
let confirmed = 0
if currentNode.path.isDirectory
let choice =input("Delete the current node\n" .
\ "==========================================================\n" .
\ "STOP! To delete this entire directory, type 'yes'\n" .
\ "" . currentNode.path.str() . ": ")
let confirmed = choice ==# 'yes'
else
echo "Delete the current node\n" .
\ "==========================================================\n".
\ "Are you sure you wish to delete the node:\n" .
\ "" . currentNode.path.str() . " (yN):"
let choice = nr2char(getchar())
let confirmed = choice ==# 'y'
endif
if confirmed
try
call currentNode.delete()
call NERDTreeRender()
"if the node is open in a buffer, ask the user if they want to
"close that buffer
let bufnum = bufnr(currentNode.path.str())
if buflisted(bufnum)
let prompt = "\nNode deleted.\n\nThe file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
call s:promptToDelBuffer(bufnum, prompt)
endif
redraw
catch /^NERDTree/
call s:echoWarning("Could not remove node")
endtry
else
call s:echo("delete aborted")
endif
endfunction
" FUNCTION: NERDTreeCopyNode() {{{1
function! NERDTreeCopyNode()
let currentNode = g:NERDTreeFileNode.GetSelected()
let newNodePath = input("Copy the current node\n" .
\ "==========================================================\n" .
\ "Enter the new path to copy the node to: \n" .
\ "", currentNode.path.str(), "file")
if newNodePath != ""
"strip trailing slash
let newNodePath = substitute(newNodePath, '\/$', '', '')
let confirmed = 1
if currentNode.path.copyingWillOverwrite(newNodePath)
call s:echo("Warning: copying may overwrite files! Continue? (yN)")
let choice = nr2char(getchar())
let confirmed = choice ==# 'y'
endif
if confirmed
try
let newNode = currentNode.copy(newNodePath)
if !empty(newNode)
call NERDTreeRender()
call newNode.putCursorHere(0, 0)
endif
catch /^NERDTree/
call s:echoWarning("Could not copy node")
endtry
endif
else
call s:echo("Copy aborted.")
endif
redraw
endfunction
function! NERDTreeQuickLook()
let treenode = g:NERDTreeFileNode.GetSelected()
if treenode != {}
call system("qlmanage -p 2>/dev/null '" . treenode.path.str() . "'")
endif
endfunction
function! NERDTreeRevealInFinder()
let treenode = g:NERDTreeFileNode.GetSelected()
if treenode != {}
let x = system("open -R '" . treenode.path.str() . "'")
endif
endfunction
function! NERDTreeExecuteFile()
let treenode = g:NERDTreeFileNode.GetSelected()
if treenode != {}
let x = system("open '" . treenode.path.str() . "'")
endif
endfunction
" vim: set sw=4 sts=4 et fdm=marker:
|
00000svn-vim-cfg
|
trunk/vimfiles/nerdtree_plugin/fs_menu.vim
|
Vim Script
|
gpl3
| 8,124
|
" Description: VimBuddy statusline character
" Author: Flemming Madsen <vim@themadsens.dk>
" Modified: August 2007
" Version: 0.9.2
"
" Usage: Insert %{VimBuddy()} into your 'statusline'
"
function! VimBuddy()
" Take a copy for others to see the messages
if ! exists("s:vimbuddy_msg")
let s:vimbuddy_msg = v:statusmsg
endif
if ! exists("s:vimbuddy_warn")
let s:vimbuddy_warn = v:warningmsg
endif
if ! exists("s:vimbuddy_err")
let s:vimbuddy_err = v:errmsg
endif
if ! exists("s:vimbuddy_onemore")
let s:vimbuddy_onemore = ""
endif
if g:actual_curbuf != bufnr("%")
" Not my buffer, sleeping
return "|-o"
elseif s:vimbuddy_err != v:errmsg
let v:errmsg = v:errmsg . " "
let s:vimbuddy_err = v:errmsg
return ":-("
elseif s:vimbuddy_warn != v:warningmsg
let v:warningmsg = v:warningmsg . " "
let s:vimbuddy_warn = v:warningmsg
return "(-:"
elseif s:vimbuddy_msg != v:statusmsg
let v:statusmsg = v:statusmsg . " "
let s:vimbuddy_msg = v:statusmsg
let test = matchstr(v:statusmsg, 'lines *$')
let num = substitute(v:statusmsg, '^\([0-9]*\).*', '\1', '') + 0
" How impressed should we be
if test != "" && num > 20
let str = ":-O"
elseif test != "" && num
let str = ":-o"
else
let str = ":-/"
endif
let s:vimbuddy_onemore = str
return str
elseif s:vimbuddy_onemore != ""
let str = s:vimbuddy_onemore
let s:vimbuddy_onemore = ""
return str
endif
if ! exists("b:lastcol")
let b:lastcol = col(".")
endif
if ! exists("b:lastlineno")
let b:lastlineno = line(".")
endif
let num = b:lastcol - col(".")
let b:lastcol = col(".")
if (num == 1 || num == -1) && b:lastlineno == line(".")
" Let VimBuddy rotate his nose
let num = b:lastcol % 4
if num == 0
let ch = '/'
elseif num == 1
let ch = '-'
elseif num == 2
let ch = '\'
else
let ch = '|'
endif
return ":" . ch . ")"
endif
let b:lastlineno = line(".")
" Happiness is my favourite mood
return ":-)"
endfunction
|
00000svn-vim-cfg
|
trunk/vimfiles/plugin.Bak/vimbuddy.vim
|
Vim Script
|
gpl3
| 2,313
|
" Author: Gergely Kontra <kgergely@mcl.hu>
" Version: 0.32
" Description:
" Most recently used files appear in the file menu
"
" FEEDBACK PLEASE
"
" Installation: {{{
" - Drop it into your plugin directory
" - $MRU variable can contain the full filename, where the MRU files should
" be written. (If not specified, assumed location on UNIX is
" $HOME/.vimrecent and $VIM/_vimrecent on other systems.
" - MRU_num variable can contain the number of files to store (default is 4)
" - PATHSIZELIMIT variable can be used to limit the size of the path name
" appearing in the menu
" - To define what to do, when you select a menu item, you can adjust
" OPEN_FUNC variable. It must contain a globally available function, which
" has one parameter: the file to be processed.
" The default is 'SpWhenModified'. You can change it to
" 'SpWhenNamedOrModified', if you want (almost) always split windows, or,
" you can write your own function.
" }}}
"
" History: {{{
" 0.1: * Initial release (not published)
" 0.2: * You can access the files through your keyboard (1-9), when you are
" in the file menu
" * Bugfixes
" * When you click on an item, the function named MRU_FUNCTION will be
" called, or it will be opened in a window (in the current window,
" when the file is not modified, or in a new window othervise)
" 0.21: * You can adjust PATHSIZELIMIT to limit the path size appeared in
" the menu
" * OPEN_FUNC is now really OPEN_FUNC :)
" * Delete buffer, even when 'hidden' is set
" Thanks to Roger Pilkey for the bug report
" 0.3: * Use clientserver feature to synchronize the menu instances
" 0.31: * Shut up clientserver stuff
" 0.32: * Fixed filename escaping (Thx to Fritz Mehner for the patch)
" }}}
" TODO:
" Are all valid filenames escaped?
"
if !exists('SpWhenModified') "integration with FavMenu {{{
fu! SpWhenModified(f) "splits only when curr buf is modified
let fesc = escape( a:f, " %" )
if &mod
exe 'sp '.fesc
el
exe 'e '.fesc
en
endf
fu! SpWhenNamedOrModified(f) "splits, when curr buf has name, or is modified
if bufname('%')!='' || &mod
exe 'sp '.a:f
el
exe 'e '.a:f
en
endf
fu! OpenFile()
if exists('g:OPEN_FUNC')
retu g:OPEN_FUNC
el
retu 'SpWhenModified'
en
endf
fu! TruncPath(path)
let p=a:path
let pathlen=strlen(p)
if exists('g:PATHSIZELIMIT') && pathlen>g:PATHSIZELIMIT
let cut=match(p,'[/\\]',pathlen-g:PATHSIZELIMIT)
if cut>0 && cut<pathlen
let p='\.\.\.'.strpart(p,cut)
en
en
retu p
endf
end "}}}
fu! s:SendAll(what) "{{{
exe 'cal '.a:what
if has('clientserver')
let servers=serverlist()
let pos=0
let re="[^\n]\\+" "Thanx to Mark Hillebrand
wh match(servers,re,pos) != -1
let s=matchstr(servers,re,pos)
let pos=pos+strlen(s)+1
if v:servername!=s
cal remote_expr(s,a:what)
en
endw
en
endf "}}}
fu! MRUDestroy() " must be global :( {{{
sv $MRU|set bh=delete
" First cleanup old MRU's
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
" WARNING: Keep next 2 lines in sync with the :g below
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
g/^.\+$/sil! exe 'aun &File.'.
\'[&'.line('.').']\ '.
\escape(fnamemodify(getline('.'),':p:t'),' \.')
" Figure out fullname
q!
endf "}}}
fu! MRURefresh() " must be global :( {{{
sv $MRU|set bh=delete
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
" WARNING: Keep next command in synx with the :g above
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
g/^.\+$/exe 'amenu 10.'.(line('.')+511).' &File.'.
\'[&'.line('.').']\ '.
\escape(fnamemodify(getline('.'),':p:t'),' \.').
\'<Tab>'.
\TruncPath(escape(fnamemodify(getline('.'),':p:h'),' \.')).
\' :call <C-R>=OpenFile()<CR>("'.
\escape(getline('.'),'\').'")<CR>'
q!
endf "}}}
fu! s:MRUAdd(f) "{{{
"let lz=&lz|se lz
if a:f!='//' && !buflisted(a:f) " if param not good...
retu
end
sil! cal s:SendAll('MRUDestroy()')
if a:f!='//' " add this file to the top (if real file)
let fullname=fnamemodify(a:f,':p')
let v=virtcol('.')|let l=line('.')
norm H
let hl=line('.')
vs $MRU
"let b=bufnr('%')|e! $MRU
setl nobl bh=delete ma
if search('^\V'.escape(fullname,'\').'\$','w')
move 0
el
exe 'norm ggO'.fullname."\<Esc>"
en
let num=1+(exists('g:MRU_num') ? g:MRU_num : 4)
sil! exe num.',$d _'
let pm=&pm|let &pm=''
wq
" w|exe 'b' b " syntax lost!
let &pm=pm
exe 'norm' hl.'Gzt'.l.'G'.v.'|'
en
cal s:SendAll('MRURefresh()')
"let &lz=lz
endf "}}}
if !exists('$MRU')
if has('unix')
let $MRU=$HOME.'/.vimrecent'
el
let $MRU=$VIM.'\_vimrecent'
en
en
am 10.511 &File.-SepMRU- <Nop>
sil cal MRUDestroy()|sil cal MRURefresh()
aug MRU
au!
au BufWritePost * sil! call <SID>MRUAdd(@%)
aug END
" vim:ft=vim:fdm=marker:
|
00000svn-vim-cfg
|
trunk/vimfiles/plugin.Bak/MRU.vim
|
Vim Script
|
gpl3
| 5,037
|
" Author: Gergely Kontra <kgergely@mcl.hu>
" Version: 0.32
" Description:
" Most recently used files appear in the file menu
"
" FEEDBACK PLEASE
"
" Installation: {{{
" - Drop it into your plugin directory
" - $MRU variable can contain the full filename, where the MRU files should
" be written. (If not specified, assumed location on UNIX is
" $HOME/.vimrecent and $VIM/_vimrecent on other systems.
" - MRU_num variable can contain the number of files to store (default is 4)
" - PATHSIZELIMIT variable can be used to limit the size of the path name
" appearing in the menu
" - To define what to do, when you select a menu item, you can adjust
" OPEN_FUNC variable. It must contain a globally available function, which
" has one parameter: the file to be processed.
" The default is 'SpWhenModified'. You can change it to
" 'SpWhenNamedOrModified', if you want (almost) always split windows, or,
" you can write your own function.
" }}}
"
" History: {{{
" 0.1: * Initial release (not published)
" 0.2: * You can access the files through your keyboard (1-9), when you are
" in the file menu
" * Bugfixes
" * When you click on an item, the function named MRU_FUNCTION will be
" called, or it will be opened in a window (in the current window,
" when the file is not modified, or in a new window othervise)
" 0.21: * You can adjust PATHSIZELIMIT to limit the path size appeared in
" the menu
" * OPEN_FUNC is now really OPEN_FUNC :)
" * Delete buffer, even when 'hidden' is set
" Thanks to Roger Pilkey for the bug report
" 0.3: * Use clientserver feature to synchronize the menu instances
" 0.31: * Shut up clientserver stuff
" 0.32: * Fixed filename escaping (Thx to Fritz Mehner for the patch)
" }}}
" TODO:
" Are all valid filenames escaped?
"
if !exists('SpWhenModified') "integration with FavMenu {{{
fu! SpWhenModified(f) "splits only when curr buf is modified
let fesc = escape( a:f, " %" )
if &mod
exe 'sp '.fesc
el
exe 'e '.fesc
en
endf
fu! SpWhenNamedOrModified(f) "splits, when curr buf has name, or is modified
if bufname('%')!='' || &mod
exe 'sp '.a:f
el
exe 'e '.a:f
en
endf
fu! OpenFile()
if exists('g:OPEN_FUNC')
retu g:OPEN_FUNC
el
retu 'SpWhenModified'
en
endf
fu! TruncPath(path)
let p=a:path
let pathlen=strlen(p)
if exists('g:PATHSIZELIMIT') && pathlen>g:PATHSIZELIMIT
let cut=match(p,'[/\\]',pathlen-g:PATHSIZELIMIT)
if cut>0 && cut<pathlen
let p='\.\.\.'.strpart(p,cut)
en
en
retu p
endf
end "}}}
fu! s:SendAll(what) "{{{
exe 'cal '.a:what
if has('clientserver')
let servers=serverlist()
let pos=0
let re="[^\n]\\+" "Thanx to Mark Hillebrand
wh match(servers,re,pos) != -1
let s=matchstr(servers,re,pos)
let pos=pos+strlen(s)+1
if v:servername!=s
cal remote_expr(s,a:what)
en
endw
en
endf "}}}
fu! MRUDestroy() " must be global :( {{{
sv $MRU|set bh=delete
" First cleanup old MRU's
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
" WARNING: Keep next 2 lines in sync with the :g below
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
g/^.\+$/sil! exe 'aun &File.'.
\'[&'.line('.').']\ '.
\escape(fnamemodify(getline('.'),':p:t'),' \.')
" Figure out fullname
q!
endf "}}}
fu! MRURefresh() " must be global :( {{{
sv $MRU|set bh=delete
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
" WARNING: Keep next command in synx with the :g above
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
g/^.\+$/exe 'amenu 10.'.(line('.')+511).' &File.'.
\'[&'.line('.').']\ '.
\escape(fnamemodify(getline('.'),':p:t'),' \.').
\'<Tab>'.
\TruncPath(escape(fnamemodify(getline('.'),':p:h'),' \.')).
\' :call <C-R>=OpenFile()<CR>("'.
\escape(getline('.'),'\').'")<CR>'
q!
endf "}}}
fu! s:MRUAdd(f) "{{{
"let lz=&lz|se lz
if a:f!='//' && !buflisted(a:f) " if param not good...
retu
end
sil! cal s:SendAll('MRUDestroy()')
if a:f!='//' " add this file to the top (if real file)
let fullname=fnamemodify(a:f,':p')
let v=virtcol('.')|let l=line('.')
norm H
let hl=line('.')
vs $MRU
"let b=bufnr('%')|e! $MRU
setl nobl bh=delete ma
if search('^\V'.escape(fullname,'\').'\$','w')
move 0
el
exe 'norm ggO'.fullname."\<Esc>"
en
let num=1+(exists('g:MRU_num') ? g:MRU_num : 4)
sil! exe num.',$d _'
let pm=&pm|let &pm=''
wq
" w|exe 'b' b " syntax lost!
let &pm=pm
exe 'norm' hl.'Gzt'.l.'G'.v.'|'
en
cal s:SendAll('MRURefresh()')
"let &lz=lz
endf "}}}
if !exists('$MRU')
if has('unix')
let $MRU=$HOME.'/.vimrecent'
el
let $MRU=$VIM.'\_vimrecent'
en
en
am 10.511 &File.-SepMRU- <Nop>
sil cal MRUDestroy()|sil cal MRURefresh()
aug MRU
au!
au BufWritePost * sil! call <SID>MRUAdd(@%)
aug END
" vim:ft=vim:fdm=marker:
|
00000svn-vim-cfg
|
trunk/vimfiles/plugin.Bak/.svn/text-base/MRU.vim.svn-base
|
Vim Script
|
gpl3
| 5,037
|
"=============================================================================
" Copyright: Copyright (C) 2001-2007 Jeff Lanzarotta
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
" bufexplorer.vim is provided *as is* and comes with no
" warranty of any kind, either expressed or implied. In no
" event will the copyright holder be liable for any damages
" resulting from the use of this software.
" Name Of File: bufexplorer.vim
" Description: Buffer Explorer Vim Plugin
" Maintainer: Jeff Lanzarotta (delux256-vim at yahoo dot com)
" Last Changed: Friday, 21 December 2007
" Version: See g:bufexplorer_version for version number.
" Usage: This file should reside in the plugin directory and be
" automatically sourced.
"
" You may use the default keymappings of
"
" <Leader>be - Opens BufExplorer
"
" Or you can use
"
" ":BufExplorer" - Opens BufExplorer
"
" For more help see supplied documentation.
" History: See supplied documentation.
"=============================================================================
" Exit quickly if already running or when 'compatible' is set. {{{1
if exists("g:bufexplorer_version") || &cp
finish
endif
"1}}}
" Version number
let g:bufexplorer_version = "7.1.7"
" Check for Vim version 700 or greater {{{1
if v:version < 700
echo "Sorry, bufexplorer ".g:bufexplorer_version."\nONLY runs with Vim 7.0 and greater."
finish
endif
" Public Interface {{{1
nmap <silent> <unique> <Leader>be :BufExplorer<CR>
" Create commands {{{1
command BufExplorer :call StartBufExplorer(has ("gui") ? "drop" : "hide edit")
" Set {{{1
function s:Set(var, default)
if !exists(a:var)
if type(a:default)
exec "let" a:var "=" string(a:default)
else
exec "let" a:var "=" a:default
endif
return 1
endif
return 0
endfunction
" Default values {{{1
call s:Set("g:bufExplorerDefaultHelp", 1) " Show default help?
call s:Set("g:bufExplorerDetailedHelp", 0) " Show detailed help?
call s:Set("g:bufExplorerFindActive", 1) " When selecting an active buffer, take you to the window where it is active?
call s:Set("g:bufExplorerReverseSort", 0) " sort reverse?
call s:Set("g:bufExplorerShowDirectories", 1) " (Dir's are added by commands like ':e .')
call s:Set("g:bufExplorerShowRelativePath", 0) " Show listings with relative or absolute paths?
call s:Set("g:bufExplorerShowUnlisted", 0) " Show unlisted buffers?
call s:Set("g:bufExplorerSortBy", "mru") " Sorting methods are in s:sort_by:
call s:Set("g:bufExplorerSplitOutPathName", 1) " Split out path and file name?
" Global variables {{{1
let s:MRUList = []
let s:running = 0
let s:sort_by = ["number", "name", "fullpath", "mru", "extension"]
let s:tabSpace = []
let s:types = {"fullname": ':p', "path": ':p:h', "relativename": ':~:.', "relativepath": ':~:.:h', "shortname": ':t'}
let s:originBuffer = 0
" Setup the autocommands that handle the MRUList and other stuff. {{{1
autocmd VimEnter * call s:Setup()
" Setup {{{1
function s:Setup()
" Build initial MRUList.
let s:MRUList = range(1, bufnr('$'))
let s:tabSpace = []
" Now that the MRUList is created, add the other autocmds.
autocmd BufEnter,BufNew * call s:ActivateBuffer()
autocmd BufWipeOut * call s:DeactivateBuffer(1)
autocmd BufDelete * call s:DeactivateBuffer(0)
autocmd BufWinEnter \[BufExplorer\] call s:Initialize()
autocmd BufWinLeave \[BufExplorer\] call s:Cleanup()
endfunction
" ActivateBuffer {{{1
function s:ActivateBuffer()
let b = bufnr("%")
let l = get(s:tabSpace, tabpagenr(), [])
if empty(l) || index(l, b) == -1
call add(l, b)
let s:tabSpace[tabpagenr()] = l
endif
call s:MRUPush(b)
endfunction
" DeactivateBuffer {{{1
function s:DeactivateBuffer(remove)
"echom "afile:" expand("<afile>")
"echom "bufnr, afile:" bufnr(expand("<afile>"))
"echom "buffers:" string(tabpagebuflist())
"echom "MRU before:" string(s:MRUList)
if a:remove
call s:MRUPop(bufnr(expand("<afile>")))
end
"echom "MRU after:" string(s:MRUList)
endfunction
" MRUPop {{{1
function s:MRUPop(buf)
call filter(s:MRUList, 'v:val != '.a:buf)
endfunction
" MRUPush {{{1
function s:MRUPush(buf)
" Skip temporary buffer with buftype set.
" Don't add the BufExplorer window to the list.
if !empty(getbufvar(a:buf, "&buftype")) ||
\ !buflisted(a:buf) || empty(bufname(a:buf)) ||
\ fnamemodify(bufname(a:buf), ":t") == "[BufExplorer]"
return
end
call s:MRUPop(a:buf)
call insert(s:MRUList,a:buf)
endfunction
" Initialize {{{1
function s:Initialize()
let s:_insertmode = &insertmode
set noinsertmode
let s:_showcmd = &showcmd
set noshowcmd
let s:_cpo = &cpo
set cpo&vim
let s:_report = &report
let &report = 10000
let s:_list = &list
set nolist
setlocal nonumber
setlocal foldcolumn=0
setlocal nofoldenable
setlocal cursorline
setlocal nospell
set nobuflisted
let s:running = 1
endfunction
" Cleanup {{{1
function s:Cleanup()
let &insertmode = s:_insertmode
let &showcmd = s:_showcmd
let &cpo = s:_cpo
let &report = s:_report
let &list = s:_list
let s:running = 0
delmarks!
endfunction
" StartBufExplorer {{{1
function StartBufExplorer(open)
let name = '[BufExplorer]'
if !has("win32")
" On non-Windows boxes, escape the name so that is shows up correctly.
let name = escape(name, "[]")
endif
" Make sure there is only one explorer open at a time.
if s:running == 1
" Go to the open buffer.
if has("gui")
exec "drop" name
endif
return
endif
let s:originBuffer = bufnr("%")
silent let s:raw_buffer_listing = s:GetBufferInfo()
let copy = copy(s:raw_buffer_listing)
if (g:bufExplorerShowUnlisted == 0)
call filter(copy, 'v:val.attributes !~ "u"')
endif
if (!empty(copy))
call filter(copy, 'v:val.shortname !~ "\\\[No Name\\\]"')
endif
if len(copy) <= 1
echo "\r"
call s:Warn("Sorry, there are no more buffers to explore")
return
endif
if !exists("b:displayMode") || b:displayMode != "winmanager"
" Do not use keepalt when opening bufexplorer to allow the buffer that we
" are leaving to become the new alternate buffer
exec "silent keepjumps ".a:open." ".name
endif
call s:DisplayBufferList()
endfunction
" DisplayBufferList {{{1
function s:DisplayBufferList()
setlocal bufhidden=delete
setlocal buftype=nofile
setlocal modifiable
setlocal noswapfile
setlocal nowrap
call s:SetupSyntax()
call s:MapKeys()
call setline(1, s:CreateHelp())
call s:BuildBufferList()
call cursor(s:firstBufferLine, 1)
if !g:bufExplorerResize
normal! zz
endif
setlocal nomodifiable
endfunction
" MapKeys {{{1
function s:MapKeys()
if exists("b:displayMode") && b:displayMode == "winmanager"
nnoremap <buffer> <silent> <tab> :call <SID>SelectBuffer()<cr>
endif
nnoremap <buffer> <silent> <F1> :call <SID>ToggleHelp()<cr>
nnoremap <buffer> <silent> <2-leftmouse> :call <SID>SelectBuffer()<cr>
nnoremap <buffer> <silent> <cr> :call <SID>SelectBuffer()<cr>
nnoremap <buffer> <silent> t :call <SID>SelectBuffer("tab")<cr>
nnoremap <buffer> <silent> <s-cr> :call <SID>SelectBuffer("tab")<cr>
nnoremap <buffer> <silent> d :call <SID>RemoveBuffer("wipe")<cr>
nnoremap <buffer> <silent> D :call <SID>RemoveBuffer("delete")<cr>
nnoremap <buffer> <silent> m :call <SID>MRUListShow()<cr>
nnoremap <buffer> <silent> p :call <SID>ToggleSplitOutPathName()<cr>
nnoremap <buffer> <silent> q :call <SID>Close()<cr>
nnoremap <buffer> <silent> r :call <SID>SortReverse()<cr>
nnoremap <buffer> <silent> R :call <SID>ToggleShowRelativePath()<cr>
nnoremap <buffer> <silent> s :call <SID>SortSelect()<cr>
nnoremap <buffer> <silent> u :call <SID>ToggleShowUnlisted()<cr>
nnoremap <buffer> <silent> f :call <SID>ToggleFindActive()<cr>
for k in ["G", "n", "N", "L", "M", "H"]
exec "nnoremap <buffer> <silent>" k ":keepjumps normal!" k."<cr>"
endfor
endfunction
" SetupSyntax {{{1
function s:SetupSyntax()
if has("syntax")
syn match bufExplorerHelp "^\".*" contains=bufExplorerSortBy,bufExplorerMapping,bufExplorerTitle,bufExplorerSortType,bufExplorerToggleSplit,bufExplorerToggleOpen
syn match bufExplorerOpenIn "Open in \w\+ window" contained
syn match bufExplorerSplit "\w\+ split" contained
syn match bufExplorerSortBy "Sorted by .*" contained contains=bufExplorerOpenIn,bufExplorerSplit
syn match bufExplorerMapping "\" \zs.\+\ze :" contained
syn match bufExplorerTitle "Buffer Explorer.*" contained
syn match bufExplorerSortType "'\w\{-}'" contained
syn match bufExplorerBufNbr /^\s*\d\+/
syn match bufExplorerToggleSplit "toggle split type" contained
syn match bufExplorerToggleOpen "toggle open mode" contained
syn match bufExplorerModBuf /^\s*\d\+.\{4}+.*/
syn match bufExplorerLockedBuf /^\s*\d\+.\{3}[\-=].*/
syn match bufExplorerHidBuf /^\s*\d\+.\{2}h.*/
syn match bufExplorerActBuf /^\s*\d\+.\{2}a.*/
syn match bufExplorerCurBuf /^\s*\d\+.%.*/
syn match bufExplorerAltBuf /^\s*\d\+.#.*/
syn match bufExplorerUnlBuf /^\s*\d\+u.*/
hi def link bufExplorerBufNbr Number
hi def link bufExplorerMapping NonText
hi def link bufExplorerHelp Special
hi def link bufExplorerOpenIn Identifier
hi def link bufExplorerSortBy String
hi def link bufExplorerSplit NonText
hi def link bufExplorerTitle NonText
hi def link bufExplorerSortType bufExplorerSortBy
hi def link bufExplorerToggleSplit bufExplorerSplit
hi def link bufExplorerToggleOpen bufExplorerOpenIn
hi def link bufExplorerActBuf Identifier
hi def link bufExplorerAltBuf String
hi def link bufExplorerCurBuf Type
hi def link bufExplorerHidBuf Constant
hi def link bufExplorerLockedBuf Special
hi def link bufExplorerModBuf Exception
hi def link bufExplorerUnlBuf Comment
endif
endfunction
" ToggleHelp {{{1
function s:ToggleHelp()
let g:bufExplorerDetailedHelp = !g:bufExplorerDetailedHelp
setlocal modifiable
" Save position
normal! ma
" Remove old header
if (s:firstBufferLine > 1)
exec "keepjumps 1,".(s:firstBufferLine - 1) "d _"
endif
call append(0, s:CreateHelp())
silent! normal! g`a
delmarks a
setlocal nomodifiable
if exists("b:displayMode") && b:displayMode == "winmanager"
call WinManagerForceReSize("BufExplorer")
end
endfunction
" GetHelpStatus {{{1
function s:GetHelpStatus()
let ret = '" Sorted by '.((g:bufExplorerReverseSort == 1) ? "reverse " : "").g:bufExplorerSortBy
let ret .= ' | '.((g:bufExplorerFindActive == 0) ? "Don't " : "")."Locate buffer"
let ret .= ((g:bufExplorerShowUnlisted == 0) ? "" : " | Show unlisted")
let ret .= ' | '.((g:bufExplorerShowRelativePath == 0) ? "Absolute" : "Relative")
let ret .= ' '.((g:bufExplorerSplitOutPathName == 0) ? "Full" : "Split")." path"
return ret
endfunction
" CreateHelp {{{1
function s:CreateHelp()
if g:bufExplorerDefaultHelp == 0 && g:bufExplorerDetailedHelp == 0
let s:firstBufferLine = 1
return []
endif
let header = []
if g:bufExplorerDetailedHelp == 1
call add(header, '" Buffer Explorer ('.g:bufexplorer_version.')')
call add(header, '" --------------------------')
call add(header, '" <F1> : toggle this help')
call add(header, '" <enter> or Mouse-Double-Click : open buffer under cursor')
call add(header, '" <shift-enter> or t : open buffer in another tab')
call add(header, '" d : wipe buffer')
call add(header, '" D : delete buffer')
call add(header, '" p : toggle spliting of file and path name')
call add(header, '" q : quit')
call add(header, '" r : reverse sort')
call add(header, '" R : toggle showing relative or full paths')
call add(header, '" u : toggle showing unlisted buffers')
call add(header, '" s : select sort field '.string(s:sort_by).'')
call add(header, '" f : toggle find active buffer')
else
call add(header, '" Press <F1> for Help')
endif
call add(header, s:GetHelpStatus())
call add(header, '"=')
let s:firstBufferLine = len(header) + 1
return header
endfunction
" GetBufferInfo {{{1
function s:GetBufferInfo()
redir => bufoutput
buffers!
redir END
let [all, allwidths, listedwidths] = [[], {}, {}]
for n in keys(s:types)
let allwidths[n] = []
let listedwidths[n] = []
endfor
for buf in split(bufoutput, '\n')
let bits = split(buf, '"')
let b = {"attributes": bits[0], "line": substitute(bits[2], '\s*', '', '')}
for [key, val] in items(s:types)
let b[key] = fnamemodify(bits[1], val)
endfor
if getftype(b.fullname) == "dir" && g:bufExplorerShowDirectories == 1
let b.shortname = "<DIRECTORY>"
end
call add(all, b)
for n in keys(s:types)
call add(allwidths[n], len(b[n]))
if b.attributes !~ "u"
call add(listedwidths[n], len(b[n]))
endif
endfor
endfor
let [s:allpads, s:listedpads] = [{}, {}]
for n in keys(s:types)
let s:allpads[n] = repeat(' ', max(allwidths[n]))
let s:listedpads[n] = repeat(' ', max(listedwidths[n]))
endfor
return all
endfunction
" BuildBufferList {{{1
function s:BuildBufferList()
let lines = []
" Loop through every buffer.
for buf in s:raw_buffer_listing
if (!g:bufExplorerShowUnlisted && buf.attributes =~ "u")
" skip unlisted buffers if we are not to show them
continue
endif
let line = buf.attributes." "
if g:bufExplorerSplitOutPathName
let type = (g:bufExplorerShowRelativePath) ? "relativepath" : "path"
let path = buf[type]
let pad = (g:bufExplorerShowUnlisted) ? s:allpads.shortname : s:listedpads.shortname
let line .= buf.shortname." ".strpart(pad.path, len(buf.shortname))
else
let type = (g:bufExplorerShowRelativePath) ? "relativename" : "fullname"
let path = buf[type]
let line .= path
endif
let pads = (g:bufExplorerShowUnlisted) ? s:allpads : s:listedpads
if !empty(pads[type])
let line .= strpart(pads[type], len(path))." "
endif
let line .= buf.line
call add(lines, line)
endfor
call setline(s:firstBufferLine, lines)
call s:SortListing()
endfunction
" SelectBuffer {{{1
function s:SelectBuffer(...)
" Sometimes messages are not cleared when we get here so it looks like an
" error has occurred when it really has not.
echo ""
" Are we on a line with a file name?
if line('.') < s:firstBufferLine
exec "normal! \<cr>"
return
endif
let _bufNbr = str2nr(getline('.'))
if exists("b:displayMode") && b:displayMode == "winmanager"
let bufname = expand("#"._bufNbr.":p")
call WinManagerFileEdit(bufname, 0)
return
end
if bufexists(_bufNbr)
if bufnr("#") == _bufNbr
return s:Close()
endif
if (a:0 == 1) && (a:1 == "tab")
" Restore [BufExplorer] buffer.
exec "keepjumps silent buffer!".s:originBuffer
let tabNbr = s:GetTabNbr(_bufNbr)
if tabNbr == 0
" _bufNbr is not opened in any tabs
exec "999tab split +buffer" . _bufNbr
else
" _bufNbr is already opened in tab(s)
exec tabNbr . "tabnext"
" Focus window.
exec s:GetWinNbr(tabNbr, _bufNbr) . "wincmd w"
endif
else
" If the buf is active, then go to the tab where it is opened.
if bufloaded(_bufNbr) && g:bufExplorerFindActive
call s:Close()
let bufname = expand("#"._bufNbr.":p")
exec bufname ? "drop ".escape(bufname, " ") : "buffer "._bufNbr
endif
" Switch to the buffer.
exec "keepalt keepjumps silent b!" _bufNbr
endif
" Make the buffer 'listed' again.
call setbufvar(_bufNbr, "&buflisted", "1")
else
call s:Error("Sorry, that buffer no longer exists, please select another")
call s:DeleteBuffer(_bufNbr, "wipe")
endif
endfunction
" RemoveBuffer {{{1
function s:RemoveBuffer(mode)
" Are we on a line with a file name?
if line('.') < s:firstBufferLine
return
endif
" Do not allow this buffer to be deleted if it is the last one.
if len(s:MRUList) == 1
call s:Error("Sorry, you are not allowed to delete the last buffer")
return
endif
" These commands are to temporarily suspend the activity of winmanager.
if exists("b:displayMode") && b:displayMode == "winmanager"
call WinManagerSuspendAUs()
end
let _bufNbr = str2nr(getline('.'))
if getbufvar(_bufNbr, '&modified') == 1
call s:Error("Sorry, no write since last change for buffer "._bufNbr.", unable to delete")
return
else
" Okay, everything is good, delete or wipe the buffer.
call s:DeleteBuffer(_bufNbr, a:mode)
endif
" Reactivate winmanager autocommand activity.
if exists("b:displayMode") && b:displayMode == "winmanager"
call WinManagerForceReSize("BufExplorer")
call WinManagerResumeAUs()
end
endfunction
" DeleteBuffer {{{1
function s:DeleteBuffer(buf, mode)
" This routine assumes that the buffer to be removed is on the current line.
try
if a:mode == "wipe"
exe "silent bw" a:buf
else
exe "silent bd" a:buf
end
setlocal modifiable
normal! "_dd
setlocal nomodifiable
" Delete the buffer from the raw buffer list.
call filter(s:raw_buffer_listing, 'v:val.attributes !~ " '.a:buf.' "')
catch
call s:Error(v:exception)
endtry
endfunction
" Close {{{1
function s:Close()
" Get only the listed buffers.
let listed = filter(copy(s:MRUList), "buflisted(v:val)")
for b in reverse(listed[0:1])
exec "keepjumps silent b ".b
endfor
endfunction
" ToggleSplitOutPathName {{{1
function s:ToggleSplitOutPathName()
let g:bufExplorerSplitOutPathName = !g:bufExplorerSplitOutPathName
call s:RebuildBufferList()
call s:UpdateHelpStatus()
endfunction
" ToggleShowRelativePath {{{1
function s:ToggleShowRelativePath()
let g:bufExplorerShowRelativePath = !g:bufExplorerShowRelativePath
call s:RebuildBufferList()
call s:UpdateHelpStatus()
endfunction
" ToggleShowUnlisted {{{1
function s:ToggleShowUnlisted()
let g:bufExplorerShowUnlisted = !g:bufExplorerShowUnlisted
let num_bufs = s:RebuildBufferList(g:bufExplorerShowUnlisted == 0)
call s:UpdateHelpStatus()
endfunction
" ToggleFindActive {{{1
function s:ToggleFindActive()
let g:bufExplorerFindActive = !g:bufExplorerFindActive
call s:UpdateHelpStatus()
endfunction
" RebuildBufferList {{{1
function s:RebuildBufferList(...)
setlocal modifiable
let curPos = getpos('.')
if a:0
" Clear the list first.
exec "keepjumps ".s:firstBufferLine.',$d "_'
endif
let num_bufs = s:BuildBufferList()
call setpos('.', curPos)
setlocal nomodifiable
return num_bufs
endfunction
" UpdateHelpStatus {{{1
function s:UpdateHelpStatus()
setlocal modifiable
let text = s:GetHelpStatus()
call setline(s:firstBufferLine - 2, text)
setlocal nomodifiable
endfunction
" MRUCmp {{{1
function s:MRUCmp(line1, line2)
return index(s:MRUList, str2nr(a:line1)) - index(s:MRUList, str2nr(a:line2))
endfunction
" SortReverse {{{1
function s:SortReverse()
let g:bufExplorerReverseSort = !g:bufExplorerReverseSort
call s:ReSortListing()
endfunction
" SortSelect {{{1
function s:SortSelect()
let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy)+1, s:sort_by[0])
call s:ReSortListing()
endfunction
" ReSortListing {{{1
function s:ReSortListing()
setlocal modifiable
let curPos = getpos('.')
call s:SortListing()
call s:UpdateHelpStatus()
call setpos('.', curPos)
setlocal nomodifiable
endfunction
" SortListing {{{1
function s:SortListing()
let sort = s:firstBufferLine.",$sort".((g:bufExplorerReverseSort == 1) ? "!": "")
if g:bufExplorerSortBy == "number"
" Easiest case.
exec sort 'n'
elseif g:bufExplorerSortBy == "name"
if g:bufExplorerSplitOutPathName
exec sort 'ir /\d.\{7}\zs\f\+\ze/'
else
exec sort 'ir /\zs[^\/\\]\+\ze\s*line/'
endif
elseif g:bufExplorerSortBy == "fullpath"
if g:bufExplorerSplitOutPathName
" Sort twice - first on the file name then on the path.
exec sort 'ir /\d.\{7}\zs\f\+\ze/'
endif
exec sort 'ir /\zs\f\+\ze\s\+line/'
elseif g:bufExplorerSortBy == "extension"
exec sort 'ir /\.\zs\w\+\ze\s/'
elseif g:bufExplorerSortBy == "mru"
let l = getline(s:firstBufferLine, "$")
call sort(l, "<SID>MRUCmp")
if g:bufExplorerReverseSort
call reverse(l)
endif
call setline(s:firstBufferLine, l)
endif
endfunction
" MRUListShow {{{1
function s:MRUListShow()
echomsg "MRUList=".string(s:MRUList)
endfunction
" Error {{{1
function s:Error(msg)
echohl ErrorMsg | echo a:msg | echohl none
endfunction
" Warn {{{1
function s:Warn(msg)
echohl WarningMsg | echo a:msg | echohl none
endfunction
" GetTabNbr {{{1
function s:GetTabNbr(bufNbr)
" Searching buffer bufno, in tabs.
for i in range(tabpagenr("$"))
if index(tabpagebuflist(i + 1), a:bufNbr) != -1
return i + 1
endif
endfor
return 0
endfunction
" GetWinNbr" {{{1
function s:GetWinNbr(tabNbr, bufNbr)
" window number in tabpage.
return index(tabpagebuflist(a:tabNbr), a:bufNbr) + 1
endfunction
" Winmanager Integration {{{1
let g:BufExplorer_title = "\[Buf\ List\]"
call s:Set("g:bufExplorerResize", 1)
call s:Set("g:bufExplorerMaxHeight", 25) " Handles dynamic resizing of the window.
" Function to start display. Set the mode to 'winmanager' for this buffer.
" This is to figure out how this plugin was called. In a standalone fashion
" or by winmanager.
function BufExplorer_Start()
let b:displayMode = "winmanager"
call StartBufExplorer("e")
endfunction
" Returns whether the display is okay or not.
function BufExplorer_IsValid()
return 0
endfunction
" Handles dynamic refreshing of the window.
function BufExplorer_Refresh()
let b:displayMode = "winmanager"
call StartBufExplorer("e")
endfunction
function BufExplorer_ReSize()
if !g:bufExplorerResize
return
end
let nlines = min([line("$"), g:bufExplorerMaxHeight])
exe nlines." wincmd _"
" The following lines restore the layout so that the last file line is also
" the last window line. Sometimes, when a line is deleted, although the
" window size is exactly equal to the number of lines in the file, some of
" the lines are pushed up and we see some lagging '~'s.
let pres = getpos(".")
exe $
let _scr = &scrolloff
let &scrolloff = 0
normal! z-
let &scrolloff = _scr
call setpos(".", pres)
endfunction
"}}}1
" vim:ft=vim foldmethod=marker sw=2
|
00000svn-vim-cfg
|
trunk/vimfiles/plugin.Bak/.svn/text-base/bufexplorer.vim.svn-base
|
Vim Script
|
gpl3
| 23,022
|
"=============================================================================
" Copyright: Copyright (C) 2001-2007 Jeff Lanzarotta
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
" bufexplorer.vim is provided *as is* and comes with no
" warranty of any kind, either expressed or implied. In no
" event will the copyright holder be liable for any damages
" resulting from the use of this software.
" Name Of File: bufexplorer.vim
" Description: Buffer Explorer Vim Plugin
" Maintainer: Jeff Lanzarotta (delux256-vim at yahoo dot com)
" Last Changed: Friday, 21 December 2007
" Version: See g:bufexplorer_version for version number.
" Usage: This file should reside in the plugin directory and be
" automatically sourced.
"
" You may use the default keymappings of
"
" <Leader>be - Opens BufExplorer
"
" Or you can use
"
" ":BufExplorer" - Opens BufExplorer
"
" For more help see supplied documentation.
" History: See supplied documentation.
"=============================================================================
" Exit quickly if already running or when 'compatible' is set. {{{1
if exists("g:bufexplorer_version") || &cp
finish
endif
"1}}}
" Version number
let g:bufexplorer_version = "7.1.7"
" Check for Vim version 700 or greater {{{1
if v:version < 700
echo "Sorry, bufexplorer ".g:bufexplorer_version."\nONLY runs with Vim 7.0 and greater."
finish
endif
" Public Interface {{{1
nmap <silent> <unique> <Leader>be :BufExplorer<CR>
" Create commands {{{1
command BufExplorer :call StartBufExplorer(has ("gui") ? "drop" : "hide edit")
" Set {{{1
function s:Set(var, default)
if !exists(a:var)
if type(a:default)
exec "let" a:var "=" string(a:default)
else
exec "let" a:var "=" a:default
endif
return 1
endif
return 0
endfunction
" Default values {{{1
call s:Set("g:bufExplorerDefaultHelp", 1) " Show default help?
call s:Set("g:bufExplorerDetailedHelp", 0) " Show detailed help?
call s:Set("g:bufExplorerFindActive", 1) " When selecting an active buffer, take you to the window where it is active?
call s:Set("g:bufExplorerReverseSort", 0) " sort reverse?
call s:Set("g:bufExplorerShowDirectories", 1) " (Dir's are added by commands like ':e .')
call s:Set("g:bufExplorerShowRelativePath", 0) " Show listings with relative or absolute paths?
call s:Set("g:bufExplorerShowUnlisted", 0) " Show unlisted buffers?
call s:Set("g:bufExplorerSortBy", "mru") " Sorting methods are in s:sort_by:
call s:Set("g:bufExplorerSplitOutPathName", 1) " Split out path and file name?
" Global variables {{{1
let s:MRUList = []
let s:running = 0
let s:sort_by = ["number", "name", "fullpath", "mru", "extension"]
let s:tabSpace = []
let s:types = {"fullname": ':p', "path": ':p:h', "relativename": ':~:.', "relativepath": ':~:.:h', "shortname": ':t'}
let s:originBuffer = 0
" Setup the autocommands that handle the MRUList and other stuff. {{{1
autocmd VimEnter * call s:Setup()
" Setup {{{1
function s:Setup()
" Build initial MRUList.
let s:MRUList = range(1, bufnr('$'))
let s:tabSpace = []
" Now that the MRUList is created, add the other autocmds.
autocmd BufEnter,BufNew * call s:ActivateBuffer()
autocmd BufWipeOut * call s:DeactivateBuffer(1)
autocmd BufDelete * call s:DeactivateBuffer(0)
autocmd BufWinEnter \[BufExplorer\] call s:Initialize()
autocmd BufWinLeave \[BufExplorer\] call s:Cleanup()
endfunction
" ActivateBuffer {{{1
function s:ActivateBuffer()
let b = bufnr("%")
let l = get(s:tabSpace, tabpagenr(), [])
if empty(l) || index(l, b) == -1
call add(l, b)
let s:tabSpace[tabpagenr()] = l
endif
call s:MRUPush(b)
endfunction
" DeactivateBuffer {{{1
function s:DeactivateBuffer(remove)
"echom "afile:" expand("<afile>")
"echom "bufnr, afile:" bufnr(expand("<afile>"))
"echom "buffers:" string(tabpagebuflist())
"echom "MRU before:" string(s:MRUList)
if a:remove
call s:MRUPop(bufnr(expand("<afile>")))
end
"echom "MRU after:" string(s:MRUList)
endfunction
" MRUPop {{{1
function s:MRUPop(buf)
call filter(s:MRUList, 'v:val != '.a:buf)
endfunction
" MRUPush {{{1
function s:MRUPush(buf)
" Skip temporary buffer with buftype set.
" Don't add the BufExplorer window to the list.
if !empty(getbufvar(a:buf, "&buftype")) ||
\ !buflisted(a:buf) || empty(bufname(a:buf)) ||
\ fnamemodify(bufname(a:buf), ":t") == "[BufExplorer]"
return
end
call s:MRUPop(a:buf)
call insert(s:MRUList,a:buf)
endfunction
" Initialize {{{1
function s:Initialize()
let s:_insertmode = &insertmode
set noinsertmode
let s:_showcmd = &showcmd
set noshowcmd
let s:_cpo = &cpo
set cpo&vim
let s:_report = &report
let &report = 10000
let s:_list = &list
set nolist
setlocal nonumber
setlocal foldcolumn=0
setlocal nofoldenable
setlocal cursorline
setlocal nospell
set nobuflisted
let s:running = 1
endfunction
" Cleanup {{{1
function s:Cleanup()
let &insertmode = s:_insertmode
let &showcmd = s:_showcmd
let &cpo = s:_cpo
let &report = s:_report
let &list = s:_list
let s:running = 0
delmarks!
endfunction
" StartBufExplorer {{{1
function StartBufExplorer(open)
let name = '[BufExplorer]'
if !has("win32")
" On non-Windows boxes, escape the name so that is shows up correctly.
let name = escape(name, "[]")
endif
" Make sure there is only one explorer open at a time.
if s:running == 1
" Go to the open buffer.
if has("gui")
exec "drop" name
endif
return
endif
let s:originBuffer = bufnr("%")
silent let s:raw_buffer_listing = s:GetBufferInfo()
let copy = copy(s:raw_buffer_listing)
if (g:bufExplorerShowUnlisted == 0)
call filter(copy, 'v:val.attributes !~ "u"')
endif
if (!empty(copy))
call filter(copy, 'v:val.shortname !~ "\\\[No Name\\\]"')
endif
if len(copy) <= 1
echo "\r"
call s:Warn("Sorry, there are no more buffers to explore")
return
endif
if !exists("b:displayMode") || b:displayMode != "winmanager"
" Do not use keepalt when opening bufexplorer to allow the buffer that we
" are leaving to become the new alternate buffer
exec "silent keepjumps ".a:open." ".name
endif
call s:DisplayBufferList()
endfunction
" DisplayBufferList {{{1
function s:DisplayBufferList()
setlocal bufhidden=delete
setlocal buftype=nofile
setlocal modifiable
setlocal noswapfile
setlocal nowrap
call s:SetupSyntax()
call s:MapKeys()
call setline(1, s:CreateHelp())
call s:BuildBufferList()
call cursor(s:firstBufferLine, 1)
if !g:bufExplorerResize
normal! zz
endif
setlocal nomodifiable
endfunction
" MapKeys {{{1
function s:MapKeys()
if exists("b:displayMode") && b:displayMode == "winmanager"
nnoremap <buffer> <silent> <tab> :call <SID>SelectBuffer()<cr>
endif
nnoremap <buffer> <silent> <F1> :call <SID>ToggleHelp()<cr>
nnoremap <buffer> <silent> <2-leftmouse> :call <SID>SelectBuffer()<cr>
nnoremap <buffer> <silent> <cr> :call <SID>SelectBuffer()<cr>
nnoremap <buffer> <silent> t :call <SID>SelectBuffer("tab")<cr>
nnoremap <buffer> <silent> <s-cr> :call <SID>SelectBuffer("tab")<cr>
nnoremap <buffer> <silent> d :call <SID>RemoveBuffer("wipe")<cr>
nnoremap <buffer> <silent> D :call <SID>RemoveBuffer("delete")<cr>
nnoremap <buffer> <silent> m :call <SID>MRUListShow()<cr>
nnoremap <buffer> <silent> p :call <SID>ToggleSplitOutPathName()<cr>
nnoremap <buffer> <silent> q :call <SID>Close()<cr>
nnoremap <buffer> <silent> r :call <SID>SortReverse()<cr>
nnoremap <buffer> <silent> R :call <SID>ToggleShowRelativePath()<cr>
nnoremap <buffer> <silent> s :call <SID>SortSelect()<cr>
nnoremap <buffer> <silent> u :call <SID>ToggleShowUnlisted()<cr>
nnoremap <buffer> <silent> f :call <SID>ToggleFindActive()<cr>
for k in ["G", "n", "N", "L", "M", "H"]
exec "nnoremap <buffer> <silent>" k ":keepjumps normal!" k."<cr>"
endfor
endfunction
" SetupSyntax {{{1
function s:SetupSyntax()
if has("syntax")
syn match bufExplorerHelp "^\".*" contains=bufExplorerSortBy,bufExplorerMapping,bufExplorerTitle,bufExplorerSortType,bufExplorerToggleSplit,bufExplorerToggleOpen
syn match bufExplorerOpenIn "Open in \w\+ window" contained
syn match bufExplorerSplit "\w\+ split" contained
syn match bufExplorerSortBy "Sorted by .*" contained contains=bufExplorerOpenIn,bufExplorerSplit
syn match bufExplorerMapping "\" \zs.\+\ze :" contained
syn match bufExplorerTitle "Buffer Explorer.*" contained
syn match bufExplorerSortType "'\w\{-}'" contained
syn match bufExplorerBufNbr /^\s*\d\+/
syn match bufExplorerToggleSplit "toggle split type" contained
syn match bufExplorerToggleOpen "toggle open mode" contained
syn match bufExplorerModBuf /^\s*\d\+.\{4}+.*/
syn match bufExplorerLockedBuf /^\s*\d\+.\{3}[\-=].*/
syn match bufExplorerHidBuf /^\s*\d\+.\{2}h.*/
syn match bufExplorerActBuf /^\s*\d\+.\{2}a.*/
syn match bufExplorerCurBuf /^\s*\d\+.%.*/
syn match bufExplorerAltBuf /^\s*\d\+.#.*/
syn match bufExplorerUnlBuf /^\s*\d\+u.*/
hi def link bufExplorerBufNbr Number
hi def link bufExplorerMapping NonText
hi def link bufExplorerHelp Special
hi def link bufExplorerOpenIn Identifier
hi def link bufExplorerSortBy String
hi def link bufExplorerSplit NonText
hi def link bufExplorerTitle NonText
hi def link bufExplorerSortType bufExplorerSortBy
hi def link bufExplorerToggleSplit bufExplorerSplit
hi def link bufExplorerToggleOpen bufExplorerOpenIn
hi def link bufExplorerActBuf Identifier
hi def link bufExplorerAltBuf String
hi def link bufExplorerCurBuf Type
hi def link bufExplorerHidBuf Constant
hi def link bufExplorerLockedBuf Special
hi def link bufExplorerModBuf Exception
hi def link bufExplorerUnlBuf Comment
endif
endfunction
" ToggleHelp {{{1
function s:ToggleHelp()
let g:bufExplorerDetailedHelp = !g:bufExplorerDetailedHelp
setlocal modifiable
" Save position
normal! ma
" Remove old header
if (s:firstBufferLine > 1)
exec "keepjumps 1,".(s:firstBufferLine - 1) "d _"
endif
call append(0, s:CreateHelp())
silent! normal! g`a
delmarks a
setlocal nomodifiable
if exists("b:displayMode") && b:displayMode == "winmanager"
call WinManagerForceReSize("BufExplorer")
end
endfunction
" GetHelpStatus {{{1
function s:GetHelpStatus()
let ret = '" Sorted by '.((g:bufExplorerReverseSort == 1) ? "reverse " : "").g:bufExplorerSortBy
let ret .= ' | '.((g:bufExplorerFindActive == 0) ? "Don't " : "")."Locate buffer"
let ret .= ((g:bufExplorerShowUnlisted == 0) ? "" : " | Show unlisted")
let ret .= ' | '.((g:bufExplorerShowRelativePath == 0) ? "Absolute" : "Relative")
let ret .= ' '.((g:bufExplorerSplitOutPathName == 0) ? "Full" : "Split")." path"
return ret
endfunction
" CreateHelp {{{1
function s:CreateHelp()
if g:bufExplorerDefaultHelp == 0 && g:bufExplorerDetailedHelp == 0
let s:firstBufferLine = 1
return []
endif
let header = []
if g:bufExplorerDetailedHelp == 1
call add(header, '" Buffer Explorer ('.g:bufexplorer_version.')')
call add(header, '" --------------------------')
call add(header, '" <F1> : toggle this help')
call add(header, '" <enter> or Mouse-Double-Click : open buffer under cursor')
call add(header, '" <shift-enter> or t : open buffer in another tab')
call add(header, '" d : wipe buffer')
call add(header, '" D : delete buffer')
call add(header, '" p : toggle spliting of file and path name')
call add(header, '" q : quit')
call add(header, '" r : reverse sort')
call add(header, '" R : toggle showing relative or full paths')
call add(header, '" u : toggle showing unlisted buffers')
call add(header, '" s : select sort field '.string(s:sort_by).'')
call add(header, '" f : toggle find active buffer')
else
call add(header, '" Press <F1> for Help')
endif
call add(header, s:GetHelpStatus())
call add(header, '"=')
let s:firstBufferLine = len(header) + 1
return header
endfunction
" GetBufferInfo {{{1
function s:GetBufferInfo()
redir => bufoutput
buffers!
redir END
let [all, allwidths, listedwidths] = [[], {}, {}]
for n in keys(s:types)
let allwidths[n] = []
let listedwidths[n] = []
endfor
for buf in split(bufoutput, '\n')
let bits = split(buf, '"')
let b = {"attributes": bits[0], "line": substitute(bits[2], '\s*', '', '')}
for [key, val] in items(s:types)
let b[key] = fnamemodify(bits[1], val)
endfor
if getftype(b.fullname) == "dir" && g:bufExplorerShowDirectories == 1
let b.shortname = "<DIRECTORY>"
end
call add(all, b)
for n in keys(s:types)
call add(allwidths[n], len(b[n]))
if b.attributes !~ "u"
call add(listedwidths[n], len(b[n]))
endif
endfor
endfor
let [s:allpads, s:listedpads] = [{}, {}]
for n in keys(s:types)
let s:allpads[n] = repeat(' ', max(allwidths[n]))
let s:listedpads[n] = repeat(' ', max(listedwidths[n]))
endfor
return all
endfunction
" BuildBufferList {{{1
function s:BuildBufferList()
let lines = []
" Loop through every buffer.
for buf in s:raw_buffer_listing
if (!g:bufExplorerShowUnlisted && buf.attributes =~ "u")
" skip unlisted buffers if we are not to show them
continue
endif
let line = buf.attributes." "
if g:bufExplorerSplitOutPathName
let type = (g:bufExplorerShowRelativePath) ? "relativepath" : "path"
let path = buf[type]
let pad = (g:bufExplorerShowUnlisted) ? s:allpads.shortname : s:listedpads.shortname
let line .= buf.shortname." ".strpart(pad.path, len(buf.shortname))
else
let type = (g:bufExplorerShowRelativePath) ? "relativename" : "fullname"
let path = buf[type]
let line .= path
endif
let pads = (g:bufExplorerShowUnlisted) ? s:allpads : s:listedpads
if !empty(pads[type])
let line .= strpart(pads[type], len(path))." "
endif
let line .= buf.line
call add(lines, line)
endfor
call setline(s:firstBufferLine, lines)
call s:SortListing()
endfunction
" SelectBuffer {{{1
function s:SelectBuffer(...)
" Sometimes messages are not cleared when we get here so it looks like an
" error has occurred when it really has not.
echo ""
" Are we on a line with a file name?
if line('.') < s:firstBufferLine
exec "normal! \<cr>"
return
endif
let _bufNbr = str2nr(getline('.'))
if exists("b:displayMode") && b:displayMode == "winmanager"
let bufname = expand("#"._bufNbr.":p")
call WinManagerFileEdit(bufname, 0)
return
end
if bufexists(_bufNbr)
if bufnr("#") == _bufNbr
return s:Close()
endif
if (a:0 == 1) && (a:1 == "tab")
" Restore [BufExplorer] buffer.
exec "keepjumps silent buffer!".s:originBuffer
let tabNbr = s:GetTabNbr(_bufNbr)
if tabNbr == 0
" _bufNbr is not opened in any tabs
exec "999tab split +buffer" . _bufNbr
else
" _bufNbr is already opened in tab(s)
exec tabNbr . "tabnext"
" Focus window.
exec s:GetWinNbr(tabNbr, _bufNbr) . "wincmd w"
endif
else
" If the buf is active, then go to the tab where it is opened.
if bufloaded(_bufNbr) && g:bufExplorerFindActive
call s:Close()
let bufname = expand("#"._bufNbr.":p")
exec bufname ? "drop ".escape(bufname, " ") : "buffer "._bufNbr
endif
" Switch to the buffer.
exec "keepalt keepjumps silent b!" _bufNbr
endif
" Make the buffer 'listed' again.
call setbufvar(_bufNbr, "&buflisted", "1")
else
call s:Error("Sorry, that buffer no longer exists, please select another")
call s:DeleteBuffer(_bufNbr, "wipe")
endif
endfunction
" RemoveBuffer {{{1
function s:RemoveBuffer(mode)
" Are we on a line with a file name?
if line('.') < s:firstBufferLine
return
endif
" Do not allow this buffer to be deleted if it is the last one.
if len(s:MRUList) == 1
call s:Error("Sorry, you are not allowed to delete the last buffer")
return
endif
" These commands are to temporarily suspend the activity of winmanager.
if exists("b:displayMode") && b:displayMode == "winmanager"
call WinManagerSuspendAUs()
end
let _bufNbr = str2nr(getline('.'))
if getbufvar(_bufNbr, '&modified') == 1
call s:Error("Sorry, no write since last change for buffer "._bufNbr.", unable to delete")
return
else
" Okay, everything is good, delete or wipe the buffer.
call s:DeleteBuffer(_bufNbr, a:mode)
endif
" Reactivate winmanager autocommand activity.
if exists("b:displayMode") && b:displayMode == "winmanager"
call WinManagerForceReSize("BufExplorer")
call WinManagerResumeAUs()
end
endfunction
" DeleteBuffer {{{1
function s:DeleteBuffer(buf, mode)
" This routine assumes that the buffer to be removed is on the current line.
try
if a:mode == "wipe"
exe "silent bw" a:buf
else
exe "silent bd" a:buf
end
setlocal modifiable
normal! "_dd
setlocal nomodifiable
" Delete the buffer from the raw buffer list.
call filter(s:raw_buffer_listing, 'v:val.attributes !~ " '.a:buf.' "')
catch
call s:Error(v:exception)
endtry
endfunction
" Close {{{1
function s:Close()
" Get only the listed buffers.
let listed = filter(copy(s:MRUList), "buflisted(v:val)")
for b in reverse(listed[0:1])
exec "keepjumps silent b ".b
endfor
endfunction
" ToggleSplitOutPathName {{{1
function s:ToggleSplitOutPathName()
let g:bufExplorerSplitOutPathName = !g:bufExplorerSplitOutPathName
call s:RebuildBufferList()
call s:UpdateHelpStatus()
endfunction
" ToggleShowRelativePath {{{1
function s:ToggleShowRelativePath()
let g:bufExplorerShowRelativePath = !g:bufExplorerShowRelativePath
call s:RebuildBufferList()
call s:UpdateHelpStatus()
endfunction
" ToggleShowUnlisted {{{1
function s:ToggleShowUnlisted()
let g:bufExplorerShowUnlisted = !g:bufExplorerShowUnlisted
let num_bufs = s:RebuildBufferList(g:bufExplorerShowUnlisted == 0)
call s:UpdateHelpStatus()
endfunction
" ToggleFindActive {{{1
function s:ToggleFindActive()
let g:bufExplorerFindActive = !g:bufExplorerFindActive
call s:UpdateHelpStatus()
endfunction
" RebuildBufferList {{{1
function s:RebuildBufferList(...)
setlocal modifiable
let curPos = getpos('.')
if a:0
" Clear the list first.
exec "keepjumps ".s:firstBufferLine.',$d "_'
endif
let num_bufs = s:BuildBufferList()
call setpos('.', curPos)
setlocal nomodifiable
return num_bufs
endfunction
" UpdateHelpStatus {{{1
function s:UpdateHelpStatus()
setlocal modifiable
let text = s:GetHelpStatus()
call setline(s:firstBufferLine - 2, text)
setlocal nomodifiable
endfunction
" MRUCmp {{{1
function s:MRUCmp(line1, line2)
return index(s:MRUList, str2nr(a:line1)) - index(s:MRUList, str2nr(a:line2))
endfunction
" SortReverse {{{1
function s:SortReverse()
let g:bufExplorerReverseSort = !g:bufExplorerReverseSort
call s:ReSortListing()
endfunction
" SortSelect {{{1
function s:SortSelect()
let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy)+1, s:sort_by[0])
call s:ReSortListing()
endfunction
" ReSortListing {{{1
function s:ReSortListing()
setlocal modifiable
let curPos = getpos('.')
call s:SortListing()
call s:UpdateHelpStatus()
call setpos('.', curPos)
setlocal nomodifiable
endfunction
" SortListing {{{1
function s:SortListing()
let sort = s:firstBufferLine.",$sort".((g:bufExplorerReverseSort == 1) ? "!": "")
if g:bufExplorerSortBy == "number"
" Easiest case.
exec sort 'n'
elseif g:bufExplorerSortBy == "name"
if g:bufExplorerSplitOutPathName
exec sort 'ir /\d.\{7}\zs\f\+\ze/'
else
exec sort 'ir /\zs[^\/\\]\+\ze\s*line/'
endif
elseif g:bufExplorerSortBy == "fullpath"
if g:bufExplorerSplitOutPathName
" Sort twice - first on the file name then on the path.
exec sort 'ir /\d.\{7}\zs\f\+\ze/'
endif
exec sort 'ir /\zs\f\+\ze\s\+line/'
elseif g:bufExplorerSortBy == "extension"
exec sort 'ir /\.\zs\w\+\ze\s/'
elseif g:bufExplorerSortBy == "mru"
let l = getline(s:firstBufferLine, "$")
call sort(l, "<SID>MRUCmp")
if g:bufExplorerReverseSort
call reverse(l)
endif
call setline(s:firstBufferLine, l)
endif
endfunction
" MRUListShow {{{1
function s:MRUListShow()
echomsg "MRUList=".string(s:MRUList)
endfunction
" Error {{{1
function s:Error(msg)
echohl ErrorMsg | echo a:msg | echohl none
endfunction
" Warn {{{1
function s:Warn(msg)
echohl WarningMsg | echo a:msg | echohl none
endfunction
" GetTabNbr {{{1
function s:GetTabNbr(bufNbr)
" Searching buffer bufno, in tabs.
for i in range(tabpagenr("$"))
if index(tabpagebuflist(i + 1), a:bufNbr) != -1
return i + 1
endif
endfor
return 0
endfunction
" GetWinNbr" {{{1
function s:GetWinNbr(tabNbr, bufNbr)
" window number in tabpage.
return index(tabpagebuflist(a:tabNbr), a:bufNbr) + 1
endfunction
" Winmanager Integration {{{1
let g:BufExplorer_title = "\[Buf\ List\]"
call s:Set("g:bufExplorerResize", 1)
call s:Set("g:bufExplorerMaxHeight", 25) " Handles dynamic resizing of the window.
" Function to start display. Set the mode to 'winmanager' for this buffer.
" This is to figure out how this plugin was called. In a standalone fashion
" or by winmanager.
function BufExplorer_Start()
let b:displayMode = "winmanager"
call StartBufExplorer("e")
endfunction
" Returns whether the display is okay or not.
function BufExplorer_IsValid()
return 0
endfunction
" Handles dynamic refreshing of the window.
function BufExplorer_Refresh()
let b:displayMode = "winmanager"
call StartBufExplorer("e")
endfunction
function BufExplorer_ReSize()
if !g:bufExplorerResize
return
end
let nlines = min([line("$"), g:bufExplorerMaxHeight])
exe nlines." wincmd _"
" The following lines restore the layout so that the last file line is also
" the last window line. Sometimes, when a line is deleted, although the
" window size is exactly equal to the number of lines in the file, some of
" the lines are pushed up and we see some lagging '~'s.
let pres = getpos(".")
exe $
let _scr = &scrolloff
let &scrolloff = 0
normal! z-
let &scrolloff = _scr
call setpos(".", pres)
endfunction
"}}}1
" vim:ft=vim foldmethod=marker sw=2
|
00000svn-vim-cfg
|
trunk/vimfiles/plugin.Bak/bufexplorer.vim
|
Vim Script
|
gpl3
| 23,022
|
""Refer to link""http://vim.wikia.com/index.php?title=Highlight_multiple_words&diff=23776&oldid=prev
" Plugin to highlight multiple words in different colors.
" Version 2008-11-19 from http://vim.wikia.com/wiki/VimTip1572
" File highlights.csv (in same directory as script) defines the highlights.
"
" Type '\m' to toggle mapping of keypad on/off (assuming \ leader).
" Type '\f' to find the next match; '\F' to find backwards.
" Can also type '\n' or '\N' for search; then n or N will find next.
" On the numeric keypad, press:
" 1 to highlight visually selected text or current word
" using highlight group hl1 (defined below)
" 2 for highlight hl2, 3 for highlight hl3, etc
" (can press 1 to 9 on keypad for highlights hl1 to hl9)
" 0 to remove highlight from current word
" - to remove all highlights in current window
" + to restore highlights cleared with '-' in current window
" * to restore highlights (possibly from another window)
" Can press 1 or 2 on main keyboard before keypad 1..9 for more highlights.
" Commands:
" ':Highlight' list all highlights.
" ':Highlight [n [pattern]]' set highlight.
" ':Hsample' display all highlights in a scratch buffer.
" ':Hclear [hlnum|pattern|*]' clear highlights.
" ':Hsave x', ':Hrestore x' save/restore highlights (x any name).
" Saving current highlights requires '!' in 'viminfo' option.
if v:version < 702 || exists('loaded_highlightmultiple') || &cp
finish
endif
let loaded_highlightmultiple = 1
" On first call, read file highlights.csv in same directory as script.
" For example, line "5,white,blue,black,green" executes:
" highlight hl5 ctermfg=white ctermbg=blue guifg=black guibg=green
let s:data_file = expand('<sfile>:p:r').'.csv'
let s:loaded_data = 0
function! LoadHighlights()
if !s:loaded_data
if filereadable(s:data_file)
let names = ['hl', 'ctermfg=', 'ctermbg=', 'guifg=', 'guibg=']
for line in readfile(s:data_file)
let fields = split(line, ',', 1)
if len(fields) == 5 && fields[0] =~ '^\d\+$'
let cmd = range(5)
call map(cmd, 'names[v:val].fields[v:val]')
call filter(cmd, 'v:val!~''=$''')
execute 'silent highlight '.join(cmd)
endif
endfor
let s:loaded_data = 1
endif
if !s:loaded_data
echo 'Error: Could not read highlight data from '.s:data_file
endif
endif
endfunction
" Return last visually selected text or '\<cword\>'.
" what = 1 (selection), or 2 (cword), or 0 (guess if 1 or 2 is wanted).
function! s:Pattern(what)
if a:what == 2 || (a:what == 0 && histget(':', -1) =~# '^H')
let result = expand("<cword>")
if !empty(result)
let result = '\<'.result.'\>'
endif
else
let old_reg = getreg('"')
let old_regtype = getregtype('"')
normal! gvy
let result = substitute(escape(@@, '\.*$^~['), '\_s\+', '\\_s\\+', 'g')
normal! gV
call setreg('"', old_reg, old_regtype)
endif
return result
endfunction
" Remove any highlighting for hlnum then highlight pattern (if not empty).
" If pat is numeric, use current word or visual selection and
" increase hlnum by count*10 (if count [1..9] is given).
function! s:DoHighlight(hlnum, pat, decade)
call LoadHighlights()
let hltotal = a:hlnum
if 0 < a:decade && a:decade < 10
let hltotal += a:decade * 10
endif
if type(a:pat) == type(0)
let pattern = s:Pattern(a:pat)
else
let pattern = a:pat
endif
let id = hltotal + 100
silent! call matchdelete(id)
if !empty(pattern)
try
call matchadd('hl'.hltotal, pattern, -1, id)
catch /E28:/
echo 'Highlight hl'.hltotal.' is not defined'
endtry
endif
endfunction
" Remove all matches for pattern.
function! s:UndoHighlight(pat)
if type(a:pat) == type(0)
let pattern = s:Pattern(a:pat)
else
let pattern = a:pat
endif
for m in getmatches()
if m.pattern ==# pattern
call matchdelete(m.id)
endif
endfor
endfunction
" Return pattern to search for next match, and do search.
function! s:Search(backward)
let patterns = []
for m in getmatches()
call add(patterns, m.pattern)
endfor
if empty(patterns)
let pat = ''
else
let pat = join(patterns, '\|')
call search(pat, a:backward ? 'b' : '')
endif
return pat
endfunction
" Enable or disable mappings and any current matches.
function! s:MatchToggle()
if exists('g:match_maps') && g:match_maps
let g:match_maps = 0
for i in range(0, 9)
execute 'unmap <k'.i.'>'
endfor
nunmap <kMinus>
nunmap <kPlus>
nunmap <kMultiply>
nunmap <Leader>f
nunmap <Leader>F
nunmap <Leader>n
nunmap <Leader>N
else
let g:match_maps = 1
for i in range(1, 9)
execute 'vnoremap <silent> <k'.i.'> :<C-U>call <SID>DoHighlight('.i.', 1, v:count)<CR>'
execute 'nnoremap <silent> <k'.i.'> :<C-U>call <SID>DoHighlight('.i.', 2, v:count)<CR>'
endfor
vnoremap <silent> <k0> :<C-U>call <SID>UndoHighlight(1)<CR>
nnoremap <silent> <k0> :<C-U>call <SID>UndoHighlight(2)<CR>
nnoremap <silent> <kMinus> :call <SID>WindowMatches(0)<CR>
nnoremap <silent> <kPlus> :call <SID>WindowMatches(1)<CR>
nnoremap <silent> <kMultiply> :call <SID>WindowMatches(2)<CR>
nnoremap <silent> <Leader>f :call <SID>Search(0)<CR>
nnoremap <silent> <Leader>F :call <SID>Search(1)<CR>
nnoremap <silent> <Leader>n :let @/=<SID>Search(0)<CR>
nnoremap <silent> <Leader>N :let @/=<SID>Search(1)<CR>
endif
call s:WindowMatches(g:match_maps)
echo 'Mappings for matching:' g:match_maps ? 'ON' : 'off'
endfunction
nnoremap <silent> <Leader>m :call <SID>MatchToggle()<CR>
" Remove and save current matches, or restore them.
function! s:WindowMatches(action)
call LoadHighlights()
if a:action == 1
if exists('w:last_matches')
call setmatches(w:last_matches)
endif
elseif a:action == 2
if exists('g:last_matches')
call setmatches(g:last_matches)
else
call s:Hrestore('')
endif
else
let m = getmatches()
if !empty(m)
let w:last_matches = m
let g:last_matches = m
call s:Hsave('')
call clearmatches()
endif
endif
endfunction
" Return name of global variable to save value ('' if invalid).
function! s:NameForSave(name)
if a:name =~# '^\w*$'
return 'HI_SAVE_'.toupper(a:name)
endif
echo 'Error: Invalid name "'.a:name.'"'
return ''
endfunction
" Return custom completion string (match patterns).
function! s:MatchPatterns(A, L, P)
return join(sort(map(getmatches(), 'v:val.pattern')), "\n")
endfunction
" Return custom completion string (saved highlight names).
function! s:SavedNames(A, L, P)
let l = filter(keys(g:), 'v:val =~# ''^HI_SAVE_\w''')
return tolower(join(sort(map(l, 'strpart(v:val, 8)')), "\n"))
endfunction
" Save current highlighting in a global variable.
function! s:Hsave(name)
let sname = s:NameForSave(a:name)
if !empty(sname)
let l = getmatches()
call map(l, 'join([v:val.group, v:val.pattern, v:val.priority, v:val.id], "\t")')
let g:{sname} = join(l, "\n")
endif
endfunction
command! -nargs=? -complete=custom,s:SavedNames Hsave call <SID>Hsave('<args>')
" Restore current highlighting from a global variable.
function! s:Hrestore(name)
call LoadHighlights()
let sname = s:NameForSave(a:name)
if !empty(sname)
if exists('g:{sname}')
let matches = []
for l in split(g:{sname}, "\n")
let f = split(l, "\t", 1)
call add(matches, {'group':f[0], 'pattern':f[1], 'priority':f[2], 'id':f[3]})
endfor
call setmatches(matches)
else
echo 'No such global variable: '.sname
endif
endif
endfunction
command! -nargs=? -complete=custom,s:SavedNames Hrestore call <SID>Hrestore('<args>')
" Clear a match, or clear all current matches. Example args:
" '14' = hl14, '*' = all, '' = visual selection or cword,
" 'pattern' = all matches for pattern
function! s:Hclear(pattern) range
if empty(a:pattern)
call s:UndoHighlight(0)
elseif a:pattern == '*'
call s:WindowMatches(0)
elseif a:pattern =~ '^[1-9][0-9]\?$'
call s:DoHighlight(str2nr(a:pattern), '', 0)
else
call s:UndoHighlight(a:pattern)
endif
endfunction
command! -nargs=* -complete=custom,s:MatchPatterns -range Hclear call <SID>Hclear('<args>')
" Create a scratch buffer with sample text, and apply all highlighting.
function! s:Hsample()
call LoadHighlights()
new
setlocal buftype=nofile bufhidden=hide noswapfile
let lines = []
let items = []
for hl in filter(range(1, 99), 'v:val % 10 > 0')
if hlexists('hl'.hl)
let sample = printf('Sample%2d', hl)
call s:DoHighlight(hl, sample, 0)
else
let sample = ' '
endif
call add(items, sample)
if len(items) >= 3
call insert(lines, substitute(join(items), '\s\+$', '', ''))
let items = []
endif
endfor
call append(0, filter(lines, 'len(v:val) > 0'))
$d
%s/\d3$/&\r/e
endfunction
command! Hsample call <SID>Hsample()
" Set a match, or display all current matches. Example args:
" '14' = set hl14 for visual selection or cword,
" '14 pattern' = set hl14 for pattern, '' = display all
function! s:Highlight(args) range
if empty(a:args)
echo 'Highlight groups and patterns:'
for m in getmatches()
echo m.group m.pattern
endfor
return
endif
let l = matchlist(a:args, '^\s*\([1-9][0-9]\?\)\%($\|\s\+\(.*\)\)')
if len(l) >= 3
let hlnum = str2nr(l[1])
let pattern = l[2]
if empty(pattern)
let pattern = s:Pattern(0)
endif
call s:DoHighlight(hlnum, pattern, 0)
return
endif
echo 'Error: First argument must be highlight number 1..99'
endfunction
command! -nargs=* -range Highlight call <SID>Highlight('<args>')
|
00000svn-vim-cfg
|
trunk/vimfiles/plugin.Bak/highlights.vim
|
Vim Script
|
gpl3
| 10,040
|
#!/bin/bash
#===============================================================================
# FILE: wrapper.sh
# USAGE: ./wrapper.sh scriptname [cmd-line-args]
# DESCRIPTION: Wraps the execution of a programm or script.
# Use with xterm: xterm -e wrapper.sh scriptname cmd-line-args
# This script is used by the Vim plugin bash-support.vim
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dr.-Ing. Fritz Mehner (fgm), mehner.fritz@fh-swf.de
# COMPANY: Fachhochschule Südwestfalen, Iserlohn
# CREATED: 23.11.2004 18:04:01 CET
# REVISION: $Id: wrapper.sh,v 1.5 2009/06/04 17:14:02 mehner Exp $
#===============================================================================
scriptname="${1}" # name of the script to execute
returncode=0 # default return code
if [ ${#} -ge 1 ] ; then
if [ -x "$scriptname" ] ; then # start an executable script?
"${@}"
else
awk -f "${@}" # start a script which is not executable
fi
returncode=$?
[ $returncode -ne 0 ] && printf "'${@}' returned ${returncode}\n"
else
printf "\n!! ${0} : no argument(s) !!\n"
fi
read -p "... press return key ... " dummy
exit $returncode
|
00000svn-vim-cfg
|
trunk/vimfiles/awk-support/scripts/wrapper.sh
|
Shell
|
gpl3
| 1,361
|