コード例 #1
0
        public IHttpActionResult DeleteEmpInfo(int Id)
        {
            var found  = _db.DailyFileDetailses.Include("DailyFile").Where(x => x.Id == Id).FirstOrDefault();
            var code   = _db.Employees.Find(found.EmployeeId).Code;
            var empnum = _db.DailyFileDetailses.Count(x => x.DailyFileId == found.DailyFileId);

            if (found != null)
            {
                try
                {
                    string path = found.DailyFile.FilePath;
                    string con  =
                        (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path +
                         ";Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';");



                    BL bl = new BL(con);
                    bl.update(String.Format("update [Sheet1$] set[{1}] =[{1}]-" + found.Net.ToString() + " where  [{0}] = '" + code.ToString() + "'",
                                            "رقم الموظف بجهته الأصلية", "المرتب"));


                    found.DailyFile.FileTotalAmount -= found.Net;
                    found.DailyFile.EmployeesNumber  = empnum - 1;

                    _db.DailyFileDetailses.Remove(found);
                    _db.SaveChanges();


                    return(Ok());
                }
                catch (Exception ex)
                {
                    throw  new Exception(ex.Message);
                    return(Conflict());
                }
            }
            return(Conflict());
        }
コード例 #2
0
        public IHttpActionResult UpdateEmpInfo(int DailyFileId, int EmployeeId, decimal Net)
        {
            var dailyfile = _db.DailyFiles.Find(DailyFileId);
            var empnum    = _db.DailyFileDetailses.Count(x => x.DailyFileId == DailyFileId);

            if (dailyfile != null)
            {
                dailyfile.DailyFileDetailses = new List <DailyFileDetails>()
                {
                    new DailyFileDetails()
                    {
                        DailyFileId = DailyFileId,
                        EmployeeId  = EmployeeId,
                        Net         = Net
                    }
                };
                dailyfile.FileTotalAmount += Net;
                dailyfile.EmployeesNumber  = empnum + 1;

                _db.SaveChanges();

                var root = HttpContext.Current.Server.MapPath("~/Uploads/SourceFile/ATM.xls");

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


                string con2 = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dailyfile.FilePath +
                               ";Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';");
                //string con2 =
                //  رقم الموظف بجهته الأصلية
                //string con2 = (@"provider=microsoft.ace.oledb.12.0;data source=c:\file\bank.xls;extended properties='excel 12.0 xml; hdr = yes; imex = 1';");
                var code = _db.Employees.Find(EmployeeId).Code;
                BL  bl   = new BL(con1);

                DataTable dtw = bl.GetTable(String.Format("select * from [Sheet1$] where [{0}] = '" + code.ToString() + "'", "رقم الموظف بجهته الأصلية"));
                BL        bl2 = new BL(con2);

                DataTable dtw2 = bl2.GetTable(String.Format("select * from [Sheet1$] where [{0}] = '" + code.ToString() + "'", "رقم الموظف بجهته الأصلية"));

                if (dtw2.Rows.Count == 0)
                {
                    bl2.Insert(String.Format("insert into [Sheet1$] values ('{0}','{1}','{2}','{3}','{4}','{5}',{6})"
                                             , dtw.Rows[0].ItemArray[0]
                                             , dtw.Rows[0].ItemArray[1]
                                             , dtw.Rows[0].ItemArray[2]
                                             , dtw.Rows[0].ItemArray[3]
                                             , dtw.Rows[0].ItemArray[4]
                                             , dtw.Rows[0].ItemArray[5]
                                             , Net
                                             ));
                }
                else
                {
                    bl2.update(String.Format("update [Sheet1$] set[{1}] =[{1}]+" + Net + " where  [{0}] = '" + code.ToString() + "'",
                                             "رقم الموظف بجهته الأصلية", "المرتب"));
                }
                ///		49	23706.61--145     73,984.58
                //if (EmpInfo != null)
                //{
                //    _db = new ERPContext();
                //    var model = _db.DailyFileDetailses.Find(EmpInfo.Id);
                //    model.Net = EmpInfo.Net;
                //    _db.SaveChanges();

                //}
                return(Ok());
            }
            return(BadRequest("Wrong Request"));
        }
コード例 #3
0
        public IHttpActionResult UpdateEmpInfo(int DailyFileId, int EmployeeId, decimal Net)
        {

            var dailyfile = _db.DailyFiles.Find(DailyFileId);
            var empnum = _db.DailyFileDetailses.Count(x => x.DailyFileId == DailyFileId);

            if (dailyfile != null)
            {
                dailyfile.DailyFileDetailses = new List<DailyFileDetails>()
                {
                    new DailyFileDetails()
                    {
                        DailyFileId = DailyFileId,
                        EmployeeId = EmployeeId,
                        Net = Net
                    }
                };
                dailyfile.FileTotalAmount += Net;
                dailyfile.EmployeesNumber = empnum + 1;

                _db.SaveChanges();

                var root = HttpContext.Current.Server.MapPath("~/Uploads/SourceFile/ATM.xls");

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


                string con2 = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dailyfile.FilePath +
    ";Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';");
                //string con2 =
                //  رقم الموظف بجهته الأصلية
                //string con2 = (@"provider=microsoft.ace.oledb.12.0;data source=c:\file\bank.xls;extended properties='excel 12.0 xml; hdr = yes; imex = 1';");
                var code = _db.Employees.Find(EmployeeId).Code;
                BL bl = new BL(con1);

                DataTable dtw = bl.GetTable(String.Format("select * from [Sheet1$] where [{0}] = '" +code.ToString()+"'", "رقم الموظف بجهته الأصلية"));
                BL bl2 = new BL(con2);

              DataTable dtw2=  bl2.GetTable(String.Format("select * from [Sheet1$] where [{0}] = '" + code.ToString() + "'", "رقم الموظف بجهته الأصلية"));

                if(dtw2.Rows.Count==0)
                { 
                bl2.Insert(String.Format("insert into [Sheet1$] values ('{0}','{1}','{2}','{3}','{4}','{5}',{6})"
                    , dtw.Rows[0].ItemArray[0]
                    , dtw.Rows[0].ItemArray[1]
                    , dtw.Rows[0].ItemArray[2]
                    , dtw.Rows[0].ItemArray[3]
                    , dtw.Rows[0].ItemArray[4]
                    , dtw.Rows[0].ItemArray[5]
                    ,Net
                    ));
                }
                else
                {
                    bl2.update(String.Format("update [Sheet1$] set[{1}] =[{1}]+" + Net + " where  [{0}] = '" + code.ToString() + "'",
                        "رقم الموظف بجهته الأصلية", "المرتب"));
                }
                ///		49	23706.61--145     73,984.58
                //if (EmpInfo != null)
                //{
                //    _db = new ERPContext();
                //    var model = _db.DailyFileDetailses.Find(EmpInfo.Id);
                //    model.Net = EmpInfo.Net;
                //    _db.SaveChanges();

                //}
                return Ok();
            }
            return BadRequest("Wrong Request");
        }
コード例 #4
0
        public IHttpActionResult DeleteEmpInfo(int Id)
        {
            var found = _db.DailyFileDetailses.Include("DailyFile").Where(x => x.Id == Id).FirstOrDefault();
            var code = _db.Employees.Find(found.EmployeeId).Code;
            var empnum = _db.DailyFileDetailses.Count(x => x.DailyFileId == found.DailyFileId);
            if (found != null)
            {
                try
                {
                    string path = found.DailyFile.FilePath;
                    string con =
               (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path +
                ";Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';");



                    BL bl = new BL(con);
                    bl.update(String.Format("update [Sheet1$] set[{1}] =[{1}]-"+found.Net.ToString()+" where  [{0}] = '" + code.ToString()+"'",
                        "رقم الموظف بجهته الأصلية", "المرتب"));


                    found.DailyFile.FileTotalAmount -= found.Net;
                    found.DailyFile.EmployeesNumber = empnum - 1;
                   
                    _db.DailyFileDetailses.Remove(found);
                    _db.SaveChanges();

                    
                    return Ok();
                }
                catch (Exception ex)
                {
                    throw  new Exception(ex.Message);
                    return Conflict();
                }

            }
            return Conflict();
        }