protected void Page_Load(object sender, EventArgs e)
    {
        //���б�����ɾ����ť��ͨ��AJAXִ������ĺ�̨���룬ɾ��һ����¼
        if (Request["DelSchClassid"] != null)
        {
            int re = BLLTable<HR_SchClass>.Factory(conn).Delete(HR_SchClass.Attribute.SchClassid, Request["DelSchClassid"]);
            HR_Scheduling sdcond = new HR_Scheduling();
            sdcond.Top(500);
            sdcond.Where(" {0} = {1} ", HR_Scheduling.Attribute.SchClassid, Request["DelSchClassid"]);
            while (BLLTable<HR_Scheduling>.Factory(conn).Delete(sdcond) > 0)
            {
                continue;
            }
            if (re > 0)
            {
                Response.Write("1");//����������� ����0 ��ʾ�����ɹ���Ҳ����ֱ����� �ַ������ͻ��˽��������ַ�����Ϣ��Ϊ��ʾ
            }
            else
            {
                Response.Write("ɾ��ʧ�ܣ�");
            }
        }

        //���б�������ɾ����ť��ͨ��AJAXִ������ĺ�̨���룬ɾ��������¼
        if (Request["DelKeyIDS"] != null)
        {
            HR_SchClass cond = new HR_SchClass();
            cond.In(HR_SchClass.Attribute.SchClassid, Request["DelKeyIDS"]);
            int re = BLLTable<HR_SchClass>.Factory(conn).Delete(cond);
            HR_Scheduling sdcond = new HR_Scheduling();
            sdcond.Top(500);
            sdcond.In(HR_Scheduling.Attribute.SchClassid, Request["DelKeyIDS"]);
            while (BLLTable<HR_Scheduling>.Factory(conn).Delete(sdcond) > 0)
            {
                continue;
            }
            if (re > 0)
            {
                Response.Write("1");//����������� ����0 ��ʾ�����ɹ���Ҳ����ֱ����� �ַ������ͻ��˽��������ַ�����Ϣ��Ϊ��ʾ
            }
            else
            {
                Response.Write("ɾ��ʧ�ܣ�");
            }
        }

        //���û���ϸ��Ϣ�鿴�༭ҳ�棬�㱣��ʱ��ͨ��AJAXִ������ĺ�̨���룬ʵ�ֲ����ֶεĸ���
        if (Request["saveInfo"] != null)
        {
            HR_SchClass val = new HR_SchClass();
            val.SchClassid = int.Parse(Request["FieldKeyID"]);
            List<AttributeItem> lstCol = val.af_AttributeItemList;
            for (int i = 0; i < lstCol.Count; i++)
            {
                if (!string.IsNullOrEmpty(Request["txt" + lstCol[i].FieldName])) {
                    val.SetValue(lstCol[i].FieldName,Request["txt" + lstCol[i].FieldName]);
                }
            }

            BLLTable<HR_SchClass>.Factory(conn).Update(val, HR_SchClass.Attribute.SchClassid);
            Response.Write("�޸��û���Ϣ�ɹ�");

        }
        Response.End();
    }
Beispiel #2
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        try
        {
            HR_STAFF stfVal = new HR_STAFF();
            stfVal.STAFF_ID = 0;
            List <HR_STAFF> stffs = BLLTable <HR_STAFF> .Factory(conn).Select(stfVal, new HR_STAFF());

            string[]   schidstr = hidSelBanciId.Value.TrimEnd(',').Split(',');
            List <int> schids   = new List <int>();
            for (int i = 0; i < schidstr.Length; i++)
            {
                int sid = -1;
                if (int.TryParse(schidstr[i], out sid))
                {
                    schids.Add(sid);
                }
            }
            int                  stfCount = 0;
            int                  stfSch   = 0;
            DateTime             sDate    = DateTime.Parse(txtStartTime.Value);
            DateTime             eDate    = DateTime.Parse(txtEndTime.Value);
            DateTime             dt       = sDate;
            List <HR_Scheduling> schList  = new List <HR_Scheduling>();
            foreach (HR_STAFF stf in stffs)
            {
                stfCount++;
                dt = sDate;
                while (dt.Date <= eDate.Date)
                {
                    foreach (int schid in schids)
                    {
                        HR_Scheduling sch = new HR_Scheduling();
                        sch._SchYear    = dt.Date.Year;
                        sch._SchMonth   = Convert.ToInt16(dt.Date.Month);
                        sch._SchDay     = Convert.ToInt16(dt.Date.Day);
                        sch._STAFF_ID   = Convert.ToInt32(stf.STAFF_ID);
                        sch._SchType    = Convert.ToInt32(txtType.Value);
                        sch._SchClassid = schid;
                        schList.Add(sch);
                    }
                    dt = dt.AddDays(1);
                    stfSch++;
                }
            }
            int           buildCount = 0;
            HR_Scheduling delCon     = new HR_Scheduling();
            delCon.Top(500);
            string wher = " CAST(CAST({0} AS char(4)) + '-' + CAST({1} AS char(2)) + '-' + CAST({2} AS char(2)) as datetime) >= '{3}-{4}-{5}' and CAST(CAST({6} AS char(4)) + '-' + CAST({7} AS char(2)) + '-' + CAST({8} AS char(2)) as datetime) <= '{9}-{10}-{11}' ";
            delCon.Where(wher, HR_Scheduling.Attribute.SchYear, HR_Scheduling.Attribute.SchMonth, HR_Scheduling.Attribute.SchDay,
                         sDate.Year, sDate.Month, sDate.Day,
                         HR_Scheduling.Attribute.SchYear, HR_Scheduling.Attribute.SchMonth, HR_Scheduling.Attribute.SchDay,
                         eDate.Year, eDate.Month, eDate.Day);
            while (BLLTable <HR_Scheduling> .Factory(conn).Delete(delCon) > 0)
            {
                continue;
            }
            DataTable dataTable = BLLTable <HR_Scheduling> .qDataTable("select * from " + HR_Scheduling.Attribute.SchDay.TableName + " where 1=2");

            List <DataRow> dataList = new List <DataRow>();
            foreach (HR_Scheduling sch in schList)
            {
                DataRow dr = dataTable.NewRow();
                foreach (DataColumn dc in dataTable.Columns)
                {
                    dr[dc] = sch.GetValue(new AttributeItem(HR_Scheduling.Attribute.STAFF_ID.TableName, dc.ColumnName));
                }
                dataList.Add(dr);
            }

            try
            {
                //将电量数据批量插入数据库
                SqlBulkCopy sbc = new SqlBulkCopy(MyConfigurationSettings.GetValue("conn"));
                sbc.BatchSize            = 1000;
                sbc.BulkCopyTimeout      = (((dataList.Count) / 1000) + 1) * 3;
                sbc.DestinationTableName = HR_Scheduling.Attribute.STAFF_ID.TableName;
                sbc.WriteToServer(dataList.ToArray());
                buildCount += dataList.Count;
            }
            catch { }
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "$('.main').unmask();alert('成功修改" + buildCount + "条记录');", true);
        }
        catch (Exception ex)
        {
            litWarn.Text = ex.Message;
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        try
        {
            HR_STAFF stfVal = new HR_STAFF();
            stfVal.STAFF_ID = 0;
            List<HR_STAFF> stffs = BLLTable<HR_STAFF>.Factory(conn).Select(stfVal, new HR_STAFF());
            string[] schidstr = hidSelBanciId.Value.TrimEnd(',').Split(',');
            List<int> schids = new List<int>();
            for (int i = 0; i < schidstr.Length; i++)
            {
                int sid = -1;
                if (int.TryParse(schidstr[i], out sid))
                    schids.Add(sid);
            }
            int stfCount = 0;
            int stfSch = 0;
            DateTime sDate = DateTime.Parse(txtStartTime.Value);
            DateTime eDate = DateTime.Parse(txtEndTime.Value);
            DateTime dt = sDate;
            List<HR_Scheduling> schList = new List<HR_Scheduling>();
            foreach (HR_STAFF stf in stffs)
            {
                stfCount++;
                dt = sDate;
                while (dt.Date <= eDate.Date)
                {
                    foreach (int schid in schids)
                    {
                        HR_Scheduling sch = new HR_Scheduling();
                        sch._SchYear = dt.Date.Year;
                        sch._SchMonth = Convert.ToInt16(dt.Date.Month);
                        sch._SchDay = Convert.ToInt16(dt.Date.Day);
                        sch._STAFF_ID = Convert.ToInt32(stf.STAFF_ID);
                        sch._SchType = Convert.ToInt32(txtType.Value);
                        sch._SchClassid = schid;
                        schList.Add(sch);
                    }
                    dt = dt.AddDays(1);
                    stfSch++;
                }
            }
            int buildCount = 0;
            HR_Scheduling delCon = new HR_Scheduling();
            delCon.Top(500);
            string wher = " CAST(CAST({0} AS char(4)) + '-' + CAST({1} AS char(2)) + '-' + CAST({2} AS char(2)) as datetime) >= '{3}-{4}-{5}' and CAST(CAST({6} AS char(4)) + '-' + CAST({7} AS char(2)) + '-' + CAST({8} AS char(2)) as datetime) <= '{9}-{10}-{11}' ";
            delCon.Where(wher, HR_Scheduling.Attribute.SchYear, HR_Scheduling.Attribute.SchMonth, HR_Scheduling.Attribute.SchDay,
                            sDate.Year, sDate.Month, sDate.Day,
                            HR_Scheduling.Attribute.SchYear, HR_Scheduling.Attribute.SchMonth, HR_Scheduling.Attribute.SchDay,
                            eDate.Year, eDate.Month, eDate.Day);
            while (BLLTable<HR_Scheduling>.Factory(conn).Delete(delCon) > 0)
            {
                continue;
            }
            DataTable dataTable = BLLTable<HR_Scheduling>.qDataTable("select * from " + HR_Scheduling.Attribute.SchDay.TableName + " where 1=2");
            List<DataRow> dataList = new List<DataRow>();
            foreach (HR_Scheduling sch in schList)
            {
                DataRow dr = dataTable.NewRow();
                foreach (DataColumn dc in dataTable.Columns)
                {
                    dr[dc] = sch.GetValue(new AttributeItem(HR_Scheduling.Attribute.STAFF_ID.TableName, dc.ColumnName));
                }
                dataList.Add(dr);
            }

            try
            {
                //���������������������ݿ�
                SqlBulkCopy sbc = new SqlBulkCopy(MyConfigurationSettings.GetValue("conn"));
                sbc.BatchSize = 1000;
                sbc.BulkCopyTimeout = (((dataList.Count) / 1000) + 1) * 3;
                sbc.DestinationTableName = HR_Scheduling.Attribute.STAFF_ID.TableName;
                sbc.WriteToServer(dataList.ToArray());
                buildCount += dataList.Count;
            }
            catch { }
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "$('.main').unmask();alert('�ɹ��޸�" + buildCount + "����¼');", true);
        }
        catch (Exception ex)
        {
            litWarn.Text = ex.Message;
        }
    }