protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
예제 #2
0
 public static void AddSupplierAlongWithItsLedgerToDatabase(Supplier supplier)
 {
     var context = new ERPContext();
     try
     {
         context.Suppliers.Add(supplier);
         CreateAndAddSupplierLedgerToDatabaseContext(context, supplier);
         context.SaveChanges();
     }
     catch
     {
         MessageBox.Show("The supplier's name is already being used.", "Invalid Supplier", MessageBoxButton.OK);
     }
     finally
     {
         context.Dispose();
     }
 }
예제 #3
0
        public static void AddSupplierAlongWithItsLedgerToDatabase(Supplier supplier)
        {
            var context = new ERPContext();

            try
            {
                context.Suppliers.Add(supplier);
                CreateAndAddSupplierLedgerToDatabaseContext(context, supplier);
                context.SaveChanges();
            }
            catch
            {
                MessageBox.Show("The supplier's name is already being used.", "Invalid Supplier", MessageBoxButton.OK);
            }
            finally
            {
                context.Dispose();
            }
        }
예제 #4
0
 public static void AddItemToDatabase(Item item)
 {
     var success = true;
     var context = new ERPContext();
     try
     {
         AddItemToDatabaseContext(context, item);
         context.SaveChanges();
     }
     catch
     {
         success = false;
         MessageBox.Show("The item ID is already being used.", "Invalid ID", MessageBoxButton.OK);
     }
     finally
     {
         if (success)
             MessageBox.Show("Successfully added item!", "Success", MessageBoxButton.OK);
         context.Dispose();
     }
 }
예제 #5
0
        public static void AddItemToDatabase(Item item)
        {
            var success = true;
            var context = new ERPContext();

            try
            {
                AddItemToDatabaseContext(context, item);
                context.SaveChanges();
            }
            catch
            {
                success = false;
                MessageBox.Show("The item ID is already being used.", "Invalid ID", MessageBoxButton.OK);
            }
            finally
            {
                if (success)
                {
                    MessageBox.Show("Successfully added item!", "Success", MessageBoxButton.OK);
                }
                context.Dispose();
            }
        }
예제 #6
0
 public void Dispose()
 {
     _context.Dispose();
 }
예제 #7
0
        public IHttpActionResult PostFormData()
        {
            var    httpRequest = HttpContext.Current.Request;
            string path        = "";
            string filePath    = "";


            try
            {
                if (httpRequest.Files.Count > 0)
                {
                    foreach (string file in httpRequest.Files)
                    {
                        long dataSourceId = 1;
                        var  postedFile   = httpRequest.Files[file];
                        filePath = HttpContext.Current.Server.MapPath("~/Uploads/SourceFile/" + postedFile.FileName);
                        //postedFile.SaveAs(filePath);
                        Stream stream   = postedFile.InputStream;
                        byte[] fileData = null;
                        using (var binaryReader = new BinaryReader(postedFile.InputStream))
                        {
                            fileData = binaryReader.ReadBytes(postedFile.ContentLength);
                        }
                        var strrr    = new MemoryStream(fileData);
                        var tempfile = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
                        // Get random file name without
                        using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                        {
                            // Write content of your memory stream into file stream
                            strrr.WriteTo(fs);
                        }
                    }
                }


                string check = "ATM";
                string con   =
                    (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';");


                BL bl = new BL(con);

                DataTable dtw = bl.GetTable("select * from [Sheet1$]");
                _db = new ERPContext();
                var employees = _db.Employees.ToList();


                var  payingType = dtw.Rows[1].ItemArray[1];
                bool pay        = true;
                if (payingType.Equals("3-مرتب تحويلات بنكية"))
                {
                    check = "Bank";
                    pay   = false;
                }
                foreach (DataRow row in dtw.Rows)
                {
                    //   Employee emp = (from c in employees where (c.Code == Convert.ToInt32(row[4])) select (c)).FirstOrDefault();
                    int  code      = 0;
                    bool codeparse = int.TryParse(row[4].ToString(), out code);

                    Employee emp = null;
                    if (codeparse)
                    {
                        emp = _db.Employees.FirstOrDefault(x => x.Code == code);
                    }

                    if (emp != null)

                    {
                        emp.Sallary    = pay;
                        emp.Name       = row[5].ToString();
                        emp.NationalId = row[0].ToString();
                    }
                    else
                    {
                        Employee empl = new Employee
                        {
                            NationalId = row[0].ToString(),
                            Name       = row[5].ToString(),
                            Code       = Convert.ToInt32(row[4]),
                            Sallary    = pay,
                            Other      = true
                        };



                        _db.Employees.Add(empl);
                    }
                }
                _db.SaveChanges();
                _db.Dispose();
                //if (File.Exists(HttpContext.Current.Server.MapPath("~/Uploads/SourceFile/" + check + ".xls")))
                //{
                //    File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/SourceFile/" + check + ".xls"));
                //}

                //File.Move(filePath, HttpContext.Current.Server.MapPath("~/Uploads/SourceFile/" + check + ".xls"));

                return(Ok(new { msg = "success" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }