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

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

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

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

Добавлен: 28.03.2023

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

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

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

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 = 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.mtOut;

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

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

item.DateMove = DateTime.Now;

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

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

{

unitOfWork.MoveProductRepository.Insert(item);

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.ObFrom = App.store;

//item.ObTo = unitOfWork.KontragentRepository.GetByID(item.MoveTo);

FMoveProduct frm = new FMoveProduct(item, unitOfWork);

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

{

unitOfWork.MoveProductRepository.Update(item);

unitOfWork.Save();

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 CMoveProductReturn

{

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("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,MoveToText,MoveFromText";

flist = new EntityList();

Bitmap bmp = 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.mtReturn;

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

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

item.DateMove = DateTime.Now;

//item.ObFrom = App.store;

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

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

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

{

unitOfWork.MoveProductRepository.Insert(item);

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>();

if (CurrentItem == null) return;

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

//item.ObFrom = App.store;

//item.ObTo = unitOfWork.KontragentRepository.GetByID(item.MoveTo);

FMoveProduct frm = new FMoveProduct(item, unitOfWork);

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

{

unitOfWork.MoveProductRepository.Update(item);

unitOfWork.Save();

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.Trim().Contains(e.Text.Trim()));


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

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

}

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;

namespace InFocus.Views

{

public class CProduct

{

ModeForm mode;

UnitOfWork unitOfWork;

ObservableCollection<ProductView> listentity;

string sort;

EntityList flist;

public event EventHandler UpdateAll;

public event EventHandler SelectedProduct;

public object Returned;

internal bool ReadOnly=false;

public void AddAnotherControl()

{

ToolStripLabel lbl = new ToolStripLabel("Группа");

ToolStripComboBox cbo = new ToolStripComboBox("cbogroup");

List<ProductGroup> l = unitOfWork.ProductGroupRepository.Get(orderBy: a => a.OrderBy(aa => aa.Caption)).ToList();

foreach (ProductGroup item in l)

{

cbo.Items.Add(item);

}

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

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

}

public DataGridViewColumn[] GetGrid()

{

DataGridViewColumn[] arr = new DataGridViewColumn[5];

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 = "ProductGroupText";

col.HeaderText = "Группа";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.Width = 150;

arr[2] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "UnitText";

col.HeaderText = "Ед.изм.";

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;

col.Width = 100;

arr[3] = col;

col = new DataGridViewTextBoxColumn();

col.DataPropertyName = "Description";

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

col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

arr[4] = col;

return arr;

}

public void RefreshData(List<ProductView> lst_)

{

listentity = new ObservableCollection<ProductView>(lst_);

}

public void ButtonCrudOff()

{

flist.SetEnabledButton("bnew", false);

flist.SetEnabledButton("bedit", false);

flist.SetEnabledButton("bremove", false);

}

public void Build(UnitOfWork unitOfWork_,

List<ProductView> lst_,

string ka,

ModeForm mode_=ModeForm.mfList,

ProductView selected = null)

{

unitOfWork = unitOfWork_;

mode = mode_;

listentity = new ObservableCollection<ProductView>(lst_);

sort = "Caption,ProductGroupText";

flist = new EntityList();

if (ReadOnly) ButtonCrudOff();

Bitmap bmp = InFocus.Properties.Resources.product;

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

flist.Text =string.IsNullOrEmpty(ka)? "Продукты" : "Продукты, поставляемые: " + ka;

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

AddAnotherControl();

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

flist.SetCurrentItem<ProductView>(selected);

flist.Added += delegate

{

Product item = new Product();

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

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

{

unitOfWork.ProductRepository.Insert(item);

unitOfWork.Save();