public ContractDTO insertContract(ContractDTO contractDTO)
        {
            try
            {
                Db.Ado.BeginTran();
                CONTRACT contract = new CONTRACT()
                {
                    DELIVERY_DATE   = contractDTO._delivery_date,
                    SUPPLIER_ID     = contractDTO._supplier_id,
                    CONTRACT_STATUS = 0,
                    STAFF_ID        = contractDTO._staff_id,
                    SIGN_DATE       = DateTime.Now,
                };
                Db.Insertable(contract).IgnoreColumns(it => new { it.CONTRACT_ID }).ExecuteCommand();

                var cid = Db.Ado.SqlQuery <int>("select ISEQ$$_75593.currval from dual");
                var id  = cid[0];
                if (contractDTO._contract_items != null)
                {
                    foreach (ContractItemDTO temp in contractDTO._contract_items)
                    {
                        CONTRACT_ITEM contractItem = new CONTRACT_ITEM()
                        {
                            CONTRACT_ID     = id,
                            MEDICINE_ID     = temp._medicine_id,
                            MEDICINE_MONEY  = temp._medicine_money,
                            MEDICINE_AMOUNT = temp._medicine_amount,
                            MEDICINE_STATUS = 0,
                        };
                        Db.Insertable(contractItem).ExecuteCommand();
                    }
                }
                else
                {
                    throw new Exception();
                }
                Db.Ado.CommitTran();
                contractDTO._contract_id = id;
                return(contractDTO);
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return(null);
            }
        }
Exemplo n.º 2
0
 public SupplierDTO getSupplierByContractId(int contractId)
 {
     try
     {
         CONTRACT    contract    = Db.Queryable <CONTRACT>().InSingle(contractId);
         SUPPLIER    supplier    = Db.Queryable <SUPPLIER>().InSingle(contract.SUPPLIER_ID);
         SupplierDTO supplierDTO = new SupplierDTO();
         supplierDTO._supplier_id  = supplier.SUPPLIER_ID;
         supplierDTO._name         = supplier.NAME;
         supplierDTO._phone        = supplier.PHONE;
         supplierDTO._credit_level = supplier.CREDIT_LEVEL;
         return(supplierDTO);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="completeContractDTO"></param>
        public bool completeOneContract(CompleteContractDTO completeContractDTO)
        {
            try
            {
                Db.Ado.BeginTran();
                CONTRACT contract = Db.Queryable <CONTRACT>().InSingle(completeContractDTO._contract_id);
                contract.CONTRACT_STATUS = 2;
                Db.Updateable(contract).ExecuteCommand();

                var length = Db.Queryable <CONTRACT_ITEM>().Where((it) => it.CONTRACT_ID == completeContractDTO._contract_id)
                             .Select(it => SqlFunc.AggregateCount(it.MEDICINE_ID)).Single();
                if (length != completeContractDTO.stockInDTOs.Count)
                {
                    throw new Exception();
                }
                foreach (StockInDTO stockInDTO in completeContractDTO.stockInDTOs)
                {
                    CONTRACT_ITEM contractItem = Db.Queryable <CONTRACT_ITEM>().
                                                 Where((it) => it.MEDICINE_ID == stockInDTO._medicine_id &&
                                                       it.CONTRACT_ID == completeContractDTO._contract_id).Single();
                    if (contractItem.MEDICINE_STATUS == 2)
                    {
                        continue;
                    }
                    contractItem.MEDICINE_STATUS = 2;
                    Db.Updateable(contractItem).ExecuteCommand();

                    MEDICINE_INSTANCE medicineInstance = new MEDICINE_INSTANCE
                    {
                        MEDICINE_ID     = stockInDTO._medicine_id,
                        BATCH_ID        = stockInDTO._batch_id,
                        PRODUCTION_DATE = stockInDTO._production_date,
                        VALIDITY_DATE   = stockInDTO._validity_date,
                        PURCHASE_PRICE  = contractItem.MEDICINE_MONEY,
                        SALE_PRICE      = stockInDTO._sale_price
                    };
                    Db.Insertable(medicineInstance).ExecuteCommand();

                    MEDICINE_STOCK medicineStock = new MEDICINE_STOCK
                    {
                        MEDICINE_ID = stockInDTO._medicine_id,
                        BATCH_ID    = stockInDTO._batch_id,
                        AMOUNT      = stockInDTO._in_num
                    };

                    Db.Insertable(medicineStock).IgnoreColumns(it => new { it.STOCK_ID }).ExecuteCommand();
                    var id = Db.Ado.SqlQuery <int>("select ISEQ$$_84079.currval from dual").Single();

                    STOCK_IN stockIn = new STOCK_IN
                    {
                        STOCK_ID    = id,
                        CONTRACT_ID = completeContractDTO._contract_id,
                        IN_NUM      = stockInDTO._in_num,
                        IN_TIME     = stockInDTO._in_time
                    };

                    Db.Insertable(stockIn).ExecuteCommand();
                }

                Db.Ado.CommitTran();
                return(true);
            }
            catch (Exception e)
            {
                Db.Ado.RollbackTran();
                return(false);
            }


            //stock_in.IN_NUM=contract.
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Edit([Bind(Include = "EmployeeID,EmployeeName,Image,Sex,DoB,Birthplace,HomeTown,Nation,IdNumber,Phone,Email,City,Ward,Dictrict,Street,RoomID,PositionID,ContractID,HealthInsurance,HealthInsuranceID,DeductionPersonal,DeductionDependent,EducationName,MajorID,Date,Place,CertificateName,TypeCertificate,CertificateDate,CertificatePlace,ContractID,ContractType,DateStartWork,ContractExpirationDate,BasicSalary,Password")] EmployeeViewModel employee)
        {
            List <SelectListItem> city            = new List <SelectListItem>();
            List <SelectListItem> ward            = new List <SelectListItem>();
            List <SelectListItem> dictrict        = new List <SelectListItem>();
            List <SelectListItem> nation          = new List <SelectListItem>();
            List <SelectListItem> contractType    = new List <SelectListItem>();
            List <SelectListItem> education       = new List <SelectListItem>();
            List <SelectListItem> typecertificate = new List <SelectListItem>();
            var Directory = AppDomain.CurrentDomain.BaseDirectory;
            //path of folder
            var path     = Directory + "./File_Text/";
            var encoding = Encoding.UTF8;

            string[] lines1 = System.IO.File.ReadAllLines(path + "City.txt", encoding);
            string[] lines2 = System.IO.File.ReadAllLines(path + "Ward.txt", encoding);
            string[] lines3 = System.IO.File.ReadAllLines(path + "Dictrict.txt", encoding);
            string[] lines4 = System.IO.File.ReadAllLines(path + "Nation.txt", encoding);
            string[] lines5 = System.IO.File.ReadAllLines(path + "ContractType.txt", encoding);
            string[] lines6 = System.IO.File.ReadAllLines(path + "Education.txt", encoding);
            string[] lines7 = System.IO.File.ReadAllLines(path + "TypeCertificate.txt", encoding);
            foreach (string line in lines1)
            {
                city.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines2)
            {
                ward.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines3)
            {
                dictrict.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines4)
            {
                nation.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines5)
            {
                contractType.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines6)
            {
                education.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines7)
            {
                typecertificate.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            SelectList citylist         = new SelectList(city, "Value", "Text");
            SelectList wardlist         = new SelectList(ward, "Value", "Text");
            SelectList dictrictlist     = new SelectList(dictrict, "Value", "Text");
            SelectList nationlist       = new SelectList(nation, "Value", "Text");
            SelectList contracttypelist = new SelectList(contractType, "Value", "Text");
            SelectList educationlist    = new SelectList(education, "Value", "Text");
            SelectList certificatelist  = new SelectList(typecertificate, "Value", "Text");

            // Set vào ViewBag
            ViewBag.Birthplace      = citylist;
            ViewBag.HomeTown        = citylist;
            ViewBag.nationList      = nationlist;
            ViewBag.ContractType    = contracttypelist;
            ViewBag.City            = citylist;
            ViewBag.Ward            = wardlist;
            ViewBag.Dictrict        = dictrictlist;
            ViewBag.EducationName   = educationlist;
            ViewBag.PositionID      = new SelectList(db.POSITIONs, "PositionID", "PositionName");
            ViewBag.RoomID          = new SelectList(db.ROOMs, "RoomID", "RoomName");
            ViewBag.MajorID         = new SelectList(db.MAJORs, "MajorID", "MajorName");
            ViewBag.TypeCertificate = certificatelist;
            if (employee.ContractExpirationDate < employee.DateStartWork)
            {
                ModelState.AddModelError("ContractExpirationDate", "Ngày kết thúc phải lớn hơn ngày bắt đầu");
            }
            var Parameter = db.PARAMETERs.ToList();
            var tuoi      = DateTime.Now.Year - employee.DoB.Year;

            if (employee.Sex == "Nam")
            {
                if (tuoi < Parameter[19].Value) //tuoi toi thieu nam
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
                if (tuoi > Parameter[17].Value) //tuoi toi da nam
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
            }
            else
            {
                if (tuoi < Parameter[17].Value) //tuoi toi thieu nu
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
                if (tuoi > Parameter[18].Value) //tuoi toi da nu
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
            }
            if (ModelState.IsValid)
            {
                EMPLOYEE eMPLOYEE = new EMPLOYEE();
                eMPLOYEE.EmployeeID   = employee.EmployeeID;
                eMPLOYEE.EmployeeName = FormatProperCase(employee.EmployeeName); //Chuan hoa chuoi
                if (employee.ImageFile != null)
                {
                    employee.ImageFile.SaveAs(Server.MapPath("/images") + "/" + employee.EmployeeID + ".jpg");
                }
                eMPLOYEE.Sex                = employee.Sex;
                eMPLOYEE.DoB                = (DateTime)employee.DoB;
                eMPLOYEE.Birthplace         = employee.Birthplace;
                eMPLOYEE.HomeTown           = employee.HomeTown;
                eMPLOYEE.Nation             = employee.Nation;
                eMPLOYEE.IdNumber           = employee.IdNumber;
                eMPLOYEE.Phone              = employee.Phone;
                eMPLOYEE.Email              = employee.Email;
                eMPLOYEE.City               = employee.City;
                eMPLOYEE.Ward               = employee.Ward;
                eMPLOYEE.Dictrict           = employee.Dictrict;
                eMPLOYEE.Street             = employee.Street;
                eMPLOYEE.RoomID             = employee.RoomID;
                eMPLOYEE.PositionID         = employee.PositionID;
                eMPLOYEE.ContractID         = employee.ContractID;
                eMPLOYEE.FreeInsurance      = Convert.ToBoolean(employee.HealthInsurance);
                eMPLOYEE.HealthInsuranceID  = employee.HealthInsuranceID;
                eMPLOYEE.SelfDeduction      = Convert.ToBoolean(employee.DeductionPersonal);
                eMPLOYEE.DependentDeduction = employee.DeductionDependent;
                db.Entry(eMPLOYEE).State    = EntityState.Modified;
                //Trinh do
                EDUCATIONDETAIL eDUCATIONDETAIL = new EDUCATIONDETAIL();
                eDUCATIONDETAIL.EmployeeID    = employee.EmployeeID;
                eDUCATIONDETAIL.EducationName = employee.EducationName;
                if (eDUCATIONDETAIL.EducationName == "10" || eDUCATIONDETAIL.EducationName == "11" || eDUCATIONDETAIL.EducationName == "12")
                {
                    eDUCATIONDETAIL.MajorID = "M09";
                }
                else
                {
                    eDUCATIONDETAIL.MajorID = employee.MajorID;
                }
                eDUCATIONDETAIL.Date  = employee.Date;
                eDUCATIONDETAIL.Place = employee.Place;

                //Chung chi
                CERTIFICATEDETAIL cERTIFICATEDETAIL = new CERTIFICATEDETAIL();
                cERTIFICATEDETAIL.EmployeeID       = employee.EmployeeID;
                cERTIFICATEDETAIL.CertificateName  = employee.CertificateName;
                cERTIFICATEDETAIL.CertificateDate  = employee.CertificateDate;
                cERTIFICATEDETAIL.CertificatePlace = employee.CertificatePlace;
                cERTIFICATEDETAIL.TypeCertificate  = employee.TypeCertificate;

                //Hop dong
                CONTRACT cONTRACT = new CONTRACT();
                cONTRACT.ContractID               = employee.ContractID;
                cONTRACT.ContractType             = employee.ContractType;
                cONTRACT.DateStartWork            = (DateTime)employee.DateStartWork;
                cONTRACT.ContractExpirationDate   = (DateTime)employee.ContractExpirationDate;
                cONTRACT.BasicSalary              = employee.BasicSalary;
                db.Entry(eDUCATIONDETAIL).State   = EntityState.Modified;
                db.Entry(cERTIFICATEDETAIL).State = EntityState.Modified;
                db.Entry(cONTRACT).State          = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
Exemplo n.º 5
0
        // GET: EMPLOYEEs/Details/5
        public async Task <ActionResult> Details(string id)
        {
            Session["MainTitle"] = "Quản lý nhân sự";
            Session["SubTitle"]  = "Thông tin nhân viên";
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EMPLOYEE eMPLOYEE = await db.EMPLOYEEs.FindAsync(id);

            if (eMPLOYEE == null)
            {
                return(HttpNotFound());
            }
            EmployeeViewModel employee = new EmployeeViewModel();

            employee.EmployeeID         = eMPLOYEE.EmployeeID;
            employee.EmployeeName       = eMPLOYEE.EmployeeName;
            employee.Image              = eMPLOYEE.Image;
            employee.Sex                = eMPLOYEE.Sex;
            employee.DoB                = eMPLOYEE.DoB;
            employee.Birthplace         = eMPLOYEE.Birthplace;
            employee.HomeTown           = eMPLOYEE.HomeTown;
            employee.Nation             = eMPLOYEE.Nation;
            employee.IdNumber           = eMPLOYEE.IdNumber;
            employee.Phone              = eMPLOYEE.Phone;
            employee.Email              = eMPLOYEE.Email;
            employee.City               = eMPLOYEE.City;
            employee.Ward               = eMPLOYEE.Ward;
            employee.Dictrict           = eMPLOYEE.Dictrict;
            employee.RoomName           = eMPLOYEE.ROOM.RoomName;
            employee.PositionName       = eMPLOYEE.POSITION.PositionName;
            employee.ContractID         = eMPLOYEE.ContractID;
            employee.HealthInsurance    = eMPLOYEE.FreeInsurance;
            employee.HealthInsuranceID  = eMPLOYEE.HealthInsuranceID;
            employee.SocialInsuranceID  = eMPLOYEE.HealthInsuranceID.Substring(eMPLOYEE.HealthInsuranceID.Length - 10, 10);
            employee.DeductionPersonal  = eMPLOYEE.SelfDeduction;
            employee.DeductionDependent = (int)eMPLOYEE.DependentDeduction;
            employee.State              = (bool)eMPLOYEE.State;
            List <EDUCATIONDETAIL> eDUCATIONDETAIL = db.EDUCATIONDETAILs.SqlQuery("Select * from EDUCATIONDETAIL where employeeID = '" + id + "'").ToList();
            CONTRACT cONTRACT = await db.CONTRACTs.FindAsync(eMPLOYEE.ContractID);

            List <CERTIFICATEDETAIL> cERTIFICATEDETAIL = db.CERTIFICATEDETAILs.SqlQuery("Select * from CERTIFICATEDETAIL where employeeID = '" + id + "'").ToList();

            //Trinh do
            employee.EducationName = eDUCATIONDETAIL[0].EducationName;
            employee.MajorName     = eDUCATIONDETAIL[0].MAJOR.MajorName;
            employee.Date          = eDUCATIONDETAIL[0].Date;
            employee.Place         = eDUCATIONDETAIL[0].Place;
            //Chung chi
            employee.CertificateName  = cERTIFICATEDETAIL[0].CertificateName;
            employee.TypeCertificate  = cERTIFICATEDETAIL[0].TypeCertificate;
            employee.CertificateDate  = cERTIFICATEDETAIL[0].CertificateDate;
            employee.CertificatePlace = cERTIFICATEDETAIL[0].CertificatePlace;
            //Hop dong
            employee.ContractID             = cONTRACT.ContractID;
            employee.ContractType           = cONTRACT.ContractType;
            employee.DateStartWork          = cONTRACT.DateStartWork;
            employee.ContractExpirationDate = cONTRACT.ContractExpirationDate;
            employee.BasicSalary            = (int)cONTRACT.BasicSalary;
            return(View(employee));
        }
Exemplo n.º 6
0
        // GET: EMPLOYEEs/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EMPLOYEE eMPLOYEE = await db.EMPLOYEEs.FindAsync(id);

            if (eMPLOYEE == null)
            {
                return(HttpNotFound());
            }
            EmployeeViewModel     employee        = new EmployeeViewModel();
            List <SelectListItem> city            = new List <SelectListItem>();
            List <SelectListItem> ward            = new List <SelectListItem>();
            List <SelectListItem> dictrict        = new List <SelectListItem>();
            List <SelectListItem> nation          = new List <SelectListItem>();
            List <SelectListItem> contractType    = new List <SelectListItem>();
            List <SelectListItem> education       = new List <SelectListItem>();
            List <SelectListItem> typecertificate = new List <SelectListItem>();
            var Directory = AppDomain.CurrentDomain.BaseDirectory;
            //path of folder
            var path     = Directory + "./File_Text/";
            var encoding = Encoding.UTF8;

            string[] lines1 = System.IO.File.ReadAllLines(path + "City.txt", encoding);
            string[] lines2 = System.IO.File.ReadAllLines(path + "Ward.txt", encoding);
            string[] lines3 = System.IO.File.ReadAllLines(path + "Dictrict.txt", encoding);
            string[] lines4 = System.IO.File.ReadAllLines(path + "Nation.txt", encoding);
            string[] lines5 = System.IO.File.ReadAllLines(path + "ContractType.txt", encoding);
            string[] lines6 = System.IO.File.ReadAllLines(path + "Education.txt", encoding);
            string[] lines7 = System.IO.File.ReadAllLines(path + "TypeCertificate.txt", encoding);
            foreach (string line in lines1)
            {
                city.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines2)
            {
                ward.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines3)
            {
                dictrict.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines4)
            {
                nation.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines5)
            {
                contractType.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines6)
            {
                education.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines7)
            {
                typecertificate.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            SelectList citylist         = new SelectList(city, "Value", "Text");
            SelectList wardlist         = new SelectList(ward, "Value", "Text");
            SelectList dictrictlist     = new SelectList(dictrict, "Value", "Text");
            SelectList nationlist       = new SelectList(nation, "Value", "Text");
            SelectList contracttypelist = new SelectList(contractType, "Value", "Text");
            SelectList educationlist    = new SelectList(education, "Value", "Text");
            SelectList certificatelist  = new SelectList(typecertificate, "Value", "Text");

            // Set vào ViewBag
            ViewBag.Birthplace      = citylist;
            ViewBag.HomeTown        = citylist;
            ViewBag.nationList      = nationlist;
            ViewBag.ContractType    = contracttypelist;
            ViewBag.City            = citylist;
            ViewBag.Ward            = wardlist;
            ViewBag.Dictrict        = dictrictlist;
            ViewBag.EducationName   = educationlist;
            ViewBag.PositionID      = new SelectList(db.POSITIONs, "PositionID", "PositionName");
            ViewBag.RoomID          = new SelectList(db.ROOMs, "RoomID", "RoomName");
            ViewBag.MajorID         = new SelectList(db.MAJORs, "MajorID", "MajorName");
            ViewBag.TypeCertificate = certificatelist;

            employee.EmployeeID         = eMPLOYEE.EmployeeID;
            employee.EmployeeName       = eMPLOYEE.EmployeeName;
            employee.Image              = eMPLOYEE.Image;
            employee.Sex                = eMPLOYEE.Sex;
            employee.DoB                = eMPLOYEE.DoB;
            employee.Birthplace         = eMPLOYEE.Birthplace;
            employee.HomeTown           = eMPLOYEE.HomeTown;
            employee.Nation             = eMPLOYEE.Nation;
            employee.IdNumber           = eMPLOYEE.IdNumber;
            employee.Phone              = eMPLOYEE.Phone;
            employee.Email              = eMPLOYEE.Email;
            employee.City               = eMPLOYEE.City;
            employee.Ward               = eMPLOYEE.Ward;
            employee.Dictrict           = eMPLOYEE.Dictrict;
            employee.Street             = eMPLOYEE.Street;
            employee.RoomID             = eMPLOYEE.RoomID;
            employee.PositionID         = eMPLOYEE.PositionID;
            employee.ContractID         = eMPLOYEE.ContractID;
            employee.HealthInsurance    = eMPLOYEE.FreeInsurance;
            employee.HealthInsuranceID  = eMPLOYEE.HealthInsuranceID;
            employee.DeductionPersonal  = eMPLOYEE.SelfDeduction;
            employee.DeductionDependent = (int)eMPLOYEE.DependentDeduction;
            List <EDUCATIONDETAIL> eDUCATIONDETAIL = db.EDUCATIONDETAILs.SqlQuery("Select * from EDUCATIONDETAIL where employeeID = '" + id + "'").ToList();
            CONTRACT cONTRACT = await db.CONTRACTs.FindAsync(eMPLOYEE.ContractID);

            List <CERTIFICATEDETAIL> cERTIFICATEDETAIL = db.CERTIFICATEDETAILs.SqlQuery("Select * from CERTIFICATEDETAIL where employeeID = '" + id + "'").ToList();
            USER uSER = await db.USERS.FindAsync(id);

            //Trinh do
            employee.EducationName = eDUCATIONDETAIL[0].EducationName;
            employee.MajorID       = eDUCATIONDETAIL[0].MajorID;
            employee.Date          = eDUCATIONDETAIL[0].Date;
            employee.Place         = eDUCATIONDETAIL[0].Place;
            //Chung chi
            employee.CertificateName  = cERTIFICATEDETAIL[0].CertificateName;
            employee.TypeCertificate  = cERTIFICATEDETAIL[0].TypeCertificate;
            employee.CertificateDate  = cERTIFICATEDETAIL[0].CertificateDate;
            employee.CertificatePlace = cERTIFICATEDETAIL[0].CertificatePlace;
            //Hop dong
            employee.ContractID             = cONTRACT.ContractID;
            employee.ContractType           = cONTRACT.ContractType;
            employee.DateStartWork          = cONTRACT.DateStartWork;
            employee.ContractExpirationDate = cONTRACT.ContractExpirationDate;
            employee.BasicSalary            = cONTRACT.BasicSalary;
            //Tai khoan
            employee.Password = uSER.Password;
            return(View(employee));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Create([Bind(Include = "EmployeeName,ImageFile,Sex,DoB,Birthplace,HomeTown,Nation,IdNumber,Phone,Email,City,Ward,Dictrict,Street,RoomID,PositionID,ContractID,HealthInsurance,HealthInsuranceID,DeductionPersonal,DeductionDependent,EducationName,MajorID,Date,Place,CertificateName,TypeCertificate,CertificateDate,CertificatePlace,ContractID,ContractType,DateStartWork,ContractExpirationDate,BasicSalary,Password")] EmployeeViewModel employee)
        {
            //Tao ID nhan vien tu dong
            var    emloyeeList = db.EMPLOYEEs.SqlQuery("Select * from EMPLOYEE").ToList();
            int    n           = 0;
            string id;
            bool   flag;

            do
            {
                n++;
                flag = false;
                String formatted = String.Format("{0:000000}", n);
                id = "NV" + formatted;
                foreach (var i in emloyeeList)
                {
                    if (i.EmployeeID == id)
                    {
                        flag = true;
                        break;
                    }
                }
            }while (flag == true);
            List <SelectListItem> city            = new List <SelectListItem>();
            List <SelectListItem> ward            = new List <SelectListItem>();
            List <SelectListItem> dictrict        = new List <SelectListItem>();
            List <SelectListItem> nation          = new List <SelectListItem>();
            List <SelectListItem> contractType    = new List <SelectListItem>();
            List <SelectListItem> education       = new List <SelectListItem>();
            List <SelectListItem> typecertificate = new List <SelectListItem>();
            var Directory = AppDomain.CurrentDomain.BaseDirectory;
            //path of folder
            var path     = Directory + "./File_Text/";
            var encoding = Encoding.UTF8;

            string[] lines1 = System.IO.File.ReadAllLines(path + "City.txt", encoding);
            string[] lines2 = System.IO.File.ReadAllLines(path + "Ward.txt", encoding);
            string[] lines3 = System.IO.File.ReadAllLines(path + "Dictrict.txt", encoding);
            string[] lines4 = System.IO.File.ReadAllLines(path + "Nation.txt", encoding);
            string[] lines5 = System.IO.File.ReadAllLines(path + "ContractType.txt", encoding);
            string[] lines6 = System.IO.File.ReadAllLines(path + "Education.txt", encoding);
            string[] lines7 = System.IO.File.ReadAllLines(path + "TypeCertificate.txt", encoding);
            foreach (string line in lines1)
            {
                city.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines2)
            {
                ward.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines3)
            {
                dictrict.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines4)
            {
                nation.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines5)
            {
                contractType.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines6)
            {
                education.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            foreach (string line in lines7)
            {
                typecertificate.Add(new SelectListItem()
                {
                    Text  = line,
                    Value = line
                });
            }
            SelectList citylist         = new SelectList(city, "Value", "Text");
            SelectList wardlist         = new SelectList(ward, "Value", "Text");
            SelectList dictrictlist     = new SelectList(dictrict, "Value", "Text");
            SelectList nationlist       = new SelectList(nation, "Value", "Text");
            SelectList contracttypelist = new SelectList(contractType, "Value", "Text");
            SelectList educationlist    = new SelectList(education, "Value", "Text");
            SelectList certificatelist  = new SelectList(typecertificate, "Value", "Text");

            // Set vào ViewBag
            ViewBag.Birthplace      = citylist;
            ViewBag.HomeTown        = citylist;
            ViewBag.nationList      = nationlist;
            ViewBag.ContractType    = contracttypelist;
            ViewBag.City            = citylist;
            ViewBag.Ward            = wardlist;
            ViewBag.Dictrict        = dictrictlist;
            ViewBag.EducationName   = educationlist;
            ViewBag.PositionID      = new SelectList(db.POSITIONs, "PositionID", "PositionName");
            ViewBag.RoomID          = new SelectList(db.ROOMs, "RoomID", "RoomName");
            ViewBag.MajorID         = new SelectList(db.MAJORs, "MajorID", "MajorName");
            ViewBag.TypeCertificate = certificatelist;
            ViewBag.EmployeeID      = id;
            if (employee.ContractExpirationDate < employee.DateStartWork)
            {
                ModelState.AddModelError("ContractExpirationDate", "Ngày kết thúc phải lớn hơn ngày bắt đầu");
            }
            var Parameter = db.PARAMETERs.ToList();
            var tuoi      = DateTime.Now.Year - employee.DoB.Year;

            if (employee.Sex == "Nam")
            {
                if (tuoi < Parameter[19].Value) //tuoi toi thieu nam
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
                if (tuoi > Parameter[17].Value) //tuoi toi da nam
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
            }
            else
            {
                if (tuoi < Parameter[17].Value) //tuoi toi thieu nu
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
                if (tuoi > Parameter[18].Value) //tuoi toi da nu
                {
                    ModelState.AddModelError("DoB", "Tuổi không hợp lệ");
                }
            }
            if (ModelState.IsValid)
            {
                EMPLOYEE eMPLOYEE = new EMPLOYEE();
                eMPLOYEE.EmployeeID   = id;
                eMPLOYEE.EmployeeName = FormatProperCase(employee.EmployeeName); //Chuan hoa chuoi
                if (employee.ImageFile != null)
                {
                    BinaryReader b       = new BinaryReader(employee.ImageFile.InputStream);
                    byte[]       binData = b.ReadBytes(employee.ImageFile.ContentLength);
                    eMPLOYEE.Image = binData;
                }
                eMPLOYEE.Sex                = employee.Sex;
                eMPLOYEE.DoB                = (DateTime)employee.DoB;
                eMPLOYEE.Birthplace         = employee.Birthplace;
                eMPLOYEE.HomeTown           = employee.HomeTown;
                eMPLOYEE.Nation             = employee.Nation;
                eMPLOYEE.IdNumber           = employee.IdNumber;
                eMPLOYEE.Phone              = employee.Phone;
                eMPLOYEE.Email              = employee.Email;
                eMPLOYEE.City               = employee.City;
                eMPLOYEE.Ward               = employee.Ward;
                eMPLOYEE.Street             = employee.Street;
                eMPLOYEE.Dictrict           = employee.Dictrict;
                eMPLOYEE.RoomID             = employee.RoomID;
                eMPLOYEE.PositionID         = employee.PositionID;
                eMPLOYEE.ContractID         = employee.ContractID;
                eMPLOYEE.FreeInsurance      = Convert.ToBoolean(employee.HealthInsurance);
                eMPLOYEE.HealthInsuranceID  = employee.HealthInsuranceID;
                eMPLOYEE.SelfDeduction      = Convert.ToBoolean(employee.DeductionPersonal);
                eMPLOYEE.DependentDeduction = employee.DeductionDependent;
                eMPLOYEE.State              = true;
                //Trinh do
                EDUCATIONDETAIL eDUCATIONDETAIL = new EDUCATIONDETAIL();
                eDUCATIONDETAIL.EmployeeID    = id;
                eDUCATIONDETAIL.EducationName = employee.EducationName;
                if (eDUCATIONDETAIL.EducationName == "10" || eDUCATIONDETAIL.EducationName == "11" || eDUCATIONDETAIL.EducationName == "12")
                {
                    eDUCATIONDETAIL.MajorID = "M09";
                }
                else
                {
                    eDUCATIONDETAIL.MajorID = employee.MajorID;
                }
                eDUCATIONDETAIL.Date  = employee.Date;
                eDUCATIONDETAIL.Place = employee.Place;
                db.EDUCATIONDETAILs.Add(eDUCATIONDETAIL);
                //Chung chi
                CERTIFICATEDETAIL cERTIFICATEDETAIL = new CERTIFICATEDETAIL();
                cERTIFICATEDETAIL.EmployeeID       = id;
                cERTIFICATEDETAIL.CertificateName  = employee.CertificateName;
                cERTIFICATEDETAIL.CertificateDate  = employee.CertificateDate;
                cERTIFICATEDETAIL.CertificatePlace = employee.CertificatePlace;
                cERTIFICATEDETAIL.TypeCertificate  = employee.TypeCertificate;
                db.CERTIFICATEDETAILs.Add(cERTIFICATEDETAIL);
                //Hop dong
                CONTRACT cONTRACT = new CONTRACT();
                cONTRACT.ContractID             = employee.ContractID;
                cONTRACT.ContractType           = employee.ContractType;
                cONTRACT.DateStartWork          = (DateTime)employee.DateStartWork;
                cONTRACT.ContractExpirationDate = (DateTime)employee.ContractExpirationDate;
                cONTRACT.BasicSalary            = employee.BasicSalary;
                //Tai khoan
                USER uSER = new USER();
                uSER.EmployeeID = id;
                uSER.Password   = employee.Password;
                db.CONTRACTs.Add(cONTRACT);
                db.EMPLOYEEs.Add(eMPLOYEE);
                db.USERS.Add(uSER);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }