コード例 #1
0
        protected async void bulkUpsertEmployees_Click(object sender, EventArgs e)
        {
            List <TWP_EE_Upsert> updatedEE = new List <TWP_EE_Upsert>();


            if (EEImport.HasFile)
            {
                StreamReader csvreader = new StreamReader(EEImport.FileContent);
                while (!csvreader.EndOfStream)
                {
                    var line   = csvreader.ReadLine();
                    var values = line.Split(',');

                    List <Variable>             varsList = new List <Variable>();
                    Dictionary <string, string> varsDic  = new Dictionary <string, string>();
                    TWP_upsert_State            vars     = new TWP_upsert_State();
                    List <TWP_Employee_Schema>  eeSchema = await TWPSDK.listEESchema(siteId, returnAuthToken);

                    List <TWP_upsert_State> states = new List <TWP_upsert_State>();

                    IList <string> varValue = new List <string>();


                    int valCount = 15;


                    foreach (string key in eeSchema[0].States[0].Variables.Keys)
                    {
                        string currkey = key;
                        if (!varsDic.ContainsKey(key))
                        {
                            varsDic.Add(key, valCount.ToString());
                        }
                        valCount++;
                    }

                    if (values[0] != "RecordNumber")
                    {
                        List <TWP_Identifier> idList = new List <TWP_Identifier>();
                        List <string>         testid = new List <string>();

                        if (values.Length > 13)
                        {
                            for (int i = 12; i <= 14; i++)
                            {
                                TWP_Identifier id = new TWP_Identifier();
                                id.Id = !string.IsNullOrEmpty(values[i]) ? values[i].ToString() : "";
                                idList.Add(id);
                                testid.Add(id.Id);
                            }
                        }


                        for (var i = 0; i < eeSchema[0].States[0].Variables.Keys.Count; i++)
                        {
                            int    keyInd = i + 15;
                            string value  = values[keyInd];

                            string key = varsDic.FirstOrDefault(x => x.Value == keyInd.ToString()).Key;
                            varsDic[key] = value;
                            if (value == "" && key != "EmployeeType")
                            {
                                varsDic.Remove(key);
                            }
                        }

                        vars.EffectiveDate = DateTime.Now.ToString("yyyy-MM-dd");
                        vars.Variables     = varsDic;
                        states.Add(vars);

                        TWP_EE_Upsert ee = new TWP_EE_Upsert()
                        {
                            FirstName       = values[1],
                            MiddleName      = values[2],
                            LastName        = values[3],
                            EmployeeCode    = values[4],
                            Designation     = values[5],
                            Phone           = values[6],
                            Email           = values[7],
                            StartDate       = values[8],
                            EndDate         = values[9],
                            ExportBlock     = Convert.ToBoolean(values[10]),
                            WebClockEnabled = Convert.ToBoolean(values[11]),
                            //Identifiers = idList,
                            States = states
                        };

                        try
                        {
                            await TWPSDK.UpsertEmployee(siteId, returnAuthToken, values[0], ee);

                            createButton(ee.EmployeeCode, $"{ee.FirstName} {ee.LastName}");
                        }
                        catch
                        {
                            createButton(ee.EmployeeCode, $"{ee.FirstName} {ee.LastName}", false);
                        }
                    }
                }
            }
        }
コード例 #2
0
        protected async void downloadEmployees_Click(object sender, EventArgs e)
        {
            List <TWP_Employee_Schema> eeSchema = await TWPSDK.listEESchema(siteId, returnAuthToken);

            IList <string> schemaState = eeSchema[0].States[0].Variables.Keys.ToList();

            List <TWP_Employee> employees = await TWPSDK.ListEmployees(siteId, returnAuthToken);

            StringBuilder sb = new StringBuilder();

            int idCount     = 3;
            int statesCount = 0;

            string header = "RecordNumber,First Name,Middle Name,Last Name,Code,Designation,Phone,Email,Start Date,Separation Date," +
                            "Export Block,WebClock Enabled,login1,login2,login3,";

            foreach (TWP_Employee_Schema results in eeSchema)
            {
                foreach (TWP_State_Schema state in results.States)
                {
                    foreach (KeyValuePair <string, string> kvp in state.Variables)
                    {
                        ++statesCount;
                        header += $"{kvp.Key.ToString()},";
                    }
                }
            }

            sb.AppendLine(header);
            string body = "";

            foreach (TWP_Employee emp in employees)
            {
                body = $"{emp.RecordNumber},{emp.FirstName},{emp.MiddleName},{emp.LastName},{emp.EmployeeCode},{emp.Designation},{emp.Phone},{emp.Email},{emp.StartDate},{emp.EndDate},{emp.ExportBlock},{emp.WebClockEnabled},";

                try
                {
                    foreach (TWP_Identifier id in emp.Identifiers)
                    {
                        if (!string.IsNullOrEmpty(id.Id))
                        {
                            body += $"{id.Id},";
                        }
                    }
                    if (emp.Identifiers.Count < idCount)
                    {
                        body += string.Concat(Enumerable.Repeat(",", idCount - emp.Identifiers.Count));
                    }
                }
                catch
                {
                    body += $",,,";
                }



                try
                {
                    foreach (TWP_State state in emp.States)
                    {
                        foreach (string varName in schemaState)
                        {
                            foreach (KeyValuePair <string, string> kvp in state.Variables)
                            {
                                if (kvp.Key == varName)
                                {
                                    body += $"{kvp.Value}";
                                }
                            }
                            body += ",";
                        }
                    }
                }
                catch
                {
                    body += string.Concat(Enumerable.Repeat(",", statesCount));
                }
                sb.AppendLine(body);
            }

            downloadFile("EmployeeDetail", sb);
        }