public DocumentsList(CashRegister _CashRegister) { InitializeComponent(); CompasLogger.Add(String.Format("Start opening DocumentsList"), CompasLogger.Level.Info); cashRegister = _CashRegister; manager = new ContextManager(); bool allowed = Compas.Logic.Security.CurrentSecurityContext.Principal.OpperationAllowed("DocumentsList"); if (allowed == true) { CompasLogger.Add(String.Format("FillDocumentFilter"), CompasLogger.Level.Info); documentFilterUC1.Fill(); CompasLogger.Add(String.Format("FillUniversalFilter"), CompasLogger.Level.Info); universalFilter1.Fill(); documentsLogic = new DocumentsLogic(manager); CompasLogger.Add(String.Format("Fill"), CompasLogger.Level.Info); Fill(); } else { MessageBox.Show("Дія заборонена. Зверніться до адміністратора."); this.Close(); } CompasLogger.Add(String.Format("End opening DocumentsList"), CompasLogger.Level.Info); //this.DataGV.CellPainting += new // DataGridViewCellPaintingEventHandler(DataGV_CellPainting); }
public void Fill() { manager = new ContextManager(); CompasLogger.Add(String.Format("UniversalFilter FillFilters"), CompasLogger.Level.Info); FillFilters(); CompasLogger.Add(String.Format("UniversalFilter FillCurrencies"), CompasLogger.Level.Info); FillCurrencies(); CompasLogger.Add(String.Format("UniversalFilter FillWares"), CompasLogger.Level.Info); FillWares(); CompasLogger.Add(String.Format("UniversalFilter FillStates"), CompasLogger.Level.Info); FillStates(); CompasLogger.Add(String.Format("UniversalFilter End"), CompasLogger.Level.Info); }
/// <summary> /// Конструктор форми створення і редагування документу /// </summary> /// <param name="_mode">режим - new або edit</param> /// <param name="_id">ыдентифыкатор документу для режиму редагування</param> /// <param name="_CashRegister">підключений принтер чеків(якщо немає то null)</param> public DocumentData(string _mode, int?_id, CashRegister _CashRegister) { InitializeComponent(); cashRegister = _CashRegister; CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info); manager = new ContextManager(); mode = _mode; id = _id; DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; FillPayments(); documentDetailsNew = new List <WareDocumentDetail>(); documentDetailsOld = new List <WareDocumentDetail>(); documentDetailsDeleted = new List <WareDocumentDetail>(); employeesDetailsView = new List <StaffEmployeeView>(); documentsLogic = new DocumentsLogic(manager); documentDetailsLogic = new DocumentDetailsLogic(manager); if (mode == "new") { //створюємо документ в памяті document = documentsLogic.CreateEmpty(); } if (mode == "edit") { //витягуємо документ в память document = documentsLogic.Get(Convert.ToInt32(id)); //витягуємо детальну інформацію по документу documentDetailsOld = documentDetailsLogic.GetAll(id); documentDetailsView = documentDetailsOld; FillEmployeeDetails(); } CompasLogger.Add(String.Format("p1"), CompasLogger.Level.Info); Fill(); CompasLogger.Add(String.Format("End opening doc form"), CompasLogger.Level.Info); }
/// <summary> /// Збереження даних документу /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveBt_Click(object sender, EventArgs e) { if (dxValidationProvider1.Validate() == true) { if (ContractorLUE.EditValue != null) { document.ContractorID = Convert.ToInt32(ContractorLUE.EditValue); } if (CurrencyLUE.EditValue != null) { document.CurrencyID = Convert.ToInt32(CurrencyLUE.EditValue); } if (DateDE.EditValue != null) { document.Date = Convert.ToDateTime(DateDE.EditValue); } document.Description = DescriptionTE.Text; document.Address = AddressTE.Text; document.Number = NumberTE.Text; if (DocumentTypeLUE.EditValue != null) { document.DocumentTypeID = Convert.ToInt32(DocumentTypeLUE.EditValue); } if (FromObjectLUE.EditValue != null) { document.FromStructureObjectID = Convert.ToInt32(FromObjectLUE.EditValue); } if (ToObjectLUE.EditValue != null) { document.ToStructureObjectD = Convert.ToInt32(ToObjectLUE.EditValue); } int enterpriseId = Convert.ToInt32(EnterprisesCB.SelectedValue); int?teamId = null; if (TeamsLUE.EditValue != null) { teamId = Convert.ToInt32(TeamsLUE.EditValue); } //перезаписуємо дані працівників documentsLogic.DeleteDocumentEmployees(document, employeesDetailsView); foreach (StaffEmployeeView item in employeesDetailsView) { documentsLogic.SaveDocumentWithEmployees(document, item.Employee, teamId, mode); } if (cardId != null) { document.CardID = cardId; } document.DocumentSum = documentSum; document.EnterpriseID = enterpriseId; if (mode == "new") { document.CreatedDate = DateTime.Now; document.CreatedUserID = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; int userId = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; Logic.Staff.StaffEmployeeLogic staffLogic = new Logic.Staff.StaffEmployeeLogic(manager); StaffEmployee employee = staffLogic.GetByUserID(userId); if (employee != null) { document.CreatedEmployeeID = employee.ID; } //foreach (WareDocumentDetail detail in documentDetailsNew) //{ // documentDetailsLogic.SaveDocumentDetail(detail); //} documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "new"); } if (mode == "edit") { documentDetailsLogic.DeleteAllForDocument(document.ID); documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "edit"); //documentsLogic. } //якщо вказані дані про авто до перевіряємо чи дані вже існують string carNumber = CarNumberTE.Text; if (carNumber.Trim().Length > 0) { CWCarsLogic carsLogic = new CWCarsLogic(manager); CWCar car = null; categoryId = null; if (CarCategoriesCB.SelectedItem != null) { if (Convert.ToInt32(CarCategoriesCB.SelectedValue) > 0) { categoryId = Convert.ToInt32(CarCategoriesCB.SelectedValue); } } List <CWCar> cars = carsLogic.GetAll(CarNumberTE.Text, modelId, brandId); if (cars.Count > 0) { car = cars.FirstOrDefault(); } else { car = carsLogic.Create(brandId, modelId, carNumber, categoryId); } if (ContractorLUE.EditValue != null) { CWContractorCarsLogic contractorCars = new CWContractorCarsLogic(manager); contractorCars.Create(Convert.ToInt32(document.ContractorID), car); } DocumentCarsLogic documentCarsLogic = new DocumentCarsLogic(manager); documentCarsLogic.Create(document, car); } //Зберігаємо зміни manager.Save(); //Здійснюємо перерахунок залишків Compas.Logic.Wares.WareRemainsLogic remainsLogic = new Compas.Logic.Wares.WareRemainsLogic(manager); foreach (WareDocumentDetail detail in documentDetailsView) { if (document.FromStructureObjectID != null) { remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.FromStructureObjectID, null); } if (document.ToStructureObjectD != null) { remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.ToStructureObjectD, null); } } manager.Save(); int documentId = document.ID; if (AddPaymentCB.Checked == true) { DocumentPaymentData paymentForm = new DocumentPaymentData(documentId, document, cashRegister); paymentForm.ShowDialog(); } if (CloseAfterPayment == true) { this.Close(); } else { //після збереження даного документу - позиції документа очищаються і форма готова для створення нового документа CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info); manager = new ContextManager(); DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; //FillPayments(); documentDetailsNew = new List <WareDocumentDetail>(); documentDetailsOld = new List <WareDocumentDetail>(); documentDetailsDeleted = new List <WareDocumentDetail>(); documentDetailsView = new List <WareDocumentDetail>(); employeesDetailsView = new List <StaffEmployeeView>(); documentsLogic = new DocumentsLogic(manager); documentDetailsLogic = new DocumentDetailsLogic(manager); if (mode == "new") { //створюємо документ в памяті document = documentsLogic.CreateEmpty(); } documentDetailsViewer.Clear(); FillDetails(); } } }
/// <summary> /// Заповнюємо поля відображення даних документу /// </summary> private void Fill() { CompasLogger.Add(String.Format("p21"), CompasLogger.Level.Info); InitContractorsLookUp(); CompasLogger.Add(String.Format("p22"), CompasLogger.Level.Info); FillDocumentTypes(); CompasLogger.Add(String.Format("p23"), CompasLogger.Level.Info); FillToObjects(); CompasLogger.Add(String.Format("p24"), CompasLogger.Level.Info); //FillFromObjects(); CompasLogger.Add(String.Format("p25"), CompasLogger.Level.Info); FillCurrencies(); CompasLogger.Add(String.Format("p26"), CompasLogger.Level.Info); FillDetails(); CompasLogger.Add(String.Format("p27"), CompasLogger.Level.Info); FillTeams(); CompasLogger.Add(String.Format("p28"), CompasLogger.Level.Info); FillEmployees(); CompasLogger.Add(String.Format("p29"), CompasLogger.Level.Info); FillCategories(); FillCarInfo(); FillEnterprises(); if (mode == "new") { DateDE.EditValue = DateTime.Now; //CurrencyLUE.EditValue = CurrencyLUE. } ConfigurationParametersLogic config = new ConfigurationParametersLogic(manager); ConfigurationParameter param0 = config.Get(ParametersLogic.Parameter.DOCUMENT_TYPE.ToString()); if (param0 != null) { int value = Convert.ToInt32(param0.Value); DocumentTypeLUE.EditValue = value; } ConfigurationParameter param1 = config.Get(ParametersLogic.Parameter.DOCUMENT_TYPE_ENABLED.ToString()); if (param1 != null) { DocumentTypeLUE.Enabled = false; } ConfigurationParameter param2 = config.Get(ParametersLogic.Parameter.DOCUMENT_CAR_DEFAULT_CATEGORY.ToString()); if (param2 != null) { int value = Convert.ToInt32(param2.Value); foreach (object a in CarCategoriesCB.Items) { if (((CWCategory)a).ID == value) { CarCategoriesCB.SelectedItem = a; } } } ConfigurationParameter param3 = config.Get(ParametersLogic.Parameter.DOCUMENT_CAR_VISIBLE.ToString()); if (param3 != null) { CarGB.Visible = Helpers.ConfigDataTypeConverter.ConvertToBoolean(param3.Value); } ConfigurationParameter param4 = config.Get(ParametersLogic.Parameter.DOCUMENT_CURRENCY.ToString()); if (param4 != null) { int value = Convert.ToInt32(param4.Value); CurrencyLUE.EditValue = value; } ConfigurationParameter param5 = config.Get(ParametersLogic.Parameter.DOCUMENT_CURRENCY_ENABLED.ToString()); if (param5 != null) { CurrencyLUE.Enabled = Helpers.ConfigDataTypeConverter.ConvertToBoolean(param5.Value); } ConfigurationParameter param6 = config.Get(ParametersLogic.Parameter.DOCUMENT_DATE_ENABLED.ToString()); if (param6 != null) { DateDE.Enabled = Helpers.ConfigDataTypeConverter.ConvertToBoolean(param6.Value); } ConfigurationParameter param7 = config.Get(ParametersLogic.Parameter.DOCUMENT_FROM_OBJECT.ToString()); if (param7 != null) { int value = Convert.ToInt32(param7.Value); FromObjectLUE.EditValue = value; } ConfigurationParameter param8 = config.Get(ParametersLogic.Parameter.DOCUMENT_FROM_OBJECT_ENABLED.ToString()); if (param8 != null) { FromObjectLUE.Enabled = Helpers.ConfigDataTypeConverter.ConvertToBoolean(param8.Value); } ConfigurationParameter param9 = config.Get(ParametersLogic.Parameter.DOCUMENT_TO_OBJECT.ToString()); if (param9 != null) { int value = Convert.ToInt32(param9.Value); ToObjectLUE.EditValue = value; } ConfigurationParameter param10 = config.Get(ParametersLogic.Parameter.DOCUMENT_TO_OBJECT_ENABLED.ToString()); if (param10 != null) { ToObjectLUE.Enabled = Helpers.ConfigDataTypeConverter.ConvertToBoolean(param10.Value); } ConfigurationParameter param11 = config.Get(ParametersLogic.Parameter.DOCUMENT_PARAMETERS_IN_DOCUMENTDATA_VISIBLE.ToString()); if (param11 != null) { if (Helpers.ConfigDataTypeConverter.ConvertToBoolean(param11.Value) == false) { splitContainerControl1.Panel1.Visible = Helpers.ConfigDataTypeConverter.ConvertToBoolean(param11.Value); splitContainerControl1.Panel1.Width = 1; splitContainerControl1.SplitterPosition = 0; } } if (mode == "edit") { if (document.DocumentTypeID != null) { DocumentTypeLUE.EditValue = document.DocumentTypeID; } ContractorLUE.EditValue = document.ContractorID; NumberTE.Text = document.Number; if (document.Date != null) { DateDE.DateTime = Convert.ToDateTime(document.Date); } if (document.FromStructureObjectID != null) { FromObjectLUE.EditValue = document.FromStructureObjectID; } if (document.ToStructureObjectD != null) { ToObjectLUE.EditValue = document.ToStructureObjectD; } if (document.CurrencyID != null) { CurrencyLUE.EditValue = document.CurrencyID; } DescriptionTE.Text = document.Description; AddressTE.Text = document.Address; if (document.EnterpriseID != null) { EnterprisesCB.SelectedValue = document.EnterpriseID; } } }
/// <summary> /// Заповнюємо перелік позицій документу /// </summary> private void FillDetails() { CompasLogger.Add(String.Format("FillDetails1"), CompasLogger.Level.Info); int?selectedIndex = null; if (DetailsGV.SelectedRows.Count > 0) { selectedIndex = DetailsGV.SelectedRows[0].Index; } DocumentDetailsLogic detailsLogic = new DocumentDetailsLogic(manager); //documentDetailsView = documentDetailsNew; if (mode == "edit") { if (documentDetailsView.Count == 0) { documentDetailsView = detailsLogic.GetAll(id); } } if ((mode == "new") & (documentDetailsView == null)) { documentDetailsView = new List <WareDocumentDetail>(); } if (selectedIndex != null) { DetailsGV.Rows[Convert.ToInt32(selectedIndex)].Selected = true; } CompasLogger.Add(String.Format("FillDetails2"), CompasLogger.Level.Info); //foreach (WareDocumentDetail a in documentDetailsNew) //{ // documentDetailsView.Add(a); //} //documentDetailsNew.Clear(); //конвертуємо в список для перегляду і підраховуємо загальну суму документу //if (documentDetailsViewer == null) documentDetailsViewer = new List <DocumentDetailView>(); documentSum = 0; decimal documentDuration = 0; WareTimeLimitsLogic timeLimitsLogic = new WareTimeLimitsLogic(manager); if (documentDetailsView.Count > 0) { foreach (WareDocumentDetail detail in documentDetailsView.OrderBy(a => a.ID)) { //if(documentDetailsViewer.Contains( DocumentDetailView detailView = new DocumentDetailView(detail, manager); documentDetailsViewer.Add(detailView); documentSum = documentSum + Convert.ToDecimal(detail.EndPrice); WareTimeLimit timeLimit = timeLimitsLogic.GetByWareID(detail.WareID); if (timeLimit != null) { documentDuration = documentDuration + timeLimit.TimeLimit; } } } CompasLogger.Add(String.Format("FillDetails3"), CompasLogger.Level.Info); DurationL.Text = documentDuration.ToString("n2"); DocumentSumaL.Text = documentSum.ToString("n2"); DetailsGV.AutoGenerateColumns = false; DetailsGV.DataSource = documentDetailsViewer; if (DetailsGV.Rows.Count == 0) { if (DetailsGV.SelectedRows.Count > 0) { DetailsGV.SelectedRows[0].Selected = false; } } //DetailsGV.Update(); CompasLogger.Add(String.Format("FillDetails4"), CompasLogger.Level.Info); }
/// <summary> /// При успішній перевірці логіна і пароля створюється КОНТЕКСТ БЕЗПЕКИ /// КОНТЕКСТ БЕЗПЕКИ зберігається в AppDomain.CurrentDomain в змінну "SecurityContext", /// до якого мають доступ всі внутрішні проекти /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveBt_Click(object sender, EventArgs e) { string hash = ""; string login = LoginTB.Text; CompasLogger.Add(String.Format("Try to login: {0}", login), CompasLogger.Level.Info); hash = Helpers.Crypto.sha512encrypt(PasswordTB.Text + login); CompasLogger.Add(String.Format("Generated HASH"), CompasLogger.Level.Info); Compas.Logic.Security.CompasIdentity identity = new Compas.Logic.Security.CompasIdentity(login, hash); CompasLogger.Add(String.Format("Identity class created"), CompasLogger.Level.Info); CompasPrincipal principal = new CompasPrincipal(identity); AppDomain.CurrentDomain.SetData("Mode", ((Helpers.Item)(ModeCB.SelectedItem)).ID); CompasLogger.Add(String.Format("Mode saved: {0}", ((Helpers.Item)(ModeCB.SelectedItem)).Name), CompasLogger.Level.Info); if (login != "romin") { if (identity.IsAuthenticated == true) { CompasLogger.Add(String.Format("Success login: {0}", login), CompasLogger.Level.Info); CompasSecurityContext context = new CompasSecurityContext(identity, principal); AppDomain.CurrentDomain.SetData("SecurityContext", context); AppDomain.CurrentDomain.SetData("Mode", ((Helpers.Item)(ModeCB.SelectedItem)).ID); //символьне значення AppDomain.CurrentDomain.SetData("InstallationID", Compas.Logic.Config.InstallationIdentifyLogic.GenerateInstallationID()); //числове значення AppDomain.CurrentDomain.SetData("InstallationIDInt", Compas.Logic.Config.InstallationIdentifyLogic.InstallationIDInt); MainMDI form = new MainMDI(); this.Visible = false; PasswordTB.Text = ""; LoginTB.Text = ""; this.Visible = false; form.ShowDialog(); this.Close(); } else { CompasLogger.Add(String.Format("Fail login: {0}", login), CompasLogger.Level.Warn); MessageBox.Show("Не знайдено користувача з вказаним логіном і паролем"); } } else { CompasSecurityContext context = new CompasSecurityContext(identity, principal); AppDomain.CurrentDomain.SetData("SecurityContext", context); //installationLogic.ClearInstallationID(); CompasLogger.Add("Генерація ідентифікатора", CompasLogger.Level.Info); //Compas.Logic.Configuration.InstallationIdentifyLogic.ClearInstallationID(); //символьне значення AppDomain.CurrentDomain.SetData("InstallationID", Compas.Logic.Config.InstallationIdentifyLogic.GenerateInstallationID()); //числове значення AppDomain.CurrentDomain.SetData("InstallationIDInt", Compas.Logic.Config.InstallationIdentifyLogic.InstallationIDInt); MainMDI form = new MainMDI(); this.Visible = false; PasswordTB.Text = ""; LoginTB.Text = ""; this.Visible = false; form.ShowDialog(); this.Close(); } }