コード例 #1
0
ファイル: Form1.cs プロジェクト: abelcondear/repo
 private void lblError_Click(object sender, EventArgs e)
 {
     FrmHelp frmHelp = new FrmHelp();
     ((TextBox)frmHelp.Controls["txtHelp"]).Text = ufld.HelpErrorRecord.Replace("\n", Environment.NewLine);
     frmHelp.ShowDialog();
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: abelcondear/repo
        private void btnSend_Click(object sender, EventArgs e)
        {
            string value = string.Empty;
            string type = string.Empty;
            string nullvalue = string.Empty;
            int error_count = 0;
            int error_fields_count = 0;
            int duplicate_count = 0;
            int total = 0;

            lblReference.Visible = false;
            lblError.Visible = false;
            lblDuplicate.Visible = false;
            lblFieldsError.Visible = false;
            btnSelect.Enabled = false;
            btnHelp.Enabled = false;
            btnSend.Enabled = false;
            btnClose.Enabled = false;

            lblStatus.Text = "Wait a moment";
            lblStatus.Update();
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

            if (rowid_witherrors.Count > 0)
            {
                if (rowid_witherrors.Count == dgView.Rows.Count)
                {
                    for (int x = 0; x < dgView.Rows.Count; x++)
                    {
                        for (int y = 0; y < dgView.Rows[x].Cells.Count; y++)
                        {
                            dgView.Rows[x].Cells[y].Style.BackColor = Constant.CLR_CELL_DEFAULT;
                            dgView.Rows[x].Cells[y].ToolTipText = string.Empty;
                        }
                    }
                }
                else
                {
                    for (int x = 0; x < dgView.Rows.Count; x++)
                    {
                        foreach (int id in rowid_witherrors)
                        {
                            if ((int)dgView.Rows[x].Cells[0].Tag == id)
                            {
                                for (int y = 0; y < dgView.Rows[x].Cells.Count; y++)
                                {
                                    dgView.Rows[x].Cells[y].Style.BackColor = Constant.CLR_CELL_DEFAULT;
                                    dgView.Rows[x].Cells[y].ToolTipText = string.Empty;
                                }
                                break;
                            }
                        }
                    }
                }

                rowid_witherrors.RemoveAll(clearAll);
                dgView.Update();
            }

            try
            {
                for (int k = 0; k < dgView.Rows.Count; k++)
                {
                    try
                    {
                        ArrayAssociative values = new ArrayAssociative();

                        for (int o = 0; o < fld.Count; o++)
                        {
                            type = fld[o].FieldType.ToLower().Trim();
                            nullvalue = fld[o].FieldNullValue.Trim();

                            if (type == "int")
                            {
                                values[fld[o].FieldName] = (nullvalue == string.Empty) ? "0" : nullvalue;
                            }
                            else if (type == "bool")
                            {
                                if (nullvalue == string.Empty)
                                {
                                    values[fld[o].FieldName] = false;
                                }
                                else
                                {
                                    values[fld[o].FieldName] = (nullvalue.ToUpper() == "YES");
                                }
                            }
                            else if (type == "datetime")
                            {
                                values[fld[o].FieldName] = (nullvalue == string.Empty) ? "01/01/1800" : nullvalue;
                            }
                            else
                            {
                                values[fld[o].FieldName] = nullvalue;
                            }
                        }

                        for (int j = 0; j < dgView.Rows[k].Cells.Count; j++)
                        {
                            value = ((string)dgView.Rows[k].Cells[j].Value).Trim();
                            type = fld[(int)index_fld[dgView.Columns[j].Name]].FieldType.ToLower().Trim();

                            if (value != string.Empty)
                            {
                                if (type == "bool")
                                {
                                    values[dgView.Columns[j].Name] = (value.ToUpper() == "YES");
                                }
                                else
                                {
                                    values[dgView.Columns[j].Name] = value;
                                }
                            }
                        }

                        if (!validate_fields(dgView.Rows[k].Index, ref total))
                        {
                            error_fields_count += total;
                            throw new System.ArgumentException(Constant.MSG_ERROR_FIELD_ITEM);
                        }

                        int retval = 1;
                        //ImportClient emp = new ImportClient();    //Here, you can create an object and call a method of your Web Service
                        /*int retval = emp.AddEmployee(
                          Convert.ToBoolean(values["Active"])
                        , (string)values["AddressNumber"]
                        , (string)values["LastName"]
                        , (string)values["Neighborhood"]
                        , (string)values["PositionHeld"]
                        , (string)values["Category"]
                        , (string)values["City"]
                        , (string)values["PostalCode"]
                        , (string)values["Company"]
                        , (string)values["CUIL"]
                        , (string)values["Area"]
                        , (string)values["ApartmentOrUF"]
                        , (string)values["Address"]
                        , Convert.ToInt32(values["Age"])
                        , (string)values["PersonalEmail"]
                        , (string)values["MaritalStatus"]
                        , Utils.ToDate((string)values["AdmissionDate"], ufld.DateFormat)
                        , Utils.ToDate((string)values["DateOfBirth"], ufld.DateFormat)
                        , (string)values["WorkShift"]
                        , (string)values["FileNumber"]
                        , (string)values["PlaceOfBirth"]
                        , (string)values["Nationality"]
                        , (string)values["FirstName"]
                        , (string)values["IdentificationNumber"]
                        , (string)values["Country"]
                        , (string)values["Floor"]
                        , (string)values["StateOrProvince"]
                        , (string)values["Gender"]
                        , (string)values["JobStatus"]
                        , (string)values["Branch"]
                        , (string)values["MobilePhone"]
                        , (string)values["EmergencyPhone"]
                        , (string)values["HomePhone"]
                        , (string)values["IdentificationType"]
                        );*/

                        if (retval == 0)
                        {
                            throw new System.ArgumentException(Constant.MSG_ERROR_SEND_ITEM);
                        }
                        else if (retval == -1)
                        {
                            throw new System.ArgumentException(Constant.MSG_ERROR_DUPLICATE_ITEM);
                        }
                    }
                    catch (Exception ex)
                    {
                        Color bg = Constant.CLR_ERROR_RECORDS;

                        if (ex.Message == Constant.MSG_ERROR_DUPLICATE_ITEM)
                        {
                            bg = Constant.CLR_DUPLICATE_RECORDS;
                            duplicate_count++;
                        }
                        else
                        {
                            error_count++;
                        }

                        for (int x = 0; x < dgView.Rows[k].Cells.Count; x++)
                        {
                            if (dgView.Rows[k].Cells[x].Style.BackColor != Constant.CLR_ERROR_FIELDS)
                            {
                                dgView.Rows[k].Cells[x].Style.BackColor = bg;
                            }
                        }

                        rowid_witherrors.Add((int)dgView.Rows[k].Cells[0].Tag);
                    }
                }

                int q = dgView.Rows.Count;

                for (int x = 0; x < q; x++)
                {
                    bool deleterow = true;

                    foreach (int id in rowid_witherrors)
                    {
                        if ((int)dgView.Rows[x].Cells[0].Tag == id)
                        {
                            deleterow = false;
                            break;
                        }
                    }

                    if (deleterow)
                    {
                        dgView.Rows.RemoveAt(x);
                        x--;
                        q--;
                    }
                }

                if (rowid_witherrors.Count > 0)
                {
                    lblError.Text = Constant.LBL_ERROR_RECORDS.Replace("TOTAL", error_count.ToString());
                    lblDuplicate.Text = Constant.LBL_DUPLICATE_RECORDS.Replace("TOTAL", duplicate_count.ToString());
                    lblFieldsError.Text = Constant.LBL_ERROR_FIELDS.Replace("TOTAL", error_fields_count.ToString());
                    lblReference.Visible = true;
                    lblError.Visible = true;
                    lblDuplicate.Visible = true;
                    lblFieldsError.Visible = true;
                    MessageBox.Show(ufld.M_ErrorSend.Replace("\n", Environment.NewLine), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    FrmHelp frmHelp = new FrmHelp();
                    ((TextBox)frmHelp.Controls["txtHelp"]).Text = ufld.Help.Replace("\n", Environment.NewLine);
                    frmHelp.ShowDialog();
                }
                else
                {
                    MessageBox.Show(ufld.M_OkaySend.Replace("\n", Environment.NewLine), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: An error occurred when it tried to save the grid's records into the system. \n\nOriginal Error: \n" + ex.Message + " \n" + ex.Source, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                btnSelect.Enabled = true;
                btnHelp.Enabled = true;
                btnSend.Enabled = true;
                btnClose.Enabled = true;

                lblStatus.Text = "Import finished";
                lblStatus.Update();
                this.Cursor = System.Windows.Forms.Cursors.Default;
            }
        }