Файл: Разработка информационной системы управления ценами, поставками и оборудованием розничного продовольственного магазина.pdf

ВУЗ: Не указан

Категория: Курсовая работа

Дисциплина: Не указана

Добавлен: 16.02.2024

Просмотров: 549

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

{

unitOfWork.EmployeeRepository.Insert(item);

unitOfWork.Save();

EmployeeView ev = new EmployeeView();

EmployeeView.Map(item, ev);

listentity.Add(ev);

flist.UpdateSource<EmployeeView>(ev, sort);

}

};

flist.Edited += EditItem;

flist.Removed += delegate

{

EmployeeView item = flist.GetCurrentItem<EmployeeView>();

if (item.Id == App.user.Id) return;

if (MessageBox.Show("Удалить текущую запись?","Внимание!!!",MessageBoxButtons.OKCancel)== DialogResult.OK)

{

unitOfWork.EmployeeRepository.Delete(item.Id);

unitOfWork.Save();

listentity.Remove(item);

flist.UpdateSource<EmployeeView>(null, sort);

}

};

flist.UpdateAll += delegate

{

UpdateAll(this, EventArgs.Empty);

flist.RefreshSource<EmployeeView>(listentity.ToBindingList());

};

flist.RemoveFiltered += delegate

{

flist.RefreshSource<EmployeeView>(listentity.ToBindingList());

ToolStripComboBox cbo = flist.ts.Items.Find("cbodepart", true).OfType<ToolStripComboBox>().Single();

cbo.SelectedIndex = -1;

};

flist.Filtered += Set_Filter;

if (mode_ == ModeForm.mfList)

{

flist.MdiParent = Application.OpenForms[0];

flist.Selected += EditItem;

flist.Show();

}

else

{

flist.Selected += SelectedItem;

flist.ShowDialog();

}

}

private void SelectedItem(object sender, EventArgs e)

{

Returned = flist.GetCurrentItem<EmployeeView>();

SelectedEmployee(this, EventArgs.Empty);

flist.Close();

}

private void EditItem(object sender, EventArgs e)

{

EmployeeView CurrentItem = flist.GetCurrentItem<EmployeeView>();

Employee item = unitOfWork.EmployeeRepository.GetByID(CurrentItem.Id);

FEmployee frm = new FEmployee(item, unitOfWork);

if (frm.ShowDialog() == DialogResult.OK)

{

unitOfWork.EmployeeRepository.Update(item);

unitOfWork.Save();

EmployeeView.Map(item, CurrentItem);

flist.UpdateSource<EmployeeView>(null, sort);

}

else

{

unitOfWork.UndoingChangesObjectContext(((IObjectContextAdapter)unitOfWork.context).ObjectContext);

}

}

private void Set_Filter(object sender, FilterEventArgs e)

{

int id;

var predicate = PredicateBuilder.False<EmployeeView>();

if (e.Text.Trim().Length > 0)

{

if (Int32.TryParse(e.Text, out id))

{

predicate = predicate.Or(t => t.Id == id);

}

predicate = predicate.Or(t => t.FullName != null && t.FullName.ToLower().Contains(e.Text));

predicate = predicate.Or(t => t.Description != null && t.Description.ToLower().Contains(e.Text));

}

ToolStripComboBox cbo = flist.ts.Items.Find("cbodepart", true).OfType<ToolStripComboBox>().Single();

if (cbo.SelectedIndex >= 0)

{

if (e.Text.Trim().Length > 0)

{

predicate = predicate.And(t => t.DepartmentFK == (cbo.SelectedItem as Kontragent).Id);

}

else

{

predicate = predicate.Or(t => t.DepartmentFK == (cbo.SelectedItem as Kontragent).Id);

}

}

var query = listentity.AsQueryable().Where(predicate);

flist.RefreshSource<EmployeeView>(new ObservableCollection<EmployeeView>(query).ToBindingList());

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using InFocus.DbStore;

using System.Windows.Forms;

using System.Collections.ObjectModel;

using System.ComponentModel;

using System.Data.Entity;

using System.Drawing;

namespace InFocus.Views

{

public class CKontragent

{

ModeForm mode;

UnitOfWork unitOfWork;

ObservableCollection<Kontragent> listentity;

string sort;

EntityList flist;

public event EventHandler UpdateAll;

public event EventHandler SelectedKontragent;

public object Returned;

public DataGridViewColumn[] GetGrid()

{

DataGridViewColumn[] arr = new DataGridViewColumn[3];

DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();


col.DataPropertyName = "Id";

col.HeaderText = "ИД";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;

arr[0] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Caption";

col.HeaderText = "Поставщик";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[1] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Description";

col.HeaderText = "Описание";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[2] = col;

return arr;

}

public void RefreshData(List<Kontragent> lst_)

{

listentity = new ObservableCollection<Kontragent>(lst_);

}

public void Build(UnitOfWork unitOfWork_,List<Kontragent> lst_, ModeForm mode_=ModeForm.mfList, Kontragent selected =null)

{

unitOfWork = unitOfWork_;

mode = mode_;

listentity = new ObservableCollection<Kontragent>(lst_);

sort = "Caption";

flist = new EntityList();

flist.Text = "Поставщики";

Bitmap bmp = InFocus.Properties.Resources.truck2;

flist.Icon = Icon.FromHandle(bmp.GetHicon());

flist.Build<Kontragent>(unitOfWork, listentity.ToBindingList(), GetGrid());

flist.UpdateSource<Kontragent>(null, sort);

flist.SetCurrentItem<Kontragent>(selected);

flist.Added += delegate

{

Kontragent item = new Kontragent();

FKontragent frm = new FKontragent(item, unitOfWork);

if (frm.ShowDialog()==DialogResult.OK)

{

unitOfWork.KontragentRepository.Insert(item);

unitOfWork.Save();

listentity.Add(item);

flist.UpdateSource<Kontragent>(item, sort);

}

};

flist.Edited += EditItem;

flist.Removed += delegate

{

Kontragent item = flist.GetCurrentItem<Kontragent>();

if (MessageBox.Show("Удалить текущую запись?","Внимание!!!",MessageBoxButtons.OKCancel)== DialogResult.OK)

{

unitOfWork.KontragentRepository.Delete(item);

var listdeletemove = unitOfWork.MoveProductRepository.Get(filter: a => a.MoveTypeFK == (int)enumMoveType.mtAdd && a.MoveFrom == item.Id);

unitOfWork.context.MoveProduct.RemoveRange(listdeletemove);

var listdeletemove2 = unitOfWork.MoveProductRepository.Get(filter: a => a.MoveTypeFK == (int)enumMoveType.mtReturn && a.MoveTo == item.Id);

unitOfWork.context.MoveProduct.RemoveRange(listdeletemove2);

unitOfWork.Save();

listentity.Remove(item);

flist.UpdateSource<Kontragent>(item, sort);

}

};

flist.UpdateAll += delegate

{

UpdateAll(this, EventArgs.Empty);

flist.RefreshSource<Kontragent>(listentity.ToBindingList());

};

flist.RemoveFiltered += delegate

{

flist.RefreshSource<Kontragent>(listentity.ToBindingList());

};

flist.Filtered += Set_Filter;

if (mode_==ModeForm.mfList)

{

flist.MdiParent = Application.OpenForms[0];

flist.Selected += EditItem;

flist.Show();

}

else

{

flist.Selected += SelectedItem;

flist.ShowDialog();

}

}

private void SelectedItem(object sender, EventArgs e)

{

Returned = flist.GetCurrentItem<Kontragent>();

SelectedKontragent(this,EventArgs.Empty);

flist.Close();

}

private void EditItem(object sender, EventArgs e)

{

Kontragent item = flist.GetCurrentItem<Kontragent>();

FKontragent frm = new FKontragent(item, unitOfWork);

if (frm.ShowDialog() == DialogResult.OK)

{

unitOfWork.KontragentRepository.Update(item);

unitOfWork.Save();

flist.UpdateSource<Kontragent>(item, sort);

}

}

private void Set_Filter(object sender, FilterEventArgs e)

{

int id;

var predicate = PredicateBuilder.False<Kontragent>();

if (Int32.TryParse(e.Text, out id))

{

predicate = predicate.Or(t => t.Id==id);

}

predicate = predicate.Or(t => t.Caption != null && t.Caption.ToLower().Contains(e.Text));

predicate = predicate.Or(t => t.Comment != null && t.Comment.ToLower().Contains(e.Text));

var query = listentity.AsQueryable().Where(predicate);


flist.RefreshSource<Kontragent>(new ObservableCollection<Kontragent>(query).ToBindingList());

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using InFocus.DbStore;

using System.Windows.Forms;

using System.Collections.ObjectModel;

using System.ComponentModel;

using System.Data.Entity;

using System.Data.Entity.Infrastructure;

using System.Drawing;

using Microsoft.Reporting.WinForms;

namespace InFocus.Views

{

public class CMoveProductAdd

{

ModeForm mode;

UnitOfWork unitOfWork;

ObservableCollection<MoveProductView> listentity;

string sort;

EntityList flist;

ReportViewer rpt;

public event EventHandler UpdateAll;

public event EventHandler SelectedMoveProduct;

public object Returned;

public void AddAnotherControl()

{

ToolStripButton btn = new ToolStripButton("btnprint");

btn.Text = "Отчет";

btn.Image = InFocus.Properties.Resources.rpt;

btn.Click += Btn_Click;

btn.Visible = true;

ToolStripButton btn2 = new ToolStripButton("btnprint");

btn2.Text = "Закрыть отчет";

btn2.Image = InFocus.Properties.Resources.close;

btn2.Click += Btn_CloseReport;

btn2.Visible = true;

flist.ts.Items.Insert(7, btn);

flist.ts.Items.Insert(8, btn2);

}

private void Btn_CloseReport(object sender, EventArgs e)

{

if (rpt == null) return;

rpt.SendToBack();

}

private void Btn_Click(object sender, EventArgs e)

{

if (rpt == null)

{

rpt = new ReportViewer();

rpt.LocalReport.ReportPath = "Report/Report4.rdlc";

flist.Controls.Add(rpt);

rpt.Dock = DockStyle.Fill;

rpt.Visible = true;

List<ReportParameter> ps = new List<ReportParameter>();

ReportParameter pTitle = new ReportParameter("pTitle", "Отчет по приходу продуктов на точки");

ReportParameter pFrom = new ReportParameter("pFrom", "Поставщик");

ReportParameter pTo = new ReportParameter("pTo", "Точка продажи");

ps.Add(pTitle); ps.Add(pFrom); ps.Add(pTo);

rpt.LocalReport.SetParameters(ps);

}

rpt.LocalReport.DataSources.Clear();

rpt.LocalReport.DataSources.Add(new ReportDataSource("ds", flist.GetSourses<MoveProductView>()));

rpt.RefreshReport();

rpt.BringToFront();

}

public DataGridViewColumn[] GetGrid()

{

DataGridViewColumn[] arr = new DataGridViewColumn[6];

DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Id";

col.HeaderText = "ИД";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;

arr[0] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "DateMove";

col.HeaderText = "Дата";

col.DefaultCellStyle.Format = "d";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.Width = 150;

arr[1] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "NumberDoc";

col.HeaderText = "№ докум.";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.Width = 100;

arr[2] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "MoveFromText";

col.HeaderText = "Поставщик";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[3] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "MoveToText";

col.HeaderText = "Точка продажи";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[4] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Cost";

col.HeaderText = "Сумма, руб";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.DefaultCellStyle.Format = "C2";

col.Width = 100;

arr[5] = col;

return arr;

}

public void RefreshData(List<MoveProductView> lst_)

{

listentity = new ObservableCollection<MoveProductView>(lst_);

}

public void Build(UnitOfWork unitOfWork_,

List<MoveProductView> lst_,


ModeForm mode_=ModeForm.mfList )

{

unitOfWork = unitOfWork_;

mode = mode_;

listentity = new ObservableCollection<MoveProductView>(lst_);

sort = "DateMove,MoveFromText,MoveToText";

flist = new EntityList();

Bitmap bmp = InFocus.Properties.Resources.transfer;

flist.Icon = Icon.FromHandle(bmp.GetHicon());

flist.Text = "Приход";

flist.Build<MoveProductView>(unitOfWork, listentity.ToBindingList(), GetGrid());

AddAnotherControl();

flist.UpdateSource<MoveProductView>(null, sort);

flist.Added += delegate

{

MoveProduct item = new MoveProduct();

item.MoveTypeFK = (int)enumMoveType.mtAdd;

item.MoveType = unitOfWork.MoveTypeRepository.GetByID((int)enumMoveType.mtAdd);

item.NumberDoc = (unitOfWork.MoveProductRepository.GetCount(filter: a => a.MoveTypeFK == (int)enumMoveType.mtAdd)+1).ToString();

item.DateMove = DateTime.Now;

//item.ObTo = App.store;

//item.MoveTo = App.store.Id;

FMoveProduct frm = new FMoveProduct(item, this.unitOfWork);

if (frm.ShowDialog()==DialogResult.OK)

{

unitOfWork.MoveProductRepository.Insert(item);

unitOfWork.Save();

foreach (var mpi in item.MoveProductItems)

{

mpi.NumPartFK = item.Id;

}

unitOfWork.Save();

MoveProductView ev = MoveProductView.Map(item);

listentity.Add(ev);

flist.UpdateSource<MoveProductView>(ev, sort);

}

};

flist.Edited += EditItem;

flist.Removed += delegate

{

MoveProductView item = flist.GetCurrentItem<MoveProductView>();

//if (item.Id == App.user.Id) return;

if (MessageBox.Show("Удалить текущую запись?","Внимание!!!",MessageBoxButtons.OKCancel)== DialogResult.OK)

{

unitOfWork.MoveProductRepository.Delete(item.Id);

unitOfWork.Save();

listentity.Remove(item);

flist.UpdateSource<MoveProductView>(null, sort);

}

};

flist.UpdateAll += delegate

{

UpdateAll(this, EventArgs.Empty);

flist.RefreshSource<MoveProductView>(listentity.ToBindingList());

};

flist.RemoveFiltered += delegate

{

flist.RefreshSource<MoveProductView>(listentity.ToBindingList());

};

flist.Filtered += Set_Filter;

if (mode_ == ModeForm.mfList)

{

flist.MdiParent = Application.OpenForms[0];

flist.Selected += EditItem;

flist.Show();

}

else

{

flist.Selected += SelectedItem;

flist.ShowDialog();

}

}

private void SelectedItem(object sender, EventArgs e)

{

Returned = flist.GetCurrentItem<MoveProductView>();

SelectedMoveProduct(this, EventArgs.Empty);

flist.Close();

}

private void EditItem(object sender, EventArgs e)

{

MoveProductView CurrentItem = flist.GetCurrentItem<MoveProductView>();

MoveProduct item = unitOfWork.MoveProductRepository.GetByID(CurrentItem.Id);

//item.ObTo = App.store;

//item.ObFrom = unitOfWork.KontragentRepository.GetByID(item.MoveFrom);

FMoveProduct frm = new FMoveProduct(item, unitOfWork);

if (frm.ShowDialog() == DialogResult.OK)

{

unitOfWork.MoveProductRepository.Update(item);

unitOfWork.Save();

foreach (var mpi in item.MoveProductItems)

{

mpi.NumPartFK = item.Id;

}

MoveProductView.Map(item, CurrentItem);

flist.UpdateSource<MoveProductView>(null, sort);

}

else

{

unitOfWork.UndoingChangesObjectContext(((IObjectContextAdapter)unitOfWork.context).ObjectContext);

}

}

private void Set_Filter(object sender, FilterEventArgs e)

{

int id;

DateTime ddate;

var predicate = PredicateBuilder.False<MoveProductView>();

if (e.Text.Trim().Length > 0)

{

if (Int32.TryParse(e.Text, out id))

{

predicate = predicate.Or(t => t.Id == id);

}

if (DateTime.TryParse(e.Text, out ddate))

{

predicate = predicate.Or(t => t.DateMove.Date.ToShortDateString() == ddate.Date.ToShortDateString());

}

predicate = predicate.Or(t => t.MoveFromText != null && t.MoveFromText.Contains(e.Text));


predicate = predicate.Or(t => t.MoveToText != null && t.MoveToText.Contains(e.Text));

predicate = predicate.Or(t => t.NumberDoc != null && t.NumberDoc.Contains(e.Text));

}

var query = listentity.AsQueryable().Where(predicate);

flist.RefreshSource<MoveProductView>(new ObservableCollection<MoveProductView>(query).ToBindingList());

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using InFocus.DbStore;

using System.Windows.Forms;

using System.Collections.ObjectModel;

using System.ComponentModel;

using System.Data.Entity;

using System.Data.Entity.Infrastructure;

using System.Drawing;

using Microsoft.Reporting.WinForms;

namespace InFocus.Views

{

public class CMoveProductOut

{

ReportViewer rpt;

ModeForm mode;

UnitOfWork unitOfWork;

ObservableCollection<MoveProductView> listentity;

string sort;

EntityList flist;

public event EventHandler UpdateAll;

public event EventHandler SelectedMoveProduct;

public object Returned;

public void AddAnotherControl()

{

ToolStripButton btn = new ToolStripButton("btnprint");

btn.Text = "Отчет";

btn.Image = InFocus.Properties.Resources.rpt;

btn.Click += Btn_Click;

btn.Visible = true;

ToolStripButton btn2 = new ToolStripButton("btnprint2");

btn2.Text = "Закрыть отчет";

btn2.Image = InFocus.Properties.Resources.close;

btn2.Click += Btn_CloseReport;

btn2.Visible = true;

flist.ts.Items.Insert(7, btn);

flist.ts.Items.Insert(8, btn2);

}

private void Btn_CloseReport(object sender, EventArgs e)

{

if (rpt == null) return;

rpt.SendToBack();

}

private void Btn_Click(object sender, EventArgs e)

{

if (rpt == null)

{

rpt = new ReportViewer();

rpt.LocalReport.ReportPath = "Report/Report4.rdlc";

flist.Controls.Add(rpt);

rpt.Dock = DockStyle.Fill;

rpt.Visible = true;

List<ReportParameter> ps = new List<ReportParameter>();

ReportParameter pTitle = new ReportParameter("pTitle", "Отчет по продажам товаров покупателям");

ReportParameter pFrom = new ReportParameter("pFrom", "Точка продажи");

ReportParameter pTo = new ReportParameter("pTo", "Покупатель");

ps.Add(pTitle); ps.Add(pFrom); ps.Add(pTo);

rpt.LocalReport.SetParameters(ps);

}

rpt.LocalReport.DataSources.Clear();

rpt.LocalReport.DataSources.Add(new ReportDataSource("ds", flist.GetSourses<MoveProductView>()));

rpt.RefreshReport();

rpt.BringToFront();

}

public DataGridViewColumn[] GetGrid()

{

DataGridViewColumn[] arr = new DataGridViewColumn[6];

DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Id";

col.HeaderText = "ИД";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;

arr[0] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "DateMove";

col.HeaderText = "Дата";

col.DefaultCellStyle.Format = "d";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.Width = 150;

arr[1] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "NumberDoc";

col.HeaderText = "№ докум.";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.Width = 100;

arr[2] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "MoveFromText";

col.HeaderText = "Точка продажи";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[3] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "MoveToText";

col.HeaderText = "Покупатель";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[4] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Cost";

col.HeaderText = "Сумма, руб";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.DefaultCellStyle.Format = "C2";

col.Width = 100;