public async void LoadDataAsync()
        {
            // cbSearch.SelectedIndex = -1;
            try
            {
                AllItems = await SAItem.GetAllItems(cbSearch.Text);

                List <CommonItem> k = new List <CommonItem>();
                foreach (CommonItem Item in AllItems)
                {
                    decimal temp = Item.SellingPriceCent;
                    Item.ParcePrice = temp / 100;
                }

                cbSearch.DataSource         = AllItems;
                cbSearch.SelectedIndex      = -1;
                cbSearch.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                cbSearch.AutoCompleteSource = AutoCompleteSource.ListItems;
                cbSearch.DropDownStyle      = ComboBoxStyle.DropDown;
                AllContacts = await SAContract.GetAllContracts(cbSearchContract.Text);

                cbSearchContract.DataSource         = AllContacts;
                cbSearchContract.SelectedIndex      = -1;
                cbSearchContract.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                cbSearchContract.AutoCompleteSource = AutoCompleteSource.ListItems;
                cbSearchContract.DropDownStyle      = ComboBoxStyle.DropDown;
                // AllMols = await SAOwner.getAllMols(DataHolder.Owner.OwnerId);
                CommonMol primeryMol = DataHolder.PrimeryMol;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, DataHolder.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        internal static bool UpdateMol(CommonMol oldMol)
        {
            DatabaseEntities entities = new DatabaseEntities();
            MOL dbMol = entities.MOLs.FirstOrDefault(p => p.MolId == oldMol.MolId);

            if (dbMol == null)
            {
                return(false);
            }
            dbMol.FirstName = oldMol.FirstName;
            dbMol.Address   = oldMol.Address;
            dbMol.Email     = oldMol.Email;
            dbMol.Phone     = oldMol.Phone;
            dbMol.LastName  = oldMol.LastName;

            entities.MOLs.Attach(dbMol);
            var entry = entities.Entry(dbMol);

            entry.Property(e => e.FirstName).IsModified = true;
            entry.Property(e => e.Address).IsModified   = true;
            entry.Property(e => e.Email).IsModified     = true;
            entry.Property(e => e.Phone).IsModified     = true;
            entry.Property(e => e.LastName).IsModified  = true;
            entities.SaveChanges();
            return(true);
        }
示例#3
0
        private async void pictureBoxGreen_Click(object sender, EventArgs e)
        {
            if (dgvMol.SelectedRows.Count == 1 && dgvMol.SelectedRows[0] != null)
            {
                CommonMol selectedItem = (CommonMol)dgvMol.SelectedRows[0].DataBoundItem;
                if (DataHolder.PrimeryMol == null)
                {
                    CommonMol tempMol = new CommonMol();
                    tempMol.MolId = Guid.NewGuid();

                    CommonMol newPrimeryMol = await SAOwner.SetPrimery(tempMol, selectedItem);

                    CommonMol molToRemove = NonPrimeryMols.FirstOrDefault(p => p.MolId == newPrimeryMol.MolId);
                    NonPrimeryMols.Remove(molToRemove);
                    List <CommonMol> temp = new List <CommonMol>();
                    temp.Add(newPrimeryMol);
                    dgvPrimaryMol.DataSource = null;
                    dgvPrimaryMol.DataSource = temp;

                    if (PrimeryMol.OwnerId != Guid.Empty)
                    {
                        PrimeryMol.IsPrimery = false;
                        NonPrimeryMols.Add(PrimeryMol);
                    }

                    dgvMol.DataSource     = null;
                    dgvMol.DataSource     = NonPrimeryMols;
                    PrimeryMol            = newPrimeryMol;
                    DataHolder.PrimeryMol = newPrimeryMol;
                }
            }
        }
示例#4
0
        public static async Task <bool> PostCreateMol(CommonMol mol)
        {
            HttpResponseMessage response;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(DataHolder.ServerAddress);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic");

                try
                {
                    response = await client.PostAsJsonAsync("api/owner/createmol", mol);
                }
                catch (HttpRequestException ex)
                {
                    throw new Exception(ex.InnerException.Message);
                }

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                return(await response.Content.ReadAsAsync <bool>());
            }
        }
示例#5
0
        public static async Task <CommonMol> SetPrimery(CommonMol oldMol, CommonMol newMol)
        {
            CommonMol   mol = new CommonMol();
            List <Guid> ids = new List <Guid>();

            ids.Add(oldMol.MolId);
            ids.Add(newMol.MolId);
            HttpResponseMessage response;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(DataHolder.ServerAddress);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic");

                try
                {
                    response = await client.PostAsJsonAsync("api/owner/changeprimery", ids);
                }
                catch (HttpRequestException ex)
                {
                    throw new Exception(ex.InnerException.Message);
                }

                if (response.IsSuccessStatusCode)
                {
                    mol = await response.Content.ReadAsAsync <CommonMol>();
                }
            }
            return(mol);
        }
示例#6
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            CommonMol mol = new CommonMol();

            mol.MolId     = OldMol?.MolId ?? Guid.Empty;
            mol.OwnerId   = DataHolder.Owner.OwnerId;
            mol.Address   = tbAddress.Text;
            mol.Email     = tbPhone.Text;
            mol.FirstName = tbFirstname.Text;
            mol.LastName  = tbLastname.Text;
            mol.Phone     = tbEmail.Text;
            bool success;

            if (OldMol == null)
            {
                success = await SAOwner.PostCreateMol(mol);
            }
            else
            {
                success = await SAOwner.PostUpdateMol(mol);
            }

            if (success)
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                labelError.Visible = true;
            }
        }
        private async void cbSearchContract_SelectionChangeCommitted(object sender, EventArgs e)
        {
            mlLabel11.Text = ((CommonContract)cbSearchContract.SelectedItem).CompanyName;
            mlLabel12.Text = ((CommonContract)cbSearchContract.SelectedItem).VatNumber;
            mlLabel14.Text = ((CommonContract)cbSearchContract.SelectedItem).Bulstat;
            mlLabel16.Text = ((CommonContract)cbSearchContract.SelectedItem).Address;
            List <CommonMol> mols = await SAOwner.getAllMols(((CommonContract)cbSearchContract.SelectedItem).PartnerId);

            CommonMol mol = mols.Count == 0 ? new CommonMol() : mols.First();

            mlLabel13.Text = mol.FirstName + " " + mol.LastName;
        }
示例#8
0
 public AddEditMolForm(CommonMol oldMol)
 {
     InitializeComponent();
     if (oldMol != null)
     {
         tbFirstname.Text = !string.IsNullOrEmpty(oldMol.FirstName) ? oldMol.FirstName : "";
         tbLastname.Text  = !string.IsNullOrEmpty(oldMol.LastName) ? oldMol.LastName : "";
         tbAddress.Text   = !string.IsNullOrEmpty(oldMol.Address) ? oldMol.Address : "";
         tbPhone.Text     = !string.IsNullOrEmpty(oldMol.Email) ? oldMol.Email : "";
         tbEmail.Text     = !string.IsNullOrEmpty(oldMol.Phone) ? oldMol.Phone : "";
     }
     OldMol = oldMol;
 }
示例#9
0
        private void btnEditMol_Click(object sender, EventArgs e)
        {
            if (dgvMol.SelectedRows.Count == 1 && dgvMol.SelectedRows[0] != null)
            {
                CommonMol      selectedItem = (CommonMol)dgvMol.SelectedRows[0].DataBoundItem;
                AddEditMolForm form         = new AddEditMolForm(selectedItem);

                if (form.ShowDialog() == DialogResult.OK)
                {
                    LoadMolList();
                }
            }
        }
示例#10
0
//        private void tbSearchContracts_KeyDown(object sender, KeyEventArgs e)
//        {
//            if (e.KeyCode != Keys.Enter)
//            {
//                return;
//            }
//
//            LoadDataContracts();
//        }

        private async void btnEditContract_Click(object sender, EventArgs e)
        {
            if (dgvContracts.SelectedRows.Count == 1 && dgvContracts.SelectedRows[0] != null)
            {
                CommonContract   selectedItem = (CommonContract)dgvContracts.SelectedRows[0].DataBoundItem;
                List <CommonMol> mols         = await SAOwner.getAllMols(selectedItem.PartnerId);

                CommonMol           mol  = mols.Count == 0 ? new CommonMol() : mols.First();
                AddEditContractForm form = new AddEditContractForm(selectedItem, mol);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    LoadDataContracts();
                }
            }
        }
示例#11
0
        internal static bool CreateMol(CommonMol newMol)
        {
            DatabaseEntities entities = new DatabaseEntities();
            MOL mol = new MOL();

            mol.OwnerId   = newMol.OwnerId;
            mol.Address   = newMol.Address;
            mol.Email     = newMol.Email;
            mol.FirstName = newMol.FirstName;
            mol.LastName  = newMol.LastName;
            mol.Phone     = newMol.Phone;
            mol.MolId     = Guid.NewGuid();
            mol.IsPrimary = false;
            entities.MOLs.Add(mol);
            entities.SaveChanges();
            return(true);
        }
示例#12
0
        private async void btnDeleteMol_Click(object sender, EventArgs e)
        {
            if (dgvMol.SelectedRows.Count == 1 && dgvMol.SelectedRows[0] != null)
            {
                CommonMol selectedItem = (CommonMol)dgvMol.SelectedRows[0].DataBoundItem;
                bool      success      = await SAOwner.PostDeleteMol(selectedItem.MolId);

                if (success)
                {
                    LoadMolList();
                }
                else
                {
                    MessageBox.Show(DataHolder.GetString("error_deleting_mol"), DataHolder.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public AddEditContractForm(CommonContract c, CommonMol m)
        {
            InitializeComponent();
            contract = c;
            mol      = m;

            tbAdressContract.Text        = contract.Address;
            tbBulstatNumberContract.Text = contract.Bulstat;
            tbCompanyNameContract.Text   = contract.CompanyName;
            tbEmailContract.Text         = contract.Email;
            tbPhoneContract.Text         = contract.Phone;
            tbVatNumberContract.Text     = contract.VatNumber;
            tbAdressMolContract.Text     = mol.Address;
            tbEmailMolContract.Text      = mol.Email;
            tbFirstNameMol.Text          = mol.FirstName;
            tbLastNameMol.Text           = mol.LastName;
            tbPhoneMolContract.Text      = mol.Phone;
        }
示例#14
0
        private async void pictureBoxRed_Click(object sender, EventArgs e)
        {
            if (dgvPrimaryMol.SelectedRows.Count == 1 && dgvPrimaryMol.SelectedRows[0] != null)
            {
                CommonMol selectedItem = (CommonMol)dgvPrimaryMol.SelectedRows[0].DataBoundItem;

                CommonMol tempMol = new CommonMol();
                tempMol.MolId = Guid.NewGuid();

                CommonMol newNonPrimeryMol = await SAOwner.SetPrimery(selectedItem, tempMol);

                PrimeryMol             = new CommonMol();
                DataHolder.PrimeryMol  = null;
                selectedItem.IsPrimery = false;
                NonPrimeryMols.Add(selectedItem);
                dgvPrimaryMol.DataSource = null;
                dgvMol.DataSource        = null;
                dgvMol.DataSource        = NonPrimeryMols;
            }
        }
示例#15
0
        internal static List <CommonMol> GetAllMols(Guid ownerId)
        {
            DatabaseEntities entities  = new DatabaseEntities();
            List <MOL>       allDbMols = entities.MOLs.Where(p => p.OwnerId == ownerId).ToList();
            List <CommonMol> allMols   = new List <CommonMol>();

            foreach (var dbMol in allDbMols)
            {
                CommonMol mol = new CommonMol();
                mol.OwnerId   = dbMol.OwnerId;
                mol.Address   = dbMol.Address;
                mol.Email     = dbMol.Email;
                mol.FirstName = dbMol.FirstName;
                mol.LastName  = dbMol.LastName;
                mol.MolId     = dbMol.MolId;
                mol.Phone     = dbMol.Phone;
                mol.IsPrimery = dbMol.IsPrimary;
                allMols.Add(mol);
            }
            return(allMols);
        }
        private async void cbSearchOrders_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (trigger)
            {
                if (Settings.Default.ItemMapping)
                {
                    KeyValuePair <Guid, List <CommonItem> > mappedItems = MappedItems.FirstOrDefault(p => p.Key == ((CommonContract)cbSearchOrders.SelectedItem).PartnerId);
                    cbSearchGoodsOrders.DataSource = mappedItems.Value;
                }

                companyNameHidden.Text = ((CommonContract)cbSearchOrders.SelectedItem).CompanyName;
                lbVatHidden.Text       = ((CommonContract)cbSearchOrders.SelectedItem).VatNumber;
                lbBulstatHidden.Text   = ((CommonContract)cbSearchOrders.SelectedItem).Bulstat;
                lbAddressHidden.Text   = ((CommonContract)cbSearchOrders.SelectedItem).Address;
                List <CommonMol> mols = await SAOwner.getAllMols(((CommonContract)cbSearchOrders.SelectedItem).PartnerId);

                CommonMol mol = mols.Count == 0 ? new CommonMol() : mols.First();
                lbMolHidden.Text = mol.FirstName + " " + mol.LastName;
            }
            else
            {
                trigger = true;
            }
        }
示例#17
0
        internal static CommonMol ChangePrimary(Guid oldMolId, Guid newMolId)
        {
            CommonMol        result   = new CommonMol();
            DatabaseEntities entities = new DatabaseEntities();
            MOL dbMol = entities.MOLs.FirstOrDefault(p => p.MolId == oldMolId);

            if (dbMol != null)
            {
                dbMol.IsPrimary = false;
                entities.MOLs.Attach(dbMol);
                var entry = entities.Entry(dbMol);
                entry.Property(e => e.IsPrimary).IsModified = true;
                entities.SaveChanges();
            }

            MOL newPrimeryMol = entities.MOLs.FirstOrDefault(p => p.MolId == newMolId);

            if (newPrimeryMol != null)
            {
                newPrimeryMol.IsPrimary = true;
                entities.MOLs.Attach(newPrimeryMol);
                var entry = entities.Entry(newPrimeryMol);
                entry.Property(e => e.IsPrimary).IsModified = true;

                result.MolId     = newPrimeryMol.MolId;
                result.IsPrimery = newPrimeryMol.IsPrimary;
                result.OwnerId   = newPrimeryMol.OwnerId;
                result.Address   = newPrimeryMol.Address;
                result.Email     = newPrimeryMol.Email;
                result.FirstName = newPrimeryMol.FirstName;
                result.LastName  = newPrimeryMol.LastName;
                result.Phone     = newPrimeryMol.Phone;
                entities.SaveChanges();
            }
            return(result);
        }
示例#18
0
        public async void LoadMolList()
        {
            AllMols = await SAOwner.getAllMols(DataHolder.Owner.OwnerId);

            NonPrimeryMols.Clear();

            List <CommonMol> primeryMol = new List <CommonMol>();

            foreach (var mol in AllMols)
            {
                if (mol.IsPrimery)
                {
                    primeryMol.Add(mol);
                    PrimeryMol = mol;
                }
                else
                {
                    NonPrimeryMols.Add(mol);
                }
            }
            dgvMol.DataSource        = null;
            dgvMol.DataSource        = NonPrimeryMols;
            dgvPrimaryMol.DataSource = primeryMol;
        }
 public bool PostUpdateMol([FromBody] CommonMol mol)
 {
     return(BLOwner.UpdateMol(mol));
 }