Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            List <AbsenceUDT> DeleteAbList = tool._A.Select <AbsenceUDT>();

            tool._A.DeletedValues(DeleteAbList);

            List <AbsenceUDT> InsertAbList = new List <AbsenceUDT>();

            foreach (DataGridViewRow each in dataGridViewX1.Rows)
            {
                if (each.IsNewRow)
                {
                    continue;
                }

                AbsenceUDT udt = new AbsenceUDT();
                udt.Absence = "" + each.Cells[0].Value;
                udt.Period  = "" + each.Cells[1].Value;
                InsertAbList.Add(udt);
            }

            tool._A.InsertValues(InsertAbList);

            MsgBox.Show("新增成功!!");
            this.Close();
        }
Пример #2
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            AccessHelper      access      = new AccessHelper();
            List <AbsenceUDT> absenceList = access.Select <AbsenceUDT>();

            access.DeletedValues(absenceList);

            List <AbsenceUDT> InsertAbList = new List <AbsenceUDT>();

            foreach (DataGridViewRow dr in dataGridViewX1.Rows)
            {
                AbsenceUDT    udt      = new AbsenceUDT();
                List <string> jsonList = new List <string>();

                for (int i = 2; i < dr.Cells["actor"].ColumnIndex; i++)
                {
                    if (dr.Cells[i].Value != null)
                    {
                        if (bool.Parse("" + dr.Cells[i].Value) == true)
                        {
                            string name = dataGridViewX1.Columns[i].HeaderText;
                            string abbr = dataGridViewX1.Columns[i].Name;
                            jsonList.Add("{" + string.Format("\"Abbr\":\"{0}\",\"Name\":\"{1}\"", abbr, name) + "}");
                        }
                    }
                }

                if (jsonList.Count > 0)
                {
                    udt.Absence = "[" + string.Join(",", jsonList) + "]";
                    udt.Period  = "" + dr.Cells["period"].Value;
                    InsertAbList.Add(udt);
                }

                udt.Actor    = "" + dr.Cells["actor"].Value;
                udt.StarTime = DateTime.Parse(("" + dr.Cells["star_time"].Value) == "" ? "00:00:00" : ("" + dr.Cells["star_time"].Value));
                udt.EndTime  = DateTime.Parse(("" + dr.Cells["end_time"].Value) == "" ? "00:00:00" : ("" + dr.Cells["end_time"].Value));
            }
            access.InsertValues(InsertAbList);
            MsgBox.Show("儲存成功!!");
            this.Close();
        }