コード例 #1
0
ファイル: CatalogProvince.aspx.cs プロジェクト: war-man/HRM
        public void DuplicateLocation()
        {
            try
            {
                if (string.IsNullOrEmpty(hdfRecordId.Text))
                {
                    return;
                }
                var location    = cat_LocationServices.GetById(Convert.ToInt32(hdfRecordId.Text));
                var newLocation = new cat_Location
                {
                    Name        = location.Name,
                    Description = location.Description,
                    Group       = location.Group,
                    ParentId    = location.ParentId
                };
                cat_LocationServices.Create(newLocation);

                GridPanel1.Reload();
            }
            catch (Exception ex)
            {
                Dialog.ShowNotification("Đã có lỗi xảy ra trong quá trình nhân đôi dữ liệu !");
            }
        }
コード例 #2
0
ファイル: AddressModel.cs プロジェクト: war-man/HRM
        /// <summary>
        /// Ctor with location object
        /// </summary>
        /// <param name="address"></param>
        /// <param name="ward"></param>
        /// <param name="district"></param>
        /// <param name="province"></param>
        public AddressModel(string address, cat_Location ward, cat_Location district, cat_Location province)
        {
            // get catalog
            ward     = ward ?? new cat_Location();
            district = district ?? new cat_Location();
            province = province ?? new cat_Location();

            // init address
            Address = GenerateAddress(address, ward.Name, district.Name, province.Name);
        }
コード例 #3
0
ファイル: CatalogProvince.aspx.cs プロジェクト: war-man/HRM
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCapNhat_Click(object sender, DirectEventArgs e)
        {
            try
            {
                var location = new cat_Location
                {
                    Description = txtNote.Text,
                    Name        = txtProvinceName.Text
                };
                if (!string.IsNullOrEmpty(hdfLocationGroupChildId.Text))
                {
                    location.Group = hdfLocationGroupChildId.Text;
                }

                location.ParentId = !string.IsNullOrEmpty(hdfProvinceParentId.Text) ? Convert.ToInt32(hdfProvinceParentId.Text) : 0;

                if (e.ExtraParams["Command"] == "Edit")
                {
                    if (!string.IsNullOrEmpty(hdfRecordId.Text))
                    {
                        location.Id = Convert.ToInt32(hdfRecordId.Text);
                        cat_LocationServices.Update(location);
                        wdAddWindow.Hide();
                    }
                }
                else
                {
                    cat_LocationServices.Create(location);
                    Dialog.ShowNotification("Thêm mới thành công");
                    if (e.ExtraParams["Close"] == "True")
                    {
                        wdAddWindow.Hide();
                    }
                }
                txtNote.Reset();
                txtProvinceName.Reset();
                cbxLocationGroup.Reset();
                cbxLocationGroupChild.Reset();
                hdfLocationGroupChildId.Reset();
                cbxLocationParent.Reset();
                hdfProvinceParentId.Reset();
                hdfLocationGroupId.Reset();
                GridPanel1.Reload();
            }
            catch (Exception ex)
            {
                Dialog.ShowError(ex.Message);
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static CatalogLocationModel Update(CatalogLocationModel model)
        {
            // get existed by name
            var existedEntity = GetUnique(model.ParentId, model.Name);

            // check existed
            if (existedEntity == null || existedEntity.Id == model.Id)
            {
                // init new entity
                var entity = new cat_Location();

                // set entity props
                model.FillEntity(ref entity);

                // return
                return(new CatalogLocationModel(cat_LocationServices.Update(entity)));
            }

            // report name existed
            return(null);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static CatalogLocationModel Create(CatalogLocationModel model)
        {
            // get existed by name
            var existedEntity = GetUnique(model.ParentId, model.Name);

            // check existed
            if (existedEntity == null)
            {
                // init entity
                var entity = new cat_Location();

                // get entity from db
                model.FillEntity(ref entity);

                // return
                return(new CatalogLocationModel(cat_LocationServices.Create(entity)));
            }

            // report name existed
            return(null);
        }
コード例 #6
0
ファイル: Default.aspx.cs プロジェクト: war-man/HRM
        protected void ImportFile(object sender, DirectEventArgs e)
        {
            try
            {
                DataTable dataTable = JSON.Deserialize <DataTable>(hdfDataTable.Text);
                // count success create
                var successRecords = new List <int>();
                foreach (DataRow row in dataTable.Rows)
                {
                    // Check employee code
                    var employeeCode = row["EmployeeCode"].ToString().Trim();
                    var idNumber     = row["IDNumber"].ToString().Trim();
                    if (!string.IsNullOrEmpty(employeeCode))
                    {
                        var recordList = RecordController.CheckExistIDNumberAndEmployeeCode(null, null, employeeCode);
                        if (recordList != null && recordList.Count > 0)
                        {
                            continue;
                        }
                    }
                    // Check id number
                    if (!string.IsNullOrEmpty(idNumber))
                    {
                        var recordList = RecordController.CheckExistIDNumberAndEmployeeCode(null, idNumber, null);
                        if (recordList != null && recordList.Count > 0)
                        {
                            continue;
                        }
                    }
                    // Create new record
                    var record = new hr_Record();
                    foreach (DataColumn col in dataTable.Columns)
                    {
                        if (string.IsNullOrEmpty(row[col].ToString()))
                        {
                            continue;
                        }
                        var condition = " [Name] LIKE N'%{0}%' ".FormatWith(row[col]);
                        var location  = new cat_Location();
                        switch (col.ColumnName)
                        {
                        case nameof(hr_Record.FullName):
                            record.FullName = row[col].ToString();
                            // lấy họ và đệm từ họ tên
                            var position = record.FullName.LastIndexOf(' ');
                            record.Name = position == -1 ? record.FullName : record.FullName.Substring(position + 1).Trim();
                            break;

                        case nameof(hr_Record.Sex):
                            record.Sex = row[col].ToString().Equals("Nam");
                            break;

                        case nameof(hr_Record.BirthPlaceWardId):
                            location = cat_LocationServices.GetByCondition(condition);
                            record.BirthPlaceWardId = location.Id;
                            break;

                        case nameof(hr_Record.BirthPlaceDistrictId):
                            location = cat_LocationServices.GetByCondition(condition);
                            record.BirthPlaceDistrictId = location.Id;
                            break;

                        case nameof(hr_Record.BirthPlaceProvinceId):
                            location = cat_LocationServices.GetByCondition(condition);
                            record.BirthPlaceProvinceId = location.Id;
                            break;

                        case nameof(hr_Record.HometownWardId):
                            location = cat_LocationServices.GetByCondition(condition);
                            record.HometownWardId = location.Id;
                            break;

                        case nameof(hr_Record.HometownDistrictId):
                            location = cat_LocationServices.GetByCondition(condition);
                            record.HometownDistrictId = location.Id;
                            break;

                        case nameof(hr_Record.HometownProvinceId):
                            location = cat_LocationServices.GetByCondition(condition);
                            record.HometownProvinceId = location.Id;
                            break;

                        default:
                            var reg     = @"\(([^)]*)\)";
                            var propVal = row[col];
                            if (Regex.IsMatch(propVal.ToString(), reg))
                            {
                                propVal = Regex.Match(propVal.ToString(), reg).Groups[1].Value;
                            }
                            //get the property information based on the type
                            var propInfo = record.GetType().GetProperty(col.ColumnName);
                            //find the property type
                            var propType = propInfo.PropertyType;
                            //equivalent to the specified object.
                            //if (propType.Name == typeof(Nullable<>).Name)
                            //{
                            //    if (Nullable.GetUnderlyingType(propType) == typeof(DateTime))
                            //    {
                            //        var result = new DateTime();
                            //        if (double.TryParse(propVal.ToString(), out var value))
                            //        {
                            //            result = DateTime.FromOADate(value);
                            //        }
                            //        propVal = Convert.ChangeType(result, typeof(DateTime));
                            //    }
                            //    else
                            //    {
                            //        propVal = Convert.ChangeType(propVal, Nullable.GetUnderlyingType(propType));
                            //    }
                            //}
                            //else
                            //{
                            //    propVal = Convert.ChangeType(propVal, propType);
                            //}
                            propVal = propType.Name == typeof(Nullable <>).Name
                                    ? Convert.ChangeType(propVal, Nullable.GetUnderlyingType(propType))
                                    : Convert.ChangeType(propVal, propType);

                            //Set the value of the property
                            propInfo.SetValue(record, propVal, null);
                            break;
                        }
                    }
                    // add record
                    hr_RecordServices.Create(record);
                    successRecords.Add(dataTable.Rows.IndexOf(row));
                }
                Dialog.Alert("Thêm thành công " + successRecords.Count + " bản ghi");
                grpImportExcel.Reload();
            }
            catch (Exception ex)
            {
                Dialog.ShowError("Đã có lỗi xảy ra: " + ex.Message);
            }
        }