コード例 #1
0
        public static ComboBoxProperties InitColumnLookupEdit(ComboBoxProperties cboProperty, STGridColumnsInfo objGridColumnInfo)
        {
            string sTGridColumnRepository = objGridColumnInfo.STGridColumnRepository;

            if (string.IsNullOrEmpty(sTGridColumnRepository))
            {
                //GMCDbUtil.GetPrimaryTableWhichForeignColumnReferenceTo(objGridColumnInfo.STGridColumnTableName, objGridColumnInfo.STGridColumnName);
            }
            string lookupQueryColumn = GetLookupQueryColumn(objGridColumnInfo);

            TryToInitLookupTable(sTGridColumnRepository, lookupQueryColumn);
            if (!GMCWebApp.LookupTables.ContainsKey(sTGridColumnRepository))
            {
                return(null);
            }
            DataView dvLookupTable       = new DataView();
            string   strPrimaryRepostory = GMCDbUtil.GetTablePrimaryColumn(sTGridColumnRepository);

            if (GMCDbUtil.IsForeignKey(sTGridColumnRepository, objGridColumnInfo.STGridColumnRepoDsplMem))
            {
                string primaryTableWhichForeignColumnReferenceTo = GMCDbUtil.GetPrimaryTableWhichForeignColumnReferenceTo(sTGridColumnRepository, objGridColumnInfo.STGridColumnRepoDsplMem);
                if (!string.IsNullOrEmpty(primaryTableWhichForeignColumnReferenceTo))
                {
                    string str7 = GMCWebApp.GetLookupQueryColumn(primaryTableWhichForeignColumnReferenceTo);
                    if (string.IsNullOrEmpty(str7))
                    {
                        str7 = "*";
                    }
                    else
                    {
                        str7 = str7.Replace(",", ",b.");
                    }
                    string  strQuery = string.Format("SELECT a.{0},b.{5}\r\n                        FROM {1} a\r\n                        INNER JOIN {2} b ON a.{3} = b.{4}", new object[] { strPrimaryRepostory, sTGridColumnRepository, primaryTableWhichForeignColumnReferenceTo, objGridColumnInfo.STGridColumnRepoDsplMem, GMCDbUtil.GetTablePrimaryColumn(primaryTableWhichForeignColumnReferenceTo), str7 });
                    DataSet dataSet  = BusinessControllerFactory.GetBusinessController(sTGridColumnRepository + "Controller").GetDataSet(strQuery);
                    if ((dataSet != null) && (dataSet.Tables.Count > 0))
                    {
                        string strLookupTableName = sTGridColumnRepository + "_" + primaryTableWhichForeignColumnReferenceTo;
                        dvLookupTable = dataSet.Tables[0].DefaultView;
                        if (!GMCWebApp.LookupTables.ContainsKey(strLookupTableName))
                        {
                            GMCWebApp.LookupTables.Add(strLookupTableName, dataSet.Tables[0]);
                        }
                        else
                        {
                            GMCWebApp.LookupTables[strLookupTableName] = dataSet.Tables[0];
                        }
                    }
                }
            }
            else
            {
                dvLookupTable = GMCWebApp.LookupTables[sTGridColumnRepository].DefaultView;
            }
            string sTGridColumnRepoDsplMem = objGridColumnInfo.STGridColumnRepoDsplMem;

            if (!dvLookupTable.Table.Columns.Contains(sTGridColumnRepoDsplMem))
            {
                sTGridColumnRepoDsplMem = "";
            }
            if (string.IsNullOrEmpty(sTGridColumnRepoDsplMem))
            {
                sTGridColumnRepoDsplMem = strPrimaryRepostory.Substring(0, strPrimaryRepostory.Length - 2) + "No";
            }
            if (GMCDbUtil.IsForeignKey(sTGridColumnRepository, objGridColumnInfo.STGridColumnRepoDsplMem))
            {
                string str13 = GMCDbUtil.GetPrimaryTableWhichForeignColumnReferenceTo(sTGridColumnRepository, objGridColumnInfo.STGridColumnRepoDsplMem);
                if (string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoCol1))
                {
                    sTGridColumnRepoDsplMem = str13.Substring(0, str13.Length - 1) + "No";
                }
                else
                {
                    sTGridColumnRepoDsplMem = objGridColumnInfo.STGridColumnRepoCol1;
                }
            }
            if (cboProperty == null)
            {
                cboProperty = new ComboBoxProperties();
            }
            DataTable dtLookupTable = dvLookupTable.ToTable(false, strPrimaryRepostory, sTGridColumnRepoDsplMem);

            cboProperty.DataSource    = dtLookupTable.DefaultView;
            cboProperty.TextField     = sTGridColumnRepoDsplMem;
            cboProperty.ValueField    = strPrimaryRepostory;
            cboProperty.ValueType     = GMCDbUtil.GetCSharpVariableType(objGridColumnInfo.STGridColumnTableName, objGridColumnInfo.STGridColumnName);
            cboProperty.DropDownStyle = DropDownStyle.DropDownList;
            if (string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoCol1))
            {
                ListBoxColumn column = new ListBoxColumn(sTGridColumnRepoDsplMem);
                if (sTGridColumnRepoDsplMem.EndsWith("No"))
                {
                    column.Caption = "Mã số";
                    column.Width   = 50;
                }
                else if (sTGridColumnRepoDsplMem.EndsWith("Name"))
                {
                    column.Caption = "Tên";
                    column.Width   = 200;
                }
                cboProperty.Columns.AddColumn(dtLookupTable, column);
                if (!GMCDbUtil.IsForeignKey(sTGridColumnRepository, objGridColumnInfo.STGridColumnRepoDsplMem))
                {
                    ListBoxColumn column1 = new ListBoxColumn();
                    if (sTGridColumnRepoDsplMem.EndsWith("No"))
                    {
                        column1.FieldName = sTGridColumnRepoDsplMem.Substring(0, sTGridColumnRepoDsplMem.Length - 2) + "Name";
                        column1.Caption   = GMCWebApp.GetControlText("Tên");
                        column1.Width     = 200;
                    }
                    else if (sTGridColumnRepoDsplMem.EndsWith("Name"))
                    {
                        column1.FieldName = sTGridColumnRepoDsplMem.Substring(0, sTGridColumnRepoDsplMem.Length - 4) + "No";
                        column1.Caption   = GMCWebApp.GetControlText("Mã số");
                        column1.Width     = 50;
                    }
                    cboProperty.Columns.AddColumn(dtLookupTable, column1);
                }
            }
            else
            {
                ListBoxColumn info6 = new ListBoxColumn
                {
                    FieldName = objGridColumnInfo.STGridColumnRepoCol1,
                    Caption   = GMCWebApp.GetControlText(objGridColumnInfo.STGridColumnRepoCol1Caption),
                    Width     = 100
                };
                cboProperty.Columns.AddColumn(dtLookupTable, info6);
                if (!string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoCol2))
                {
                    ListBoxColumn info7 = new ListBoxColumn
                    {
                        FieldName = objGridColumnInfo.STGridColumnRepoCol2,
                        Caption   = GMCWebApp.GetControlText(objGridColumnInfo.STGridColumnRepoCol2Caption),
                        Width     = 100,
                    };
                    cboProperty.Columns.AddColumn(dtLookupTable, info7);
                }
                if (!string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoCol3))
                {
                    ListBoxColumn info8 = new ListBoxColumn
                    {
                        FieldName = objGridColumnInfo.STGridColumnRepoCol3,
                        Caption   = GMCWebApp.GetControlText(objGridColumnInfo.STGridColumnRepoCol3Caption),
                        Width     = 100
                    };
                    cboProperty.Columns.AddColumn(dtLookupTable, info8);
                }
                if (!string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoCol4))
                {
                    ListBoxColumn info9 = new ListBoxColumn
                    {
                        FieldName = objGridColumnInfo.STGridColumnRepoCol4,
                        Caption   = GMCWebApp.GetControlText(objGridColumnInfo.STGridColumnRepoCol4Caption),
                        Width     = 100
                    };
                    cboProperty.Columns.AddColumn(dtLookupTable, info9);
                }
                if (!string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoCol5))
                {
                    ListBoxColumn info10 = new ListBoxColumn
                    {
                        FieldName = objGridColumnInfo.STGridColumnRepoCol5,
                        Caption   = GMCWebApp.GetControlText(objGridColumnInfo.STGridColumnRepoCol5Caption),
                        Width     = 100
                    };
                    cboProperty.Columns.AddColumn(dtLookupTable, info10);
                }
            }
            if (!string.IsNullOrEmpty(objGridColumnInfo.STGridColumnRepoDsplMem))
            {
                int idx = cboProperty.Columns.Cast <ListBoxColumn>().ToList().FindIndex(x => x.FieldName.Equals(objGridColumnInfo.STGridColumnRepoDsplMem));
                if (idx != -1)
                {
                    cboProperty.TextFormatString = "{" + idx.ToString() + "}";
                }
            }
            return(cboProperty);
        }
コード例 #2
0
        public ActionResult RegisterOffWork(string oEmplOffWork)
        {
            string[] arr = oEmplOffWork.Split('&');
            HREmployeeOffWorksInfo       objEmplOffWork      = new HREmployeeOffWorksInfo();
            HREmployeeOffWorksController EmployeeOffWorkCtrl = new HREmployeeOffWorksController();

            arr.ToList().ForEach(x =>
            {
                string[] arrItem = x.Split('=');
                GMCDbUtil.SetPropertyValue(objEmplOffWork, arrItem.FirstOrDefault(), Convert.ChangeType(arrItem.LastOrDefault(), GMCDbUtil.GetCSharpVariableType("HREmployeeOffWorks", arrItem.FirstOrDefault())));
            });
            int iLeaveTypeID = new HREmployeeLeaveTypesController().GetObjectIDByNo("PN");

            if (objEmplOffWork.FK_HREmployeeLeaveTypeID == iLeaveTypeID && objEmplOffWork.HREmployeeOffWorkRegDays > Convert.ToDouble(AuthConfig.GetSession("TongNgayPhep")))
            {
                return(Content("Số ngày nghỉ phép vượt quá tổng số ngày nghỉ phép còn lại! Kiểm tra lại"));
            }
            HREmployeesInfo objEmpl = ExpertERP.Controller.EmployeeCtrl.GetObjectByID(objEmplOffWork.FK_HREmployeeID) as HREmployeesInfo;

            if (objEmpl == null)
            {
                objEmpl = GMCWebApp.GetEmployeeByUserName(Convert.ToString(AuthConfig.GetSession("CurrentUser")));
            }
            if (objEmpl != null)
            {
                DataSet ds = SqlDatabaseHelper.RunStoredProcedure("spl_GetAllDataEmployeeOffWorkByEmployeeIDAndDate", objEmpl.HREmployeeID, objEmplOffWork.HREmployeeOffWorkFromDate.Value, objEmplOffWork.HREmployeeOffWorkToDate.Value);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return(Content(string.Format("Bạn đã đăng ký phép trong thời gian {0} - {1}! Vui lòng kiểm tra lại!", objEmplOffWork.HREmployeeOffWorkFromDate.Value.ToShortDateString(), objEmplOffWork.HREmployeeOffWorkToDate.Value.ToShortDateString())));
                }
                if (objEmplOffWork.FK_HREmployeeID == 0)
                {
                    objEmplOffWork.FK_HREmployeeID = objEmpl.HREmployeeID;
                }
                objEmplOffWork.AACreatedUser              = Convert.ToString(AuthConfig.GetSession("CurrentUser"));
                objEmplOffWork.ApprovalStatusCombo        = "New";
                objEmplOffWork.HREmployeeOffWorkTypeCombo = "Permision";
                EmployeeOffWorkCtrl.SaveObject(objEmplOffWork);
                return(Content("OK"));
            }
            else
            {
                return(Content("User hiện chưa cấu hình nhân viên! Không thể đăng ký!"));
            }
        }