public static void WithExtraFields(List <ExtraField> listOfExtraFields) { List <ExtraField> newListOfExtraFields = new List <ExtraField>(); foreach (var extraField in listOfExtraFields) { ExtraField newExtraField = new ExtraField(); newExtraField.key = extraField.key; newExtraField.value = extraField.value; newListOfExtraFields.Add(newExtraField); } transaction.extraFields = newListOfExtraFields; }
private void UpdateState() { if (ExtraField == null) { DisplayName = Property.GetAttribute <DisplayNameAttribute>()?.DisplayName ?? Property.Name; ValueType = Property.PropertyType; } else { DisplayName = ExtraField.GetDisplayName(); ValueType = typeof(decimal); if (ExtraField is Level1Fields l1) { ValueType = l1.ToType(); } } }
private TransactionID TransactionUpdate(string transSerial, string transDoc, double transDocNumber) { TransactionID insertedTrans = null; try { transactionError = false; // Motor do documento BSOItemTransaction bsoItemTransaction = null; bsoItemTransaction = new BSOItemTransaction(); bsoItemTransaction.UserPermissions = systemSettings.User; bsoItemTransaction.TransactionType = DocumentTypeEnum.dcTypeSale; //Tipo de documento para cabeçalho --> vendas // Motor dos detalhes (linhas) BSOItemTransactionDetail bsoItemTransDetail = null; bsoItemTransDetail = new BSOItemTransactionDetail(); //** bsoItemTransDetail.TransactionType = DocumentTypeEnum.dcTypeSale; //Tipo de documento para linhas --> vendas // Utilizador e permissões bsoItemTransDetail.UserPermissions = systemSettings.User; bsoItemTransDetail.PermissionsType = FrontOfficePermissionEnum.foPermByUser; bsoItemTransaction.BSOItemTransactionDetail = bsoItemTransDetail; //Adicionar os detalhes ao documento bsoItemTransDetail = null; //Inicializar uma transação bsoItemTransaction.Transaction = new ItemTransaction(); bsoItemTransaction.InitNewTransaction(transDoc, transSerial); if (transDocNumber > 0) { bsoItemTransaction.Transaction.TransDocNumber = transDocNumber; } //Terceiro double partyId = 0; double.TryParse(txtTransPartyId.Text, out partyId); bsoItemTransaction.PartyID = partyId; ItemTransaction trans = bsoItemTransaction.Transaction; if (trans == null) { throw new Exception(string.Format("Não foi possivel inicializar o documento [{0}] da série [{1}]", transDoc, transSerial)); } // // Limpar todas as linhas int i = 1; while (trans.Details.Count > 0) { trans.Details.Remove(ref i); } //Set Create date and deliverydate var createDate = DateTime.Today; DateTime.TryParse(txtTransDate.Text, out createDate); trans.CreateDate = createDate; trans.ActualDeliveryDate = createDate; // // Definir se o imposto é incluido trans.TransactionTaxIncluded = chkTransTaxIncluded.Checked; // // Definir o pagamento. Neste caso optou-se por utilizar o primeiro pagamento disponivel na base de dados short PaymentId = dsoCache.PaymentProvider.GetFirstID(); trans.Payment = dsoCache.PaymentProvider.GetPayment(PaymentId); // // Comentários / Observações trans.Comments = "Gerado por " + Application.ProductName; // desconto global double globalDiscount = 0; double.TryParse(txtTransGlobalDiscount.Text, out globalDiscount); trans.PaymentCumulativeDiscountPercent1 = globalDiscount; // //------------------------------------------------------------------------- // DOCUMENT DETAILS //------------------------------------------------------------------------- // //Adicionar a primeira linha ao documento double qty = 0; double.TryParse(txtTransQuantityL1.Text, out qty); double unitPrice = 0; double.TryParse(txtTransUnitPriceL1.Text, out unitPrice); double taxPercent = 0; double.TryParse(txtTransTaxRateL1.Text, out taxPercent); short wareHouseId = 0; short.TryParse(txtTransWarehouseL1.Text, out wareHouseId); Item item = dsoCache.ItemProvider.GetItem(txtTransItemL1.Text, systemSettings.BaseCurrency); TransAddDetail(trans, item, qty, txtTransUnL1.Text, unitPrice, taxPercent, wareHouseId);//, colorId, sizeId, "", serialNumber, lotId, lotDescription, lotExpDate, 0, lotRetYear, lotEditionId); // if (chkDocExtraField1.Checked == true || chkDocExtraField2.Checked == true) { var ExtraFiedsDocument = new ExtraFieldList(); if (chkDocExtraField1.Checked == true) { ExtraField extraField1 = new ExtraField(); extraField1.ExtraFieldID = 1; //nº do campo extra extraField1.TextAnswer = txtNomeMotorista.Text; int idadeMotorista = 0; int.TryParse(txtIdadeMotorista.Text, out idadeMotorista); extraField1.NumberAnswer = idadeMotorista; extraField1.TransDocNumber = transDocNumber; extraField1.TransSerial = transSerial; extraField1.TransDocument = transDoc; ExtraFiedsDocument.Add(extraField1); } if (chkDocExtraField2.Checked == true) { ExtraField extraField2 = new ExtraField(); extraField2.ExtraFieldID = 2; //nº do campo extra extraField2.TextAnswer = txtEstadoMaterial.Text; extraField2.BooleanAnswer = chkGarantia.Checked; extraField2.TransDocNumber = transDocNumber; extraField2.TransSerial = transSerial; extraField2.TransDocument = transDoc; ExtraFiedsDocument.Add(extraField2); } bsoItemTransaction.ExtraFields = ExtraFiedsDocument; } bsoItemTransaction.Calculate(true); bsoItemTransaction.SaveDocument(false, false); if (!transactionError) { insertedTrans = bsoItemTransaction.Transaction.TransactionID; } bsoItemTransDetail = null; } catch (Exception ex) { MessageBox.Show(ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(insertedTrans); }
private void RefreshTypeList() { LVTypes.Items.Clear(); DBConnection.QueryConnection.Open(); string query = $"Select DegerTabloAdı,TabloAdi,AlanAdi,VeriTuru from Owner{DataBaseConnectionOptions.OwnerUserId}"; using (var cmd = new MySqlCommand(query, DBConnection.QueryConnection)) { using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { var lvItem = new ListViewItem { Text = dr["DegerTabloAdi"].ToString() }; var tür = "Kişi"; switch (dr["TabloAdi"].ToString()) { case "Institution": tür = "Kurum"; break; } lvItem.SubItems.AddRange(new [] { dr["AlanAdi"].ToString(), tür, ExtraField.GetFieldName(dr["VeriTuru"].ToString()) }); LVTypes.Items.Add(lvItem); } } } DBConnection.QueryConnection.Close(); }
private void btnEkle_Click(object sender, EventArgs e) { //PersonTypes pType = (from x in DBConnection.DbCon.PersonTypes where x.OwnerId == DataBaseConnectionOptions.OwnerUserId && x.Isim==cbAlan.SelectedItem.ToString() select x).First(); //if (pType == null) //{ // return; //} //var eField = new ExtraField //{ // ExtraName = txtİsim.Text, // InputType = cbTür.SelectedItem.ToString(), // ShowType = pType //}; //DBConnection.DbCon.ExtraField.Add(eField); //DBConnection.DbCon.SaveChanges(); DBConnection.QueryConnection.Open(); var id = Guid.NewGuid().ToString(); var tür = "Institution"; if (cbTür.Text == "Kişi") { tür = "Person"; } string tableQuery = $"INSERT INTO Owner1 (Id,DegerTabloAdi,TabloAdi,AlanAdi,VeriTuru) VALUES ('{id}','{txtİsim.Text}','{tür}','{cbAlan.Text}','{ExtraField.GetFieldTypeName(cmbxVeriTürü.SelectedIndex)}')"; using (var cmd = new MySqlCommand(tableQuery, DBConnection.QueryConnection)) { cmd.ExecuteNonQuery(); } tableQuery = $"CREATE TABLE {txtİsim.Text+"_"+ DataBaseConnectionOptions.OwnerUserId} (Value {ExtraField.GetFieldTypeName(cmbxVeriTürü.SelectedIndex)}, ForeignId varchar(45))"; using (var cmd = new MySqlCommand(tableQuery, DBConnection.QueryConnection)) { cmd.ExecuteNonQuery(); } DBConnection.QueryConnection.Close(); }
/// <summary>Serves as a hash function for a particular type. </summary> /// <returns>A hash code for the current <see cref="T:System.Object" />.</returns> public override int GetHashCode() { return((Property?.GetHashCode() ?? 0) ^ (ExtraField?.GetHashCode() ?? 0)); }
/// <summary> /// Save settings. /// </summary> /// <param name="storage">Settings storage.</param> public void Save(SettingsStorage storage) { storage.SetValue(_propKey, Property.ToStorage(false)); storage.SetValue(nameof(ExtraField), ExtraField?.ToStorage()); }
public void CreateDomainLevel2() { try { var ctx = ApplicationDbContext.Create(); //already OK if (ctx.Forms.Any()) { return; } var reader = new ReadOnlyContext(); var db = MemoryDB.LoadDomainLevel2(reader); var container = new MemoryDB(); foreach (var item in db.Forms) { var form = new Form { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, CreationDate = item.CreationDate, Description = item.Description, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Name = item.Name, }; container.Forms.Add(form); } foreach (var item in db.AgentLogs) { var agentLog = new AgentLog { Id = item.Id, //Agent = agent, //AgentId = agent.Id, AgentId = item.AgentId, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, //TimeZone = timeZone, //TimeZoneId = timeZone.Id, TimeZoneId = item.TimeZoneId, CreationDate = item.CreationDate, DialingHours = item.DialingHours, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Project = item.Project, ProjectId = item.ProjectId, Successes = item.Successes, TrainingHours = item.TrainingHours, }; container.AgentLogs.Add(agentLog); } //foreach (var item in db.CampaignCallCodes) //{ // var campaignCallCodes = new CampaignCallCode // { // Id = item.Id, // //CallCode = callCode, // //CallCodeId = callCode.Id, // CallCodeId = item.CallCodeId, // //Campaign = campaign, // //CampaignId = campaign.Id, // CampaignId = item.CampaignId, // CreationDate = item.CreationDate, // IsDeleted = item.IsDeleted, // LastUpdate = item.LastUpdate, // }; // container.CampaignCallCodes.Add(campaignCallCodes); //} foreach (var item in db.ExtraFields) { var extraField = new ExtraField { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, CreationDate = item.CreationDate, // ExtraFieldOptions = item.ExtraFieldOptions, FieldName = item.FieldName, IsDeleted = item.IsDeleted, TypeId = item.TypeId, LastUpdate = item.LastUpdate, }; container.ExtraFields.Add(extraField); } foreach (var item in db.UserCampaigns) { var userCampaign = new UserCampaign { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, //User = user, //UserId = user.Id, UserId = item.UserId, BudgetedHours = item.BudgetedHours, CreationDate = item.CreationDate, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, PayRateDialingHours = item.PayRateDialingHours, PayRateSuccess = item.PayRateSuccess, PayRateTrainingHours = item.PayRateTrainingHours, }; container.UserCampaigns.Add(userCampaign); } foreach (var item in db.UserProjects) { var userProject = new UserProject { Id = item.Id, //UserCampaign = userCampaign, //UserCampaignId = userCampaign.Id, UserCampaignId = item.UserCampaignId, //Project = project, //ProjectId = project.Id, ProjectId = item.ProjectId, //User = user, //UserId = user.Id, UserId = item.UserId, CreationDate = item.CreationDate, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, }; container.UserProjects.Add(userProject); } foreach (var item in db.UsersHistory) { var userHistory = new UserHistory { Id = item.Id, //User = user, //UserId = user.Id, UserId = item.UserId, //Campaign = campaign, //CampaignId = campaign?.Id, CampaignId = item.CampaignId, ConnectionId = item.ConnectionId, CreationDate = item.CreationDate, Duration = item.Duration, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, LoggedIn = item.LoggedIn, LoggedOff = item.LoggedOff, }; container.UsersHistory.Add(userHistory); } ctx.Forms.AddRange(container.Forms); ctx.AgentLogs.AddRange(container.AgentLogs); //ctx.CampaignCallCodes.AddRange(container.CampaignCallCodes); ctx.ExtraFields.AddRange(container.ExtraFields); ctx.UserCampaigns.AddRange(container.UserCampaigns); ctx.UserProjects.AddRange(container.UserProjects); ctx.UsersHistory.AddRange(container.UsersHistory); ctx.SaveChanges(); } catch (Exception ex) { var str = ex.ToString(); System.Diagnostics.Debug.WriteLine(str); } }
public static ExtraFieldValidationResult ValidateValueForUser(this ExtraField extraField, string fieldValue, User user) { var required = (user.IsRegistered() && extraField.RequiredForUsers) || (user.IsVendor() && extraField.RequiredForAgents); if (required && fieldValue.IsNullEmptyOrWhiteSpace()) { return(ExtraFieldValidationResult.EmptyValueForRequiredField); } var visible = (user.IsRegistered() && extraField.VisibleToUsers) || (user.IsVendor() && extraField.VisibleToAgents); if (user.IsRegistered() && (!extraField.IsUserEditable || !visible)) { return(ExtraFieldValidationResult.NonEditableField); } switch (extraField.FieldType) { case InputFieldType.Number: if (!fieldValue.IsNumeric()) { return(ExtraFieldValidationResult.InvalidValueForFieldType); } if (extraField.MinimumValue.IsNumeric()) { if (extraField.MinimumValue.GetInteger(false) > fieldValue.GetInteger(false)) { return(ExtraFieldValidationResult.OutOfRangeValue); } } if (extraField.MaximumValue.IsNumeric()) { if (extraField.MaximumValue.GetInteger(false) < fieldValue.GetInteger(false)) { return(ExtraFieldValidationResult.OutOfRangeValue); } } break; case InputFieldType.Email: if (!fieldValue.IsValidEmail()) { return(ExtraFieldValidationResult.InvalidValueForFieldType); } break; case InputFieldType.DateTime: if (!fieldValue.IsDateTime()) { return(ExtraFieldValidationResult.InvalidValueForFieldType); } if (extraField.MinimumValue.IsDateTime()) { if (extraField.MinimumValue.GetDateTime(false) > fieldValue.GetDateTime(false)) { return(ExtraFieldValidationResult.OutOfRangeValue); } } if (extraField.MaximumValue.IsDateTime()) { if (extraField.MaximumValue.GetDateTime(false) < fieldValue.GetDateTime(false)) { return(ExtraFieldValidationResult.OutOfRangeValue); } } break; case InputFieldType.Color: if (!fieldValue.IsColor()) { return(ExtraFieldValidationResult.InvalidValueForFieldType); } break; case InputFieldType.Dropdown: break; case InputFieldType.ImageUpload: break; case InputFieldType.FileUpload: break; default: return(ExtraFieldValidationResult.UnknownError); } return(ExtraFieldValidationResult.ValidField); }
public static string GetDbFieldName(this ExtraField extraField) { return(string.Format(ExtraFieldNameFormat, extraField.Id)); }
public static List <ExtraField> GetExtraFields(Stream stream) { var beforePos = stream.Position; try { byte[] headerBuffer = new byte[10]; int numReadBytes = 0; numReadBytes = stream.Read(headerBuffer, 0, 10); if (numReadBytes < 10) { throw new InvalidDataException("архив повреждён"); } byte id1 = headerBuffer[0]; byte id2 = headerBuffer[1]; if (id1 != 0x1f || id2 != 0x8b) { throw new InvalidDataException("Неверное магическое число в заголовке файла"); } byte flg = headerBuffer[3]; if (((HeaderFLG)flg & HeaderFLG.FEXTRA) == 0) { return(new List <ExtraField>()); } byte[] extraLengthBuffer = new byte[2]; numReadBytes = stream.Read(extraLengthBuffer, 0, 2); if (numReadBytes < 2) { throw new InvalidDataException("архив повреждён"); } short extraLength = BitConverter.ToInt16(extraLengthBuffer, 0); byte[] extraFieldsBuffer = new byte[extraLength]; numReadBytes = stream.Read(extraFieldsBuffer, 0, extraLength); if (numReadBytes < extraLength) { throw new InvalidDataException("архив повреждён"); } //var extraFieldsBufferList = extraFieldsBuffer.ToList(); List <ExtraField> result = new List <ExtraField>(); try { for (int i = 0; i < extraLength;) { byte sid1 = extraFieldsBuffer[i]; byte sid2 = extraFieldsBuffer[i + 1]; short subExtraLength = BitConverter.ToInt16(extraFieldsBuffer, i + 2); var data = extraFieldsBuffer.ToList().GetRange(i + 4, subExtraLength).ToArray(); ExtraField ef = new ExtraField(sid1, sid2, data); result.Add(ef); i = i + 4 + subExtraLength; } return(result); } catch { throw new InvalidDataException("архив повреждён"); } } catch (Exception e) { throw e; } finally { stream.Position = beforePos; } }
private void toolStripLabel5_Click(object sender, EventArgs e) { if ((sender as ToolStripLabel).Text == "Save") { List <Account> list = new List <Account>(context.Accounts.Where(o => o.Password == label17.Text && o.service.section.UserId == user.Id)); Account account = list[0]; List <ExtraField> eList = new List <ExtraField>(context.ExtraFields.Where(o => o.AccountId == account.Id)); NameExtraField.Visible = false; ValueExtraField.Visible = false; checkLabels(); if (label4.Visible == true) { context.ExtraFields.RemoveRange(eList); context.SaveChanges(); ExtraField tmp_ = new ExtraField(); tmp_.AccountId = account.Id; tmp_.Name = label4.Text; tmp_.Value = label5.Text; eList[0] = tmp_; if (label13.Visible == true) { ExtraField tmp = new ExtraField(); tmp.AccountId = account.Id; tmp.Name = label13.Text; tmp.Value = label16.Text; eList[1] = tmp; } if (label12.Visible == true) { ExtraField tmp = new ExtraField(); tmp.AccountId = account.Id; tmp.Name = label12.Text; tmp.Value = label7.Text; eList[2] = tmp; } if (label11.Visible == true) { ExtraField tmp = new ExtraField(); tmp.AccountId = account.Id; tmp.Name = label11.Text; tmp.Value = label8.Text; eList[3] = tmp; } if (label10.Visible == true) { ExtraField tmp = new ExtraField(); tmp.AccountId = account.Id; tmp.Name = label10.Text; tmp.Value = label9.Text; eList[4] = tmp; } } context.Accounts.Remove(account); context.SaveChanges(); account.Password = PasswordtextBox2.Text; account.time = DateTime.Now; foreach (var item in context.Services) { if (ServiceComboBox2.SelectedItem.ToString() == item.Name && item.section.Name == SectionComboBox1.SelectedItem.ToString()) { account.ServiceId = item.Id; break; } } context.Accounts.Add(account); context.SaveChanges(); if (eList.Count != 0) { for (int i = 0; i < eList.Count; i++) { context.ExtraFields.Add(new ExtraField { Name = eList[i].Name, Value = eList[i].Value, AccountId = account.Id }); context.SaveChanges(); } //context.ExtraFields.AddRange(eList); //context.SaveChanges(); } AddVisibleFalse(); showVisibleFalse(); edit = false; UpdateTreeView(); } if (label14.Visible == false) { return; } edit = true; showVisibleFalse(); AddVisibleTrue(); (sender as ToolStripLabel).Text = "Save"; button4.Visible = false; button3.Visible = false; button2.Visible = false; button1.Visible = false; PasswordtextBox2.Text = label17.Text; checkLabels(); }