Exemplo n.º 1
0
        public ModelLibrary.Item CreateItem(ModelLibrary.Item item, int menuId, int itemCatId)
        {
            var itemDb = new ItemDb();
            var dbItem = new DatabaseAccessLibrary.Item
            {
                name        = item.Name,
                menuId      = menuId,
                description = item.Description,
                itemCatId   = itemCatId,
            };
            var modelItem = new ModelLibrary.Item
            {
                Name        = item.Name,
                Description = item.Description,
            };

            var context           = new ValidationContext(item, null, null);
            var result            = new List <ValidationResult>();
            var isModelStateValid = Validator.TryValidateObject(item, context, result, true);

            if (!isModelStateValid)
            {
                throw new ValidationException();
            }

            itemDb.AddItem(dbItem);

            return(modelItem);
        }
Exemplo n.º 2
0
        private async void BtnLoadItem_ClickAsync(object sender, EventArgs e)
        {
            var          progressDialog = ProgressDialog.Show(this, "", "Updating Item Master...", true);
            StreamReader sr             = null;

            try
            {
                string folderPath = Path.Combine(clsGlobal.FilePath, clsGlobal.FileFolder);
                string filename   = Path.Combine(folderPath, clsGlobal.ItemFileName);

                if (File.Exists(filename))
                {
                    //Before upload new file remove all data
                    itemDb.DeleteItems();
                    sr = new StreamReader(filename);
                    //skip the header
                    sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        string Data = await sr.ReadLineAsync();

                        string[] Arr = Data.Split(',');
                        itemDb.AddItem(new Item
                        {
                            BranchCode   = Arr[0].Trim(),
                            City         = Arr[1].Trim(),
                            State        = Arr[2].Trim(),
                            Group        = Arr[3].Trim(),
                            ItemSubGroup = Arr[4].Trim(),
                            ItemName     = Arr[5].Trim(),
                            Color        = Arr[6].Trim(),
                            IMEI1        = Arr[7].Trim(),
                            IMEStock     = Arr[8].Trim(),
                            BranchName   = Arr[9].Trim(),
                            WHName       = Arr[10].Trim()
                        });
                    }

                    sr.Close();
                    sr.Dispose();
                    sr = null;

                    ShowItemCount();
                }
                else
                {
                    clsGLB.ShowMessage("Item master file not found", this, MessageTitle.INFORMATION);
                }
            }
            catch (Exception ex)
            { throw ex; }
            finally
            {
                progressDialog.Hide();
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                    sr = null;
                }
            }
        }