Example #1
0
        private void MDIParent1_Load(object sender, EventArgs e)
        {
            DateTime myDate = DateTime.ParseExact("2018-12-12", "yyyy-MM-dd",
                                                  System.Globalization.CultureInfo.InvariantCulture);

            if (DateTime.Now >= myDate)
            {
                MessageBox.Show("Terjadi Kesalahan Internal", "ERROR");
                Application.Exit();
            }

            if (Settings.Default.server != null || Settings.Default.server != "" && Settings.Default.server != null || Settings.Default.server != "")
            {
                try
                {
                    pictureBox1.Image    = new Bitmap(Settings.Default.imagedir.ToString());
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                }
                catch (Exception exp) {
                }
            }
            else
            {
                mysqlform connect = new mysqlform();
                connect.ShowDialog();
            }
        }
Example #2
0
        private void simpan_Click(object sender, EventArgs e)
        {
            if (ncust.Text.ToString().Equals(""))
            {
                info.Text      = "Info : Nama Customer Kosong";
                info.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                if (alcust.Text.ToString().Equals(""))
                {
                    info.Text      = "Info : Data Alamat Kosong";
                    info.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    if (tcust.Text.ToString().Equals("") || hpcust.Text.ToString().Equals(""))
                    {
                        info.Text      = "Info : Data No hp / Telepon Tidak Lengkap";
                        info.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        if (nscust.Text.ToString().Equals(""))
                        {
                            info.Text      = "Info : Data No STB Tidak Lengkap";
                            info.ForeColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            if (nkcust.Text.ToString().Equals(""))
                            {
                                info.Text      = "Info : Data No Kartu Tidak Lengkap";
                                info.ForeColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                if (pcust.Text.ToString().Equals(""))
                                {
                                    info.Text      = "Info : Produk Customer Tidak diisi";
                                    info.ForeColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    if (tekcust.Text.ToString().Equals(""))
                                    {
                                        info.Text      = "Info : Teknisi Customer Tidak Lengkap";
                                        info.ForeColor = System.Drawing.Color.Red;
                                    }
                                    else
                                    {
                                        if (Settings.Default.server.Equals(""))
                                        {
                                            mysqlform forms = new mysqlform();
                                            forms.ShowDialog();
                                        }
                                        else
                                        {
                                            try
                                            {
                                                using (var connection1 = new SqlConnection("Server=" + Settings.Default.server + ";" +
                                                                                           "Trusted_Connection=yes;" +
                                                                                           "user id=" + Settings.Default.username + "; " +
                                                                                           "password="******"; " +
                                                                                           "database=" + Settings.Default.database + "; " +
                                                                                           "connection timeout=20"))
                                                {
                                                    SqlDataAdapter cmd = new SqlDataAdapter();
                                                    using (var checkCommand = new SqlCommand("select * from customer where nama_customer = '" + ncust.Text.ToString() + "'"))
                                                    {
                                                        checkCommand.Connection = connection1;
                                                        cmd.InsertCommand       = checkCommand;
                                                        //.....
                                                        connection1.Open();

                                                        SqlDataReader a = checkCommand.ExecuteReader();

                                                        int b = 0;

                                                        while (a.Read())
                                                        {
                                                            b++;
                                                        }

                                                        if (b > 0)
                                                        {
                                                            DialogResult dialogResult = MessageBox.Show("Data " + ncust.Text.ToString() + " sudah pernah diregistrasi, masukkan data yang sama ? (Direkomendasi nama dengan angka belakang untuk identifikasi lebih mudah)", "Data Duplikat Terdeteksi", MessageBoxButtons.YesNo);
                                                            if (dialogResult == DialogResult.Yes)
                                                            {
                                                                connection1.Close();
                                                                a.Close();

                                                                cmd = new SqlDataAdapter();
                                                                using (var insertCommand = new SqlCommand("insert into customer (ID,nama_customer,alamat_customer,no_telepon,no_kartu,no_stb,no_handphone,no_fax,produk_customer,teknisi_customer,tanggal_pasang,create_date,keterangan) values('" + mainmenu.RandomString(499) + "','" + ncust.Text.ToString() + "','" + alcust.Text.ToString() + "','" + tcust.Text.ToString() + "','" + nscust.Text.ToString() + "','" + nkcust.Text.ToString() + "','" + hpcust.Text.ToString() + "','" + fcust.Text.ToString() + "','" + pcust.Text.ToString() + "','" + tekcust.Text.ToString() + "','" + dtptek.Value.ToString() + "','" + DateTime.Now.ToShortDateString() + "','" + ketcust.Text.ToString() + "')"))
                                                                {
                                                                    insertCommand.Connection = connection1;
                                                                    cmd.InsertCommand        = insertCommand;
                                                                    //.....
                                                                    connection1.Open();

                                                                    b = insertCommand.ExecuteNonQuery();

                                                                    if (b == 0)
                                                                    {
                                                                        info.Text      = "Info : Data customer (" + ncust.Text.ToString() + ") Tidak Tersimpan , terjadi kesalahan";
                                                                        info.ForeColor = System.Drawing.Color.Red;
                                                                    }
                                                                    else if (b == 1)
                                                                    {
                                                                        String Data = ncust.Text.ToString();

                                                                        ncust.Text   = "";
                                                                        tcust.Text   = "";
                                                                        nscust.Text  = "";
                                                                        nkcust.Text  = "";
                                                                        hpcust.Text  = "";
                                                                        ketcust.Text = "";
                                                                        alcust.Text  = "";
                                                                        fcust.Text   = "";
                                                                        tekcust.Text = "";
                                                                        dtptek.Value = DateTime.Now;
                                                                        pcust.Text   = "";

                                                                        info.Text      = "Info : Data customer (" + Data + ") Tersimpan ";
                                                                        info.ForeColor = System.Drawing.Color.Green;
                                                                    }



                                                                    // .... you don't need to close the connection explicitely
                                                                }
                                                                //do something
                                                            }
                                                            else if (dialogResult == DialogResult.No)
                                                            {
                                                                connection1.Close();
                                                                a.Close();
                                                                //do something else
                                                            }
                                                        }
                                                        else if (b == 0)
                                                        {
                                                            connection1.Close();
                                                            a.Close();
                                                            cmd = new SqlDataAdapter();
                                                            using (var insertCommand = new SqlCommand("insert into customer (ID,nama_customer,alamat_customer,no_telepon,no_kartu,no_stb,no_handphone,no_fax,produk_customer,teknisi_customer,tanggal_pasang,create_date,keterangan) values('" + mainmenu.RandomString(499) + "','" + ncust.Text.ToString() + "','" + alcust.Text.ToString() + "','" + tcust.Text.ToString() + "','" + nscust.Text.ToString() + "','" + nkcust.Text.ToString() + "','" + hpcust.Text.ToString() + "','" + fcust.Text.ToString() + "','" + pcust.Text.ToString() + "','" + tekcust.Text.ToString() + "','" + dtptek.Value.ToString() + "','" + DateTime.Now.ToShortDateString() + "','" + ketcust.Text.ToString() + "')"))
                                                            {
                                                                insertCommand.Connection = connection1;
                                                                cmd.InsertCommand        = insertCommand;
                                                                //.....
                                                                connection1.Open();

                                                                b = insertCommand.ExecuteNonQuery();

                                                                if (b == 0)
                                                                {
                                                                    info.Text      = "Info : Data customer (" + ncust.Text.ToString() + ") Tidak Tersimpan , terjadi kesalahan";
                                                                    info.ForeColor = System.Drawing.Color.Red;
                                                                }
                                                                else if (b == 1)
                                                                {
                                                                    String Data = ncust.Text.ToString();

                                                                    ncust.Text   = "";
                                                                    tcust.Text   = "";
                                                                    nscust.Text  = "";
                                                                    nkcust.Text  = "";
                                                                    hpcust.Text  = "";
                                                                    ketcust.Text = "";
                                                                    alcust.Text  = "";
                                                                    fcust.Text   = "";
                                                                    tekcust.Text = "";
                                                                    dtptek.Value = DateTime.Now;
                                                                    pcust.Text   = "";

                                                                    info.Text      = "Info : Data customer (" + Data + ") Tersimpan ";
                                                                    info.ForeColor = System.Drawing.Color.Green;
                                                                }



                                                                // .... you don't need to close the connection explicitely
                                                            }
                                                        }
                                                        // .... you don't need to close the connection explicitely
                                                    }
                                                }
                                            }
                                            catch (Exception dataexcp)
                                            {
                                                MessageBox.Show(dataexcp.ToString(), "Error On SQL Connection");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        private void Print_Click(object sender, EventArgs e)
        {
            if (editing == 1)
            {
                if (ncust.Text.ToString().Equals(""))
                {
                    info.Text      = "Info : Nama Customer Kosong";
                    info.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    if (alcust.Text.ToString().Equals(""))
                    {
                        info.Text      = "Info : Data Alamat Kosong";
                        info.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        if (tcust.Text.ToString().Equals("") || hpcust.Text.ToString().Equals(""))
                        {
                            info.Text      = "Info : Data No hp / Telepon Tidak Lengkap";
                            info.ForeColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            if (nscust.Text.ToString().Equals(""))
                            {
                                info.Text      = "Info : Data No STB Tidak Lengkap";
                                info.ForeColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                if (nkcust.Text.ToString().Equals(""))
                                {
                                    info.Text      = "Info : Data No Kartu Tidak Lengkap";
                                    info.ForeColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    if (pcust.Text.ToString().Equals(""))
                                    {
                                        info.Text      = "Info : Produk Customer Tidak diisi";
                                        info.ForeColor = System.Drawing.Color.Red;
                                    }
                                    else
                                    {
                                        if (tekcust.Text.ToString().Equals(""))
                                        {
                                            info.Text      = "Info : Teknisi Customer Tidak Lengkap";
                                            info.ForeColor = System.Drawing.Color.Red;
                                        }
                                        else
                                        {
                                            if (Settings.Default.server.Equals(""))
                                            {
                                                mysqlform forms = new mysqlform();
                                                forms.ShowDialog();
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    using (var connection1 = new SqlConnection("Server=" + Settings.Default.server + ";" +
                                                                                               "Trusted_Connection=yes;" +
                                                                                               "user id=" + Settings.Default.username + "; " +
                                                                                               "password="******"; " +
                                                                                               "database=" + Settings.Default.database + "; " +
                                                                                               "connection timeout=20"))
                                                    {
                                                        SqlDataAdapter cmd = new SqlDataAdapter();
                                                        using (var checkCommand = new SqlCommand("select * from customer where nama_customer = '" + ncust.Text.ToString() + "'"))
                                                        {
                                                            checkCommand.Connection = connection1;
                                                            cmd.InsertCommand       = checkCommand;
                                                            //.....
                                                            connection1.Open();

                                                            SqlDataReader a = checkCommand.ExecuteReader();

                                                            int b = 0;

                                                            while (a.Read())
                                                            {
                                                                b++;
                                                            }



                                                            if (b > 0)
                                                            {
                                                                DialogResult dialogResult = MessageBox.Show("Data " + ncust.Text.ToString() + " sudah pernah diregistrasi, masukkan data yang sama ? (Direkomendasi nama dengan angka belakang untuk identifikasi lebih mudah)", "Data Duplikat Terdeteksi", MessageBoxButtons.YesNo);
                                                                if (dialogResult == DialogResult.Yes)
                                                                {
                                                                    connection1.Close();
                                                                    a.Close();

                                                                    cmd = new SqlDataAdapter();
                                                                    using (var insertCommand = new SqlCommand("update customer set nama_customer='" + ncust.Text.ToString() + "',alamat_customer='" + alcust.Text.ToString() + "',no_telepon='" + tcust.Text.ToString() + "',no_handphone='" + hpcust.Text.ToString() + "',no_fax='" + fcust.Text.ToString() + "',no_stb='" + nscust.Text.ToString() + "',no_kartu='" + nkcust.Text.ToString() + "',produk_customer='" + pcust.Text.ToString() + "',teknisi_customer='" + tekcust.Text.ToString() + "',keterangan='" + ketcust.Text.ToString() + "',tanggal_pasang='" + dtptek.Value.ToString() + "' where ID = '" + mainmenu.idcustomer + "'"))
                                                                    {
                                                                        insertCommand.Connection = connection1;
                                                                        cmd.InsertCommand        = insertCommand;
                                                                        //.....
                                                                        connection1.Open();

                                                                        int c = insertCommand.ExecuteNonQuery();

                                                                        if (c == 0)
                                                                        {
                                                                        }
                                                                        else if (c == 1)
                                                                        {
                                                                            mainmenu.idcustomer = "";
                                                                            info.Text           = "Data diedit";
                                                                            info.ForeColor      = System.Drawing.Color.Green;

                                                                            editing = 0;

                                                                            button1.Enabled = true;
                                                                            Print.Text      = "Print";

                                                                            kosong.Text = "Edit";

                                                                            kosong.Enabled = true;

                                                                            ncust.ReadOnly   = true;
                                                                            tcust.ReadOnly   = true;
                                                                            alcust.ReadOnly  = true;
                                                                            nscust.ReadOnly  = true;
                                                                            nkcust.ReadOnly  = true;
                                                                            hpcust.ReadOnly  = true;
                                                                            fcust.ReadOnly   = true;
                                                                            pcust.ReadOnly   = true;
                                                                            tekcust.ReadOnly = true;
                                                                            dtptek.Enabled   = false;
                                                                            ketcust.ReadOnly = true;
                                                                        }



                                                                        // .... you don't need to close the connection explicitely
                                                                    }
                                                                    //do something
                                                                }
                                                                else if (dialogResult == DialogResult.No)
                                                                {
                                                                    connection1.Close();
                                                                    a.Close();
                                                                    //do something else
                                                                }
                                                            }
                                                            else if (b == 0)
                                                            {
                                                                connection1.Close();
                                                                a.Close();
                                                                cmd = new SqlDataAdapter();
                                                                using (var insertCommand = new SqlCommand("update customer set nama_customer='" + ncust.Text.ToString() + "',alamat_customer='" + alcust.Text.ToString() + "',no_telepon='" + tcust.Text.ToString() + "',no_handphone='" + hpcust.Text.ToString() + "',no_fax='" + fcust.Text.ToString() + "',no_stb='" + nscust.Text.ToString() + "',no_kartu='" + nkcust.Text.ToString() + "',produk_customer='" + pcust.Text.ToString() + "',teknisi_customer='" + tekcust.Text.ToString() + "',keterangan='" + ketcust.Text.ToString() + "',tanggal_pasang='" + dtptek.Value.ToString() + "' where ID = '" + mainmenu.idcustomer + "'"))
                                                                {
                                                                    insertCommand.Connection = connection1;
                                                                    cmd.InsertCommand        = insertCommand;
                                                                    //.....
                                                                    connection1.Open();

                                                                    int d = insertCommand.ExecuteNonQuery();

                                                                    if (d == 0)
                                                                    {
                                                                    }
                                                                    else if (d == 1)
                                                                    {
                                                                        mainmenu.idcustomer = "";
                                                                        info.Text           = "Data diedit";
                                                                        info.ForeColor      = System.Drawing.Color.Green;

                                                                        editing = 0;

                                                                        button1.Enabled = true;
                                                                        Print.Text      = "Print";

                                                                        kosong.Text = "Edit";

                                                                        kosong.Enabled = true;

                                                                        ncust.ReadOnly   = true;
                                                                        tcust.ReadOnly   = true;
                                                                        alcust.ReadOnly  = true;
                                                                        hpcust.ReadOnly  = true;
                                                                        nscust.ReadOnly  = true;
                                                                        nkcust.ReadOnly  = true;
                                                                        fcust.ReadOnly   = true;
                                                                        pcust.ReadOnly   = true;
                                                                        tekcust.ReadOnly = true;
                                                                        dtptek.Enabled   = false;
                                                                        ketcust.ReadOnly = true;
                                                                    }



                                                                    // .... you don't need to close the connection explicitely
                                                                }
                                                            }
                                                            // .... you don't need to close the connection explicitely
                                                        }
                                                    }
                                                }
                                                catch (Exception dataexcp)
                                                {
                                                    MessageBox.Show(dataexcp.ToString(), "Error On SQL Connection");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                print();
            }
        }
Example #4
0
        private void connectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mysqlform connect = new mysqlform();

            connect.ShowDialog();
        }